Skip to content

Commit de865dc

Browse files
committed
makeToolDOT progress
1 parent 0d643ba commit de865dc

2 files changed

Lines changed: 108 additions & 6 deletions

File tree

toolFactory/datacenter.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,47 @@ def getElementsBe(deprecated: bool = False, versionMinorMaximum: int | None = No
136136

137137
return dataframe.to_dict(orient='records') # pyright: ignore[reportReturnType]
138138

139-
def getElementsDOT(deprecated: bool = False, versionMinorMaximum: int | None = None):
140-
pass
139+
def getElementsDOT(deprecated: bool = False, versionMinorMaximum: int | None = None) -> dict[str, dict[str, dict[str, int | str]]]:
140+
listElementsHARDCODED = ['attribute', 'TypeAliasSubcategory', 'attributeVersionMinorMinimum', 'ast_exprType']
141+
listElements = listElementsHARDCODED
142+
143+
dataframe = getDataframe()
144+
dataframe = dataframe.reset_index()
145+
146+
if not deprecated:
147+
dataframe = dataframe[~dataframe['deprecated']]
148+
149+
dataframe['versionMinor'] = dataframe['versionMinor'].astype(int)
150+
151+
if versionMinorMaximum is not None:
152+
dataframe = dataframe[dataframe['versionMinor'] <= versionMinorMaximum]
153+
154+
dataframe = dataframe[dataframe['attributeKind'] == '_field']
155+
156+
dataframe['attributeVersionMinorMinimum'] = dataframe['attributeVersionMinorMinimum'].apply(
157+
lambda version: -1 if version <= pythonVersionMinorMinimum else version
158+
)
159+
160+
dataframe = dataframe.sort_values(
161+
by=listElements,
162+
ascending=[True, True, True, True],
163+
key=lambda x: x.str.lower() if x.dtype == 'object' else x
164+
)
165+
166+
dataframe = dataframe[listElements].drop_duplicates()
167+
168+
listRows = dataframe.values.tolist()
169+
dictionaryAttribute = {}
170+
for attribute, listRowsByAttribute in toolz.groupby(lambda row: row[0], listRows).items():
171+
dictionaryTypeAliasSubcategory = {}
172+
for typeAliasSubcategory, listRowsByTypeAliasSubcategory in toolz.groupby(lambda row: row[1], listRowsByAttribute).items():
173+
rowMinimum = min(listRowsByTypeAliasSubcategory, key=lambda row: row[2])
174+
dictionaryTypeAliasSubcategory[typeAliasSubcategory] = {
175+
'attributeVersionMinorMinimum': rowMinimum[2],
176+
'ast_exprType': rowMinimum[3]
177+
}
178+
dictionaryAttribute[attribute] = dictionaryTypeAliasSubcategory
179+
return dictionaryAttribute
141180

142181
def getElementsMake(deprecated: bool = False, versionMinorMaximum: int | None = None) -> list[dict[str, Any]]:
143182
"""Get elements of class `AST` and its subclasses for tool manufacturing.

toolFactory/factory3.py

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Name(expr):
3939
def writeModule(astModule: ast.Module, moduleIdentifier: str) -> None:
4040
ast.fix_missing_locations(astModule)
4141
pythonSource: str = ast.unparse(astModule)
42-
if moduleIdentifier in {'ClassIsAndAttribute', 'DOT', 'Grab'}:
42+
if 'ClassIsAndAttribute' in moduleIdentifier or 'DOT' in moduleIdentifier or 'Grab' in moduleIdentifier:
4343
pythonSource = "# ruff: noqa: F403, F405\n" + pythonSource
4444
# if 'ClassIsAndAttribute' in moduleIdentifier:
4545
# listTypeIgnore: list[ast.TypeIgnore] = []
@@ -180,7 +180,69 @@ def makeToolBe():
180180
del ClassDef
181181

182182
def makeToolDOT():
183-
pass
183+
list4ClassDefBody: list[ast.stmt] = [ClassDefDocstringDOT]
184+
185+
dictionaryToolElements: dict[str, dict[str, dict[str, int | str]]] = getElementsDOT()
186+
187+
# Process each attribute group to generate overloaded methods and implementations
188+
for attribute, attributeDictionary in dictionaryToolElements.items():
189+
# print(attribute)
190+
listElementsHARDCODED = ['attribute', 'TypeAliasSubcategory', 'attributeVersionMinorMinimum', 'ast_exprType']
191+
for TypeAliasSubcategory, Z0Z_tired in attributeDictionary.items():
192+
# print('\t', TypeAliasSubcategory)
193+
ast_exprType = cast(ast.Attribute, eval(Z0Z_tired['ast_exprType'])) # pyright: ignore[reportArgumentType]
194+
# print('\t\t', ast_exprType)
195+
attributeVersionMinorMinimum: int = Z0Z_tired['attributeVersionMinorMinimum'] # pyright: ignore[reportAssignmentType]
196+
# print('\t\t', attributeVersionMinorMinimum)
197+
# continue
198+
199+
ast_stmt = ast.FunctionDef(
200+
name=attribute,
201+
args=ast.arguments(
202+
posonlyargs=[],
203+
args=[ast.arg('node', ast.Name('hasDOT' + attribute))],
204+
vararg=None,
205+
kwonlyargs=[],
206+
kw_defaults=[],
207+
kwarg=None,
208+
defaults=[]
209+
),
210+
body=[ast.Expr(ast.Constant(value=...))],
211+
decorator_list=[astName_staticmethod, astName_overload],
212+
returns=ast_exprType
213+
)
214+
215+
if attributeVersionMinorMinimum > pythonVersionMinorMinimum:
216+
ast_stmt = ast.If(test=ast.Compare(
217+
left=ast.Attribute(ast.Name('sys'), 'version_info'),
218+
ops=[ast.GtE()],
219+
comparators=[ast.Tuple(
220+
elts=[ast.Constant(3), ast.Constant(attributeVersionMinorMinimum)],
221+
ctx=ast.Load()
222+
)]
223+
),
224+
body=[ast_stmt],
225+
orelse=[])
226+
227+
list4ClassDefBody.append(ast_stmt)
228+
229+
ClassDefDOT = ast.ClassDef(name='DOT', bases=[], keywords=[], body=list4ClassDefBody, decorator_list=[])
230+
231+
ClassDef = ClassDefDOT
232+
writeModule(ast.Module(
233+
body=[docstringWarning
234+
, ast.ImportFrom(module='astToolkit', names=[ast.alias(name='ast_Identifier'), ast.alias(name='ast_expr_Slice'), ast.alias(name='astDOTtype_param')], level=0)
235+
, ast.ImportFrom(module='astToolkit._astTypes', names=[ast.alias(name='*')], level=0)
236+
, ast.ImportFrom(module='collections.abc', names=[ast.alias(name='Sequence')], level=0)
237+
, ast.ImportFrom(module='typing', names=[ast.alias(name='Any'), ast.alias(name='Literal'), ast.alias(name='overload')], level=0)
238+
, ast.Import(names=[ast.alias(name='ast')])
239+
, ast.Import(names=[ast.alias(name='sys')])
240+
, ClassDef
241+
],
242+
type_ignores=[]
243+
)
244+
, moduleIdentifierPrefix + ClassDef.name)
245+
del ClassDef
184246

185247
def makeToolMake():
186248
list4ClassDefBody: list[ast.stmt] = [ClassDefDocstringMake]
@@ -228,5 +290,6 @@ def makeToolMake():
228290
del ClassDef
229291

230292
if __name__ == "__main__":
231-
makeTypeAlias()
232-
makeToolBe()
293+
# makeToolBe()
294+
makeToolDOT()
295+
# makeTypeAlias()

0 commit comments

Comments
 (0)