mapFolding 0.9.5__py3-none-any.whl → 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py +43 -42
- mapFolding/someAssemblyRequired/__init__.py +12 -21
- mapFolding/someAssemblyRequired/_astTypes.py +117 -0
- mapFolding/someAssemblyRequired/_theTypes.py +4 -27
- mapFolding/someAssemblyRequired/_toolBe.py +524 -0
- mapFolding/someAssemblyRequired/_toolDOT.py +493 -0
- mapFolding/someAssemblyRequired/_toolGrab.py +653 -0
- mapFolding/someAssemblyRequired/_toolIfThis.py +193 -0
- mapFolding/someAssemblyRequired/_toolMake.py +339 -0
- mapFolding/someAssemblyRequired/_toolThen.py +63 -0
- mapFolding/someAssemblyRequired/_toolboxAST.py +3 -3
- mapFolding/someAssemblyRequired/_toolboxContainers.py +4 -4
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +9 -9
- mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +9 -9
- mapFolding/someAssemblyRequired/toolboxNumba.py +1 -1
- mapFolding/someAssemblyRequired/transformationTools.py +39 -36
- mapFolding/toolFactory/astFactory.py +493 -0
- mapFolding/toolFactory/astFactory_annex.py +63 -0
- mapFolding/toolFactory/astFactory_docstrings.py +63 -0
- {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/METADATA +2 -1
- {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/RECORD +25 -18
- {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/WHEEL +1 -1
- mapFolding/someAssemblyRequired/_tool_Make.py +0 -132
- mapFolding/someAssemblyRequired/_tool_Then.py +0 -152
- mapFolding/someAssemblyRequired/_toolboxAntecedents.py +0 -404
- {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from mapFolding import getPathFilenameFoldsTotal, raiseIfNoneGitHubIssueNumber3, The
|
|
2
2
|
from mapFolding.someAssemblyRequired import (
|
|
3
3
|
ast_Identifier,
|
|
4
|
-
|
|
4
|
+
Be,
|
|
5
5
|
extractFunctionDef,
|
|
6
|
-
|
|
6
|
+
IfThis,
|
|
7
7
|
IngredientsFunction,
|
|
8
8
|
IngredientsModule,
|
|
9
9
|
LedgerOfImports,
|
|
@@ -77,12 +77,12 @@ if __name__ == '__main__':
|
|
|
77
77
|
ast_argNumbaProgress = ast.arg(arg=spices.numbaProgressBarIdentifier, annotation=ast.Name(id=numba_progressPythonClass, ctx=ast.Load()))
|
|
78
78
|
ingredientsFunction.astFunctionDef.args.args.append(ast_argNumbaProgress)
|
|
79
79
|
|
|
80
|
-
findThis =
|
|
80
|
+
findThis = IfThis.isAugAssign_targetIs(IfThis.isName_Identifier(job.shatteredDataclass.countingVariableName.id))
|
|
81
81
|
doThat = Then.replaceWith(Make.Expr(Make.Call(Make.Attribute(Make.Name(spices.numbaProgressBarIdentifier),'update'),[Make.Constant(1)])))
|
|
82
82
|
countWithProgressBar = NodeChanger(findThis, doThat)
|
|
83
83
|
countWithProgressBar.visit(ingredientsFunction.astFunctionDef)
|
|
84
84
|
|
|
85
|
-
removeReturnStatement = NodeChanger(
|
|
85
|
+
removeReturnStatement = NodeChanger(Be.Return, Then.removeIt)
|
|
86
86
|
removeReturnStatement.visit(ingredientsFunction.astFunctionDef)
|
|
87
87
|
ingredientsFunction.astFunctionDef.returns = Make.Constant(value=None)
|
|
88
88
|
|
|
@@ -119,7 +119,7 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
|
|
|
119
119
|
list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
|
|
120
120
|
list_arg_arg: list[ast_Identifier] = [ast_arg.arg for ast_arg in list_argCuzMyBrainRefusesToThink]
|
|
121
121
|
listName: list[ast.Name] = []
|
|
122
|
-
NodeTourist(
|
|
122
|
+
NodeTourist(Be.Name, Then.appendTo(listName)).visit(ingredientsFunction.astFunctionDef)
|
|
123
123
|
list_Identifiers: list[ast_Identifier] = [astName.id for astName in listName]
|
|
124
124
|
list_IdentifiersNotUsed: list[ast_Identifier] = list(set(list_arg_arg) - set(list_Identifiers))
|
|
125
125
|
|
|
@@ -147,7 +147,7 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
|
|
|
147
147
|
|
|
148
148
|
ingredientsFunction.astFunctionDef.body.insert(0, ImaAnnAssign)
|
|
149
149
|
|
|
150
|
-
findThis =
|
|
150
|
+
findThis = IfThis.is_arg_Identifier(ast_arg.arg)
|
|
151
151
|
remove_arg = NodeChanger(findThis, Then.removeIt)
|
|
152
152
|
remove_arg.visit(ingredientsFunction.astFunctionDef)
|
|
153
153
|
|
|
@@ -161,7 +161,7 @@ def makeJobNumba(job: RecipeJobTheorem2Numba, spices: SpicesJobNumba) -> None:
|
|
|
161
161
|
ingredientsCount: IngredientsFunction = IngredientsFunction(astFunctionDef, LedgerOfImports())
|
|
162
162
|
|
|
163
163
|
# Remove `foldGroups` and any other unused statements, so you can dynamically determine which variables are not used
|
|
164
|
-
findThis =
|
|
164
|
+
findThis = IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier('foldGroups'))
|
|
165
165
|
doThat = Then.removeIt
|
|
166
166
|
remove_foldGroups = NodeChanger(findThis, doThat)
|
|
167
167
|
remove_foldGroups.visit(ingredientsCount.astFunctionDef)
|
|
@@ -169,7 +169,7 @@ def makeJobNumba(job: RecipeJobTheorem2Numba, spices: SpicesJobNumba) -> None:
|
|
|
169
169
|
# replace identifiers with static values with their values, so you can dynamically determine which variables are not used
|
|
170
170
|
list_IdentifiersStaticValues = list_IdentifiersStaticValuesHARDCODED
|
|
171
171
|
for identifier in list_IdentifiersStaticValues:
|
|
172
|
-
findThis =
|
|
172
|
+
findThis = IfThis.isName_Identifier(identifier)
|
|
173
173
|
doThat = Then.replaceWith(Make.Constant(int(job.state.__dict__[identifier])))
|
|
174
174
|
NodeChanger(findThis, doThat).visit(ingredientsCount.astFunctionDef)
|
|
175
175
|
|
|
@@ -193,7 +193,7 @@ if __name__ == '__main__':
|
|
|
193
193
|
# from mapFolding.oeis import getFoldsTotalKnown
|
|
194
194
|
# print(foldsTotal == getFoldsTotalKnown({job.state.mapShape}))
|
|
195
195
|
ingredientsModule.appendLauncher(ast.parse(linesLaunch))
|
|
196
|
-
changeReturnParallelCallable = NodeChanger(
|
|
196
|
+
changeReturnParallelCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(job.shatteredDataclass.countingVariableName)))
|
|
197
197
|
changeReturnParallelCallable.visit(ingredientsCount.astFunctionDef)
|
|
198
198
|
ingredientsCount.astFunctionDef.returns = job.shatteredDataclass.countingVariableAnnotation
|
|
199
199
|
|
|
@@ -21,9 +21,9 @@ as Python scripts or further compiled into standalone executables.
|
|
|
21
21
|
from mapFolding import getPathFilenameFoldsTotal, raiseIfNoneGitHubIssueNumber3, The
|
|
22
22
|
from mapFolding.someAssemblyRequired import (
|
|
23
23
|
ast_Identifier,
|
|
24
|
-
|
|
24
|
+
Be,
|
|
25
25
|
extractFunctionDef,
|
|
26
|
-
|
|
26
|
+
IfThis,
|
|
27
27
|
IngredientsFunction,
|
|
28
28
|
IngredientsModule,
|
|
29
29
|
LedgerOfImports,
|
|
@@ -95,12 +95,12 @@ if __name__ == '__main__':
|
|
|
95
95
|
ast_argNumbaProgress = ast.arg(arg=spices.numbaProgressBarIdentifier, annotation=ast.Name(id=numba_progressPythonClass, ctx=ast.Load()))
|
|
96
96
|
ingredientsFunction.astFunctionDef.args.args.append(ast_argNumbaProgress)
|
|
97
97
|
|
|
98
|
-
findThis =
|
|
98
|
+
findThis = IfThis.isAugAssign_targetIs(IfThis.isName_Identifier(job.shatteredDataclass.countingVariableName.id))
|
|
99
99
|
doThat = Then.replaceWith(Make.Expr(Make.Call(Make.Attribute(Make.Name(spices.numbaProgressBarIdentifier),'update'),[Make.Constant(1)])))
|
|
100
100
|
countWithProgressBar = NodeChanger(findThis, doThat)
|
|
101
101
|
countWithProgressBar.visit(ingredientsFunction.astFunctionDef)
|
|
102
102
|
|
|
103
|
-
removeReturnStatement = NodeChanger(
|
|
103
|
+
removeReturnStatement = NodeChanger(Be.Return, Then.removeIt)
|
|
104
104
|
removeReturnStatement.visit(ingredientsFunction.astFunctionDef)
|
|
105
105
|
ingredientsFunction.astFunctionDef.returns = Make.Constant(value=None)
|
|
106
106
|
|
|
@@ -137,7 +137,7 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
|
|
|
137
137
|
list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
|
|
138
138
|
list_arg_arg: list[ast_Identifier] = [ast_arg.arg for ast_arg in list_argCuzMyBrainRefusesToThink]
|
|
139
139
|
listName: list[ast.Name] = []
|
|
140
|
-
NodeTourist(
|
|
140
|
+
NodeTourist(Be.Name, Then.appendTo(listName)).visit(ingredientsFunction.astFunctionDef)
|
|
141
141
|
list_Identifiers: list[ast_Identifier] = [astName.id for astName in listName]
|
|
142
142
|
list_IdentifiersNotUsed: list[ast_Identifier] = list(set(list_arg_arg) - set(list_Identifiers))
|
|
143
143
|
|
|
@@ -165,7 +165,7 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
|
|
|
165
165
|
|
|
166
166
|
ingredientsFunction.astFunctionDef.body.insert(0, ImaAnnAssign)
|
|
167
167
|
|
|
168
|
-
findThis =
|
|
168
|
+
findThis = IfThis.is_arg_Identifier(ast_arg.arg)
|
|
169
169
|
remove_arg = NodeChanger(findThis, Then.removeIt)
|
|
170
170
|
remove_arg.visit(ingredientsFunction.astFunctionDef)
|
|
171
171
|
|
|
@@ -201,7 +201,7 @@ def makeJobNumba(job: RecipeJob, spices: SpicesJobNumba) -> None:
|
|
|
201
201
|
ingredientsCount: IngredientsFunction = IngredientsFunction(astFunctionDef, LedgerOfImports())
|
|
202
202
|
|
|
203
203
|
# Remove `foldGroups` and any other unused statements, so you can dynamically determine which variables are not used
|
|
204
|
-
findThis =
|
|
204
|
+
findThis = IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier('foldGroups'))
|
|
205
205
|
doThat = Then.removeIt
|
|
206
206
|
remove_foldGroups = NodeChanger(findThis, doThat)
|
|
207
207
|
remove_foldGroups.visit(ingredientsCount.astFunctionDef)
|
|
@@ -209,7 +209,7 @@ def makeJobNumba(job: RecipeJob, spices: SpicesJobNumba) -> None:
|
|
|
209
209
|
# replace identifiers with static values with their values, so you can dynamically determine which variables are not used
|
|
210
210
|
list_IdentifiersStaticValues = list_IdentifiersStaticValuesHARDCODED
|
|
211
211
|
for identifier in list_IdentifiersStaticValues:
|
|
212
|
-
findThis =
|
|
212
|
+
findThis = IfThis.isName_Identifier(identifier)
|
|
213
213
|
doThat = Then.replaceWith(Make.Constant(int(job.state.__dict__[identifier])))
|
|
214
214
|
NodeChanger(findThis, doThat).visit(ingredientsCount.astFunctionDef)
|
|
215
215
|
|
|
@@ -233,7 +233,7 @@ if __name__ == '__main__':
|
|
|
233
233
|
# from mapFolding.oeis import getFoldsTotalKnown
|
|
234
234
|
# print(foldsTotal == getFoldsTotalKnown({job.state.mapShape}))
|
|
235
235
|
ingredientsModule.appendLauncher(ast.parse(linesLaunch))
|
|
236
|
-
changeReturnParallelCallable = NodeChanger(
|
|
236
|
+
changeReturnParallelCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(job.shatteredDataclass.countingVariableName)))
|
|
237
237
|
changeReturnParallelCallable.visit(ingredientsCount.astFunctionDef)
|
|
238
238
|
ingredientsCount.astFunctionDef.returns = job.shatteredDataclass.countingVariableAnnotation
|
|
239
239
|
|
|
@@ -123,7 +123,7 @@ def decorateCallableWithNumba(ingredientsFunction: IngredientsFunction, paramete
|
|
|
123
123
|
ingredientsFunction.imports.addImportFrom_asStr(decoratorModule, decoratorCallable)
|
|
124
124
|
# Leave this line in so that global edits will change it.
|
|
125
125
|
astDecorator: ast.Call = Make.Call(Make.Name(decoratorCallable), list_argsDecorator, listDecoratorKeywords)
|
|
126
|
-
astDecorator: ast.Call = Make.Call(Make.Name(decoratorCallable),
|
|
126
|
+
astDecorator: ast.Call = Make.Call(Make.Name(decoratorCallable), list_keyword=listDecoratorKeywords)
|
|
127
127
|
|
|
128
128
|
ingredientsFunction.astFunctionDef.decorator_list = [astDecorator]
|
|
129
129
|
return ingredientsFunction
|
|
@@ -25,12 +25,12 @@ from mapFolding.beDRY import outfitCountFolds
|
|
|
25
25
|
from mapFolding.someAssemblyRequired import (
|
|
26
26
|
ast_Identifier,
|
|
27
27
|
astModuleToIngredientsFunction,
|
|
28
|
-
|
|
28
|
+
Be,
|
|
29
29
|
DeReConstructField2ast,
|
|
30
30
|
DOT,
|
|
31
31
|
extractClassDef,
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
Grab,
|
|
33
|
+
IfThis,
|
|
34
34
|
importLogicalPath2Callable,
|
|
35
35
|
IngredientsFunction,
|
|
36
36
|
IngredientsModule,
|
|
@@ -69,7 +69,7 @@ def makeDictionaryFunctionDef(module: ast.Module) -> dict[ast_Identifier, ast.Fu
|
|
|
69
69
|
A dictionary mapping function identifiers to their AST function definition nodes.
|
|
70
70
|
"""
|
|
71
71
|
dictionaryIdentifier2FunctionDef: dict[ast_Identifier, ast.FunctionDef] = {}
|
|
72
|
-
NodeTourist(
|
|
72
|
+
NodeTourist(Be.FunctionDef, Then.updateKeyValueIn(DOT.name, Then.extractIt, dictionaryIdentifier2FunctionDef)).visit(module)
|
|
73
73
|
return dictionaryIdentifier2FunctionDef
|
|
74
74
|
|
|
75
75
|
def inlineFunctionDef(identifierToInline: ast_Identifier, module: ast.Module) -> ast.FunctionDef:
|
|
@@ -98,12 +98,12 @@ def inlineFunctionDef(identifierToInline: ast_Identifier, module: ast.Module) ->
|
|
|
98
98
|
raise ValueError(f"FunctionDefToInline not found in dictionaryIdentifier2FunctionDef: {identifierToInline = }") from ERRORmessage
|
|
99
99
|
|
|
100
100
|
listIdentifiersCalledFunctions: list[ast_Identifier] = []
|
|
101
|
-
findIdentifiersToInline = NodeTourist(findThis =
|
|
101
|
+
findIdentifiersToInline = NodeTourist(findThis = IfThis.isCallToName, doThat = Grab.funcDOTidAttribute(Then.appendTo(listIdentifiersCalledFunctions)))
|
|
102
102
|
findIdentifiersToInline.visit(FunctionDefToInline)
|
|
103
103
|
|
|
104
104
|
dictionary4Inlining: dict[ast_Identifier, ast.FunctionDef] = {}
|
|
105
105
|
for identifier in sorted(set(listIdentifiersCalledFunctions).intersection(dictionaryFunctionDef.keys())):
|
|
106
|
-
if NodeTourist(
|
|
106
|
+
if NodeTourist(IfThis.matchesMeButNotAnyDescendant(IfThis.isCall_Identifier(identifier)), Then.extractIt).captureLastMatch(module) is not None:
|
|
107
107
|
dictionary4Inlining[identifier] = dictionaryFunctionDef[identifier]
|
|
108
108
|
|
|
109
109
|
keepGoing = True
|
|
@@ -116,25 +116,28 @@ def inlineFunctionDef(identifierToInline: ast_Identifier, module: ast.Module) ->
|
|
|
116
116
|
if len(listIdentifiersCalledFunctions) > 0:
|
|
117
117
|
keepGoing = True
|
|
118
118
|
for identifier in listIdentifiersCalledFunctions:
|
|
119
|
-
if NodeTourist(
|
|
119
|
+
if NodeTourist(IfThis.matchesMeButNotAnyDescendant(IfThis.isCall_Identifier(identifier)), Then.extractIt).captureLastMatch(module) is not None:
|
|
120
120
|
FunctionDefTarget = dictionaryFunctionDef[identifier]
|
|
121
121
|
if len(FunctionDefTarget.body) == 1:
|
|
122
|
-
replacement = NodeTourist(
|
|
123
|
-
|
|
122
|
+
replacement = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(FunctionDefTarget)
|
|
123
|
+
|
|
124
|
+
findThis = IfThis.isCall_Identifier(identifier)
|
|
125
|
+
doThat = Then.replaceWith(replacement)
|
|
126
|
+
inliner = NodeChanger(findThis, doThat)
|
|
124
127
|
for astFunctionDef in dictionary4Inlining.values():
|
|
125
128
|
inliner.visit(astFunctionDef)
|
|
126
129
|
else:
|
|
127
|
-
inliner = NodeChanger(
|
|
130
|
+
inliner = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(identifier)),Then.replaceWith(FunctionDefTarget.body[0:-1]))
|
|
128
131
|
for astFunctionDef in dictionary4Inlining.values():
|
|
129
132
|
inliner.visit(astFunctionDef)
|
|
130
133
|
|
|
131
134
|
for identifier, FunctionDefTarget in dictionary4Inlining.items():
|
|
132
135
|
if len(FunctionDefTarget.body) == 1:
|
|
133
|
-
replacement = NodeTourist(
|
|
134
|
-
inliner = NodeChanger(
|
|
136
|
+
replacement = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(FunctionDefTarget)
|
|
137
|
+
inliner = NodeChanger(IfThis.isCall_Identifier(identifier), Then.replaceWith(replacement))
|
|
135
138
|
inliner.visit(FunctionDefToInline)
|
|
136
139
|
else:
|
|
137
|
-
inliner = NodeChanger(
|
|
140
|
+
inliner = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(identifier)),Then.replaceWith(FunctionDefTarget.body[0:-1]))
|
|
138
141
|
inliner.visit(FunctionDefToInline)
|
|
139
142
|
ast.fix_missing_locations(FunctionDefToInline)
|
|
140
143
|
return FunctionDefToInline
|
|
@@ -237,7 +240,7 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
237
240
|
map_stateDOTfield2Name={dictionaryDeReConstruction[field].ast_nameDOTname: dictionaryDeReConstruction[field].astName for field in Official_fieldOrder},
|
|
238
241
|
)
|
|
239
242
|
shatteredDataclass.fragments4AssignmentOrParameters = Make.Tuple(shatteredDataclass.listName4Parameters, ast.Store())
|
|
240
|
-
shatteredDataclass.repack = Make.Assign(
|
|
243
|
+
shatteredDataclass.repack = Make.Assign([Make.Name(instance_Identifier)], value=Make.Call(Make.Name(dataclass_Identifier), list_keyword=shatteredDataclass.list_keyword_field__field4init))
|
|
241
244
|
shatteredDataclass.signatureReturnAnnotation = Make.Subscript(Make.Name('tuple'), Make.Tuple(shatteredDataclass.listAnnotations))
|
|
242
245
|
|
|
243
246
|
shatteredDataclass.imports.update(*(dictionaryDeReConstruction[field].ledger for field in Official_fieldOrder))
|
|
@@ -309,18 +312,18 @@ def removeUnusedParameters(ingredientsFunction: IngredientsFunction) -> Ingredie
|
|
|
309
312
|
list_arg_arg: list[ast_Identifier] = [ast_arg.arg for ast_arg in list_argCuzMyBrainRefusesToThink]
|
|
310
313
|
listName: list[ast.Name] = []
|
|
311
314
|
fauxFunctionDef = deepcopy(ingredientsFunction.astFunctionDef)
|
|
312
|
-
NodeChanger(
|
|
313
|
-
NodeTourist(
|
|
315
|
+
NodeChanger(Be.Return, Then.removeIt).visit(fauxFunctionDef)
|
|
316
|
+
NodeTourist(Be.Name, Then.appendTo(listName)).visit(fauxFunctionDef)
|
|
314
317
|
list_Identifiers: list[ast_Identifier] = [astName.id for astName in listName]
|
|
315
318
|
list_IdentifiersNotUsed: list[ast_Identifier] = list(set(list_arg_arg) - set(list_Identifiers))
|
|
316
319
|
for arg_Identifier in list_IdentifiersNotUsed:
|
|
317
|
-
remove_arg = NodeChanger(
|
|
320
|
+
remove_arg = NodeChanger(IfThis.is_arg_Identifier(arg_Identifier), Then.removeIt)
|
|
318
321
|
remove_arg.visit(ingredientsFunction.astFunctionDef)
|
|
319
322
|
|
|
320
323
|
list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
|
|
321
324
|
|
|
322
325
|
listName: list[ast.Name] = [Make.Name(ast_arg.arg) for ast_arg in list_argCuzMyBrainRefusesToThink]
|
|
323
|
-
replaceReturn = NodeChanger(
|
|
326
|
+
replaceReturn = NodeChanger(Be.Return, Then.replaceWith(Make.Return(Make.Tuple(listName))))
|
|
324
327
|
replaceReturn.visit(ingredientsFunction.astFunctionDef)
|
|
325
328
|
|
|
326
329
|
list_annotation: list[ast.expr] = [ast_arg.annotation for ast_arg in list_argCuzMyBrainRefusesToThink if ast_arg.annotation is not None]
|
|
@@ -356,7 +359,7 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
356
359
|
(recipeFlow.sourceCallableSequential, recipeFlow.callableSequential),]
|
|
357
360
|
for ingredients in listAllIngredientsFunctions:
|
|
358
361
|
for source_Identifier, recipe_Identifier in listFindReplace:
|
|
359
|
-
updateCallName = NodeChanger(
|
|
362
|
+
updateCallName = NodeChanger(IfThis.isCall_Identifier(source_Identifier), Grab.funcAttribute(Then.replaceWith(Make.Name(recipe_Identifier))))
|
|
360
363
|
updateCallName.visit(ingredients.astFunctionDef)
|
|
361
364
|
|
|
362
365
|
ingredientsDispatcher.astFunctionDef.name = recipeFlow.callableDispatcher
|
|
@@ -370,13 +373,13 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
370
373
|
(recipeFlow.sourceConcurrencyManagerNamespace, recipeFlow.concurrencyManagerNamespace),]
|
|
371
374
|
for ingredients in listAllIngredientsFunctions:
|
|
372
375
|
for source_Identifier, recipe_Identifier in listFindReplace:
|
|
373
|
-
updateName = NodeChanger(
|
|
374
|
-
update_arg = NodeChanger(
|
|
376
|
+
updateName = NodeChanger(IfThis.isName_Identifier(source_Identifier) , Grab.idAttribute(Then.replaceWith(recipe_Identifier)))
|
|
377
|
+
update_arg = NodeChanger(IfThis.isArgument_Identifier(source_Identifier), Grab.argAttribute(Then.replaceWith(recipe_Identifier))) # type: ignore
|
|
375
378
|
updateName.visit(ingredients.astFunctionDef)
|
|
376
379
|
update_arg.visit(ingredients.astFunctionDef)
|
|
377
380
|
|
|
378
|
-
updateConcurrencyManager = NodeChanger(
|
|
379
|
-
,
|
|
381
|
+
updateConcurrencyManager = NodeChanger(IfThis.isCallAttributeNamespace_Identifier(recipeFlow.sourceConcurrencyManagerNamespace, recipeFlow.sourceConcurrencyManagerIdentifier)
|
|
382
|
+
, Grab.funcAttribute(Then.replaceWith(Make.Attribute(Make.Name(recipeFlow.concurrencyManagerNamespace), recipeFlow.concurrencyManagerIdentifier))))
|
|
380
383
|
updateConcurrencyManager.visit(ingredientsDispatcher.astFunctionDef)
|
|
381
384
|
|
|
382
385
|
# shatter Dataclass =======================================================
|
|
@@ -398,7 +401,7 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
398
401
|
|
|
399
402
|
# parallelCallable =========================================================
|
|
400
403
|
if recipeFlow.removeDataclassParallel:
|
|
401
|
-
ingredientsParallel.astFunctionDef.args = Make.
|
|
404
|
+
ingredientsParallel.astFunctionDef.args = Make.arguments(args=shatteredDataclass.list_argAnnotated4ArgumentsSpecification)
|
|
402
405
|
|
|
403
406
|
ingredientsParallel.astFunctionDef = Z0Z_lameFindReplace(ingredientsParallel.astFunctionDef, shatteredDataclass.map_stateDOTfield2Name)
|
|
404
407
|
|
|
@@ -409,25 +412,25 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
409
412
|
|
|
410
413
|
listParameters = [parameter for parameter in shatteredDataclass.listName4Parameters if parameter.id in list_arg_arg]
|
|
411
414
|
|
|
412
|
-
replaceCall2concurrencyManager = NodeChanger(
|
|
415
|
+
replaceCall2concurrencyManager = NodeChanger(IfThis.isCallAttributeNamespace_Identifier(recipeFlow.concurrencyManagerNamespace, recipeFlow.concurrencyManagerIdentifier), Then.replaceWith(Make.Call(Make.Attribute(Make.Name(recipeFlow.concurrencyManagerNamespace), recipeFlow.concurrencyManagerIdentifier), [Make.Name(recipeFlow.callableParallel)] + listParameters)))
|
|
413
416
|
|
|
414
417
|
def getIt(astCallConcurrencyResult: list[ast.Call]) -> Callable[[ast.AST], ast.AST]:
|
|
415
418
|
# TODO I cannot remember why I made this function. It doesn't fit with how I normally do things.
|
|
416
419
|
def workhorse(node: ast.AST) -> ast.AST:
|
|
417
|
-
NodeTourist(
|
|
420
|
+
NodeTourist(Be.Call, Then.appendTo(astCallConcurrencyResult)).visit(node)
|
|
418
421
|
return node
|
|
419
422
|
return workhorse
|
|
420
423
|
|
|
421
424
|
# NOTE I am dissatisfied with this logic for many reasons, including that it requires separate NodeCollector and NodeReplacer instances.
|
|
422
425
|
astCallConcurrencyResult: list[ast.Call] = []
|
|
423
|
-
get_astCallConcurrencyResult = NodeTourist(
|
|
426
|
+
get_astCallConcurrencyResult = NodeTourist(IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier(getTheOtherRecord_damn)), getIt(astCallConcurrencyResult))
|
|
424
427
|
get_astCallConcurrencyResult.visit(ingredientsDispatcher.astFunctionDef)
|
|
425
|
-
replaceAssignParallelCallable = NodeChanger(
|
|
428
|
+
replaceAssignParallelCallable = NodeChanger(IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier(getTheOtherRecord_damn)), Grab.valueAttribute(Then.replaceWith(astCallConcurrencyResult[0])))
|
|
426
429
|
replaceAssignParallelCallable.visit(ingredientsDispatcher.astFunctionDef)
|
|
427
|
-
changeReturnParallelCallable = NodeChanger(
|
|
430
|
+
changeReturnParallelCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(shatteredDataclass.countingVariableName)))
|
|
428
431
|
ingredientsParallel.astFunctionDef.returns = shatteredDataclass.countingVariableAnnotation
|
|
429
432
|
|
|
430
|
-
unpack4parallelCallable = NodeChanger(
|
|
433
|
+
unpack4parallelCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCallAttributeNamespace_Identifier(recipeFlow.concurrencyManagerNamespace, recipeFlow.concurrencyManagerIdentifier)), Then.insertThisAbove(shatteredDataclass.listUnpack))
|
|
431
434
|
|
|
432
435
|
unpack4parallelCallable.visit(ingredientsDispatcher.astFunctionDef)
|
|
433
436
|
replaceCall2concurrencyManager.visit(ingredientsDispatcher.astFunctionDef)
|
|
@@ -440,18 +443,18 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
440
443
|
return ingredientsModuleNumbaUnified
|
|
441
444
|
|
|
442
445
|
def removeDataclassFromFunction(ingredientsTarget: IngredientsFunction, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
443
|
-
ingredientsTarget.astFunctionDef.args = Make.
|
|
446
|
+
ingredientsTarget.astFunctionDef.args = Make.arguments(args=shatteredDataclass.list_argAnnotated4ArgumentsSpecification)
|
|
444
447
|
ingredientsTarget.astFunctionDef.returns = shatteredDataclass.signatureReturnAnnotation
|
|
445
|
-
changeReturnCallable = NodeChanger(
|
|
448
|
+
changeReturnCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(shatteredDataclass.fragments4AssignmentOrParameters)))
|
|
446
449
|
changeReturnCallable.visit(ingredientsTarget.astFunctionDef)
|
|
447
450
|
ingredientsTarget.astFunctionDef = Z0Z_lameFindReplace(ingredientsTarget.astFunctionDef, shatteredDataclass.map_stateDOTfield2Name)
|
|
448
451
|
return ingredientsTarget
|
|
449
452
|
|
|
450
453
|
def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFunction, targetCallableIdentifier: ast_Identifier, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
451
454
|
astCallTargetCallable = Make.Call(Make.Name(targetCallableIdentifier), shatteredDataclass.listName4Parameters)
|
|
452
|
-
replaceAssignTargetCallable = NodeChanger(
|
|
453
|
-
unpack4targetCallable = NodeChanger(
|
|
454
|
-
repack4targetCallable = NodeChanger(
|
|
455
|
+
replaceAssignTargetCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier)), Then.replaceWith(Make.Assign([shatteredDataclass.fragments4AssignmentOrParameters], value=astCallTargetCallable)))
|
|
456
|
+
unpack4targetCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier)), Then.insertThisAbove(shatteredDataclass.listUnpack))
|
|
457
|
+
repack4targetCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier)), Then.insertThisBelow([shatteredDataclass.repack]))
|
|
455
458
|
replaceAssignTargetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
456
459
|
unpack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
457
460
|
repack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
@@ -491,7 +494,7 @@ def Z0Z_lameFindReplace(astTree: 个, mappingFindReplaceNodes: Mapping[ast.AST,
|
|
|
491
494
|
|
|
492
495
|
while keepGoing:
|
|
493
496
|
for nodeFind, nodeReplace in mappingFindReplaceNodes.items():
|
|
494
|
-
NodeChanger(
|
|
497
|
+
NodeChanger(IfThis.Z0Z_unparseIs(nodeFind), Then.replaceWith(nodeReplace)).visit(newTree)
|
|
495
498
|
|
|
496
499
|
if ast.unparse(newTree) == ast.unparse(astTree):
|
|
497
500
|
keepGoing = False
|