mapFolding 0.9.5__py3-none-any.whl → 0.11.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/__init__.py +29 -27
- mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py +44 -45
- mapFolding/someAssemblyRequired/__init__.py +17 -35
- mapFolding/someAssemblyRequired/_toolIfThis.py +53 -0
- mapFolding/someAssemblyRequired/_toolboxContainers.py +15 -287
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +14 -14
- mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +13 -13
- mapFolding/someAssemblyRequired/toolboxNumba.py +1 -1
- mapFolding/someAssemblyRequired/transformationTools.py +25 -195
- {mapfolding-0.9.5.dist-info → mapfolding-0.11.0.dist-info}/METADATA +3 -1
- {mapfolding-0.9.5.dist-info → mapfolding-0.11.0.dist-info}/RECORD +15 -20
- {mapfolding-0.9.5.dist-info → mapfolding-0.11.0.dist-info}/WHEEL +1 -1
- mapFolding/someAssemblyRequired/_theTypes.py +0 -57
- mapFolding/someAssemblyRequired/_tool_Make.py +0 -132
- mapFolding/someAssemblyRequired/_tool_Then.py +0 -152
- mapFolding/someAssemblyRequired/_toolboxAST.py +0 -57
- mapFolding/someAssemblyRequired/_toolboxAntecedents.py +0 -404
- mapFolding/someAssemblyRequired/_toolboxPython.py +0 -188
- {mapfolding-0.9.5.dist-info → mapfolding-0.11.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.9.5.dist-info → mapfolding-0.11.0.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.9.5.dist-info → mapfolding-0.11.0.dist-info}/top_level.txt +0 -0
|
@@ -18,19 +18,18 @@ readable, maintainable implementations to highly optimized versions while preser
|
|
|
18
18
|
logical structure and correctness.
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
from
|
|
21
|
+
from astToolkit.transformationTools import ( inlineFunctionDef as inlineFunctionDef, removeUnusedParameters as removeUnusedParameters, write_astModule as write_astModule, )
|
|
22
22
|
from collections.abc import Callable, Mapping
|
|
23
23
|
from copy import deepcopy
|
|
24
24
|
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
|
-
DOT,
|
|
31
30
|
extractClassDef,
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
Grab,
|
|
32
|
+
IfThis,
|
|
34
33
|
importLogicalPath2Callable,
|
|
35
34
|
IngredientsFunction,
|
|
36
35
|
IngredientsModule,
|
|
@@ -45,99 +44,14 @@ from mapFolding.someAssemblyRequired import (
|
|
|
45
44
|
Then,
|
|
46
45
|
个,
|
|
47
46
|
)
|
|
48
|
-
from mapFolding.theSSOT import ComputationState,
|
|
49
|
-
from mapFolding.toolboxFilesystem import getPathFilenameFoldsTotal
|
|
47
|
+
from mapFolding.theSSOT import ComputationState, The
|
|
48
|
+
from mapFolding.toolboxFilesystem import getPathFilenameFoldsTotal
|
|
50
49
|
from os import PathLike
|
|
51
50
|
from pathlib import Path, PurePath
|
|
52
51
|
from typing import Any, Literal, overload
|
|
53
52
|
import ast
|
|
54
53
|
import dataclasses
|
|
55
54
|
import pickle
|
|
56
|
-
import python_minifier
|
|
57
|
-
|
|
58
|
-
def makeDictionaryFunctionDef(module: ast.Module) -> dict[ast_Identifier, ast.FunctionDef]:
|
|
59
|
-
"""
|
|
60
|
-
Create a dictionary mapping function names to their AST definitions.
|
|
61
|
-
|
|
62
|
-
This function creates a dictionary that maps function names to their AST function
|
|
63
|
-
definition nodes for all functions defined in the given module.
|
|
64
|
-
|
|
65
|
-
Parameters:
|
|
66
|
-
module: The AST module to extract function definitions from.
|
|
67
|
-
|
|
68
|
-
Returns:
|
|
69
|
-
A dictionary mapping function identifiers to their AST function definition nodes.
|
|
70
|
-
"""
|
|
71
|
-
dictionaryIdentifier2FunctionDef: dict[ast_Identifier, ast.FunctionDef] = {}
|
|
72
|
-
NodeTourist(be.FunctionDef, Then.updateKeyValueIn(DOT.name, Then.extractIt, dictionaryIdentifier2FunctionDef)).visit(module)
|
|
73
|
-
return dictionaryIdentifier2FunctionDef
|
|
74
|
-
|
|
75
|
-
def inlineFunctionDef(identifierToInline: ast_Identifier, module: ast.Module) -> ast.FunctionDef:
|
|
76
|
-
"""
|
|
77
|
-
Inline function calls within a function definition to create a self-contained function.
|
|
78
|
-
|
|
79
|
-
This function takes a function identifier and a module, finds the function definition,
|
|
80
|
-
and then recursively inlines all function calls within that function with their
|
|
81
|
-
implementation bodies. This produces a fully inlined function that doesn't depend
|
|
82
|
-
on other function definitions from the module.
|
|
83
|
-
|
|
84
|
-
Parameters:
|
|
85
|
-
identifierToInline: The name of the function to inline.
|
|
86
|
-
module: The AST module containing the function and its dependencies.
|
|
87
|
-
|
|
88
|
-
Returns:
|
|
89
|
-
A modified function definition with all function calls inlined.
|
|
90
|
-
|
|
91
|
-
Raises:
|
|
92
|
-
ValueError: If the function to inline is not found in the module.
|
|
93
|
-
"""
|
|
94
|
-
dictionaryFunctionDef: dict[ast_Identifier, ast.FunctionDef] = makeDictionaryFunctionDef(module)
|
|
95
|
-
try:
|
|
96
|
-
FunctionDefToInline = dictionaryFunctionDef[identifierToInline]
|
|
97
|
-
except KeyError as ERRORmessage:
|
|
98
|
-
raise ValueError(f"FunctionDefToInline not found in dictionaryIdentifier2FunctionDef: {identifierToInline = }") from ERRORmessage
|
|
99
|
-
|
|
100
|
-
listIdentifiersCalledFunctions: list[ast_Identifier] = []
|
|
101
|
-
findIdentifiersToInline = NodeTourist(findThis = ifThis.isCallToName, doThat = grab.funcDOTidAttribute(Then.appendTo(listIdentifiersCalledFunctions)))
|
|
102
|
-
findIdentifiersToInline.visit(FunctionDefToInline)
|
|
103
|
-
|
|
104
|
-
dictionary4Inlining: dict[ast_Identifier, ast.FunctionDef] = {}
|
|
105
|
-
for identifier in sorted(set(listIdentifiersCalledFunctions).intersection(dictionaryFunctionDef.keys())):
|
|
106
|
-
if NodeTourist(ifThis.matchesMeButNotAnyDescendant(ifThis.isCall_Identifier(identifier)), Then.extractIt).captureLastMatch(module) is not None:
|
|
107
|
-
dictionary4Inlining[identifier] = dictionaryFunctionDef[identifier]
|
|
108
|
-
|
|
109
|
-
keepGoing = True
|
|
110
|
-
while keepGoing:
|
|
111
|
-
keepGoing = False
|
|
112
|
-
listIdentifiersCalledFunctions.clear()
|
|
113
|
-
findIdentifiersToInline.visit(Make.Module(list(dictionary4Inlining.values())))
|
|
114
|
-
|
|
115
|
-
listIdentifiersCalledFunctions = sorted((set(listIdentifiersCalledFunctions).difference(dictionary4Inlining.keys())).intersection(dictionaryFunctionDef.keys()))
|
|
116
|
-
if len(listIdentifiersCalledFunctions) > 0:
|
|
117
|
-
keepGoing = True
|
|
118
|
-
for identifier in listIdentifiersCalledFunctions:
|
|
119
|
-
if NodeTourist(ifThis.matchesMeButNotAnyDescendant(ifThis.isCall_Identifier(identifier)), Then.extractIt).captureLastMatch(module) is not None:
|
|
120
|
-
FunctionDefTarget = dictionaryFunctionDef[identifier]
|
|
121
|
-
if len(FunctionDefTarget.body) == 1:
|
|
122
|
-
replacement = NodeTourist(be.Return, Then.extractIt(DOT.value)).captureLastMatch(FunctionDefTarget)
|
|
123
|
-
inliner = NodeChanger(ifThis.isCall_Identifier(identifier), Then.replaceWith(replacement))
|
|
124
|
-
for astFunctionDef in dictionary4Inlining.values():
|
|
125
|
-
inliner.visit(astFunctionDef)
|
|
126
|
-
else:
|
|
127
|
-
inliner = NodeChanger(ifThis.isAssignAndValueIs(ifThis.isCall_Identifier(identifier)),Then.replaceWith(FunctionDefTarget.body[0:-1]))
|
|
128
|
-
for astFunctionDef in dictionary4Inlining.values():
|
|
129
|
-
inliner.visit(astFunctionDef)
|
|
130
|
-
|
|
131
|
-
for identifier, FunctionDefTarget in dictionary4Inlining.items():
|
|
132
|
-
if len(FunctionDefTarget.body) == 1:
|
|
133
|
-
replacement = NodeTourist(be.Return, Then.extractIt(DOT.value)).captureLastMatch(FunctionDefTarget)
|
|
134
|
-
inliner = NodeChanger(ifThis.isCall_Identifier(identifier), Then.replaceWith(replacement))
|
|
135
|
-
inliner.visit(FunctionDefToInline)
|
|
136
|
-
else:
|
|
137
|
-
inliner = NodeChanger(ifThis.isAssignAndValueIs(ifThis.isCall_Identifier(identifier)),Then.replaceWith(FunctionDefTarget.body[0:-1]))
|
|
138
|
-
inliner.visit(FunctionDefToInline)
|
|
139
|
-
ast.fix_missing_locations(FunctionDefToInline)
|
|
140
|
-
return FunctionDefToInline
|
|
141
55
|
|
|
142
56
|
@overload
|
|
143
57
|
def makeInitializedComputationState(mapShape: tuple[int, ...], writeJob: Literal[True], *, pathFilename: PathLike[str] | PurePath | None = None, **keywordArguments: Any) -> Path: ...
|
|
@@ -237,7 +151,7 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
237
151
|
map_stateDOTfield2Name={dictionaryDeReConstruction[field].ast_nameDOTname: dictionaryDeReConstruction[field].astName for field in Official_fieldOrder},
|
|
238
152
|
)
|
|
239
153
|
shatteredDataclass.fragments4AssignmentOrParameters = Make.Tuple(shatteredDataclass.listName4Parameters, ast.Store())
|
|
240
|
-
shatteredDataclass.repack = Make.Assign(
|
|
154
|
+
shatteredDataclass.repack = Make.Assign([Make.Name(instance_Identifier)], value=Make.Call(Make.Name(dataclass_Identifier), list_keyword=shatteredDataclass.list_keyword_field__field4init))
|
|
241
155
|
shatteredDataclass.signatureReturnAnnotation = Make.Subscript(Make.Name('tuple'), Make.Tuple(shatteredDataclass.listAnnotations))
|
|
242
156
|
|
|
243
157
|
shatteredDataclass.imports.update(*(dictionaryDeReConstruction[field].ledger for field in Official_fieldOrder))
|
|
@@ -245,91 +159,7 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
245
159
|
|
|
246
160
|
return shatteredDataclass
|
|
247
161
|
|
|
248
|
-
def write_astModule(ingredients: IngredientsModule, pathFilename: PathLike[Any] | PurePath, packageName: ast_Identifier | None = None) -> None:
|
|
249
|
-
"""
|
|
250
|
-
Convert an IngredientsModule to Python source code and write it to a file.
|
|
251
|
-
|
|
252
|
-
This function renders an IngredientsModule into executable Python code,
|
|
253
|
-
applies code quality improvements like import organization via autoflake,
|
|
254
|
-
and writes the result to the specified file path.
|
|
255
|
-
|
|
256
|
-
The function performs several key steps:
|
|
257
|
-
1. Converts the AST module structure to a valid Python AST
|
|
258
|
-
2. Fixes location attributes in the AST for proper formatting
|
|
259
|
-
3. Converts the AST to Python source code
|
|
260
|
-
4. Optimizes imports using autoflake
|
|
261
|
-
5. Writes the final source code to the specified file location
|
|
262
|
-
|
|
263
|
-
This is typically the final step in the code generation assembly line,
|
|
264
|
-
producing optimized Python modules ready for execution.
|
|
265
|
-
|
|
266
|
-
Parameters:
|
|
267
|
-
ingredients: The IngredientsModule containing the module definition.
|
|
268
|
-
pathFilename: The file path where the module should be written.
|
|
269
|
-
packageName: Optional package name to preserve in import optimization.
|
|
270
|
-
|
|
271
|
-
Raises:
|
|
272
|
-
raiseIfNoneGitHubIssueNumber3: If the generated source code is empty.
|
|
273
|
-
"""
|
|
274
|
-
astModule = Make.Module(ingredients.body, ingredients.type_ignores)
|
|
275
|
-
ast.fix_missing_locations(astModule)
|
|
276
|
-
pythonSource: str = ast.unparse(astModule)
|
|
277
|
-
if not pythonSource: raise raiseIfNoneGitHubIssueNumber3
|
|
278
|
-
autoflake_additional_imports: list[str] = ingredients.imports.exportListModuleIdentifiers()
|
|
279
|
-
if packageName:
|
|
280
|
-
autoflake_additional_imports.append(packageName)
|
|
281
|
-
pythonSource = autoflake_fix_code(pythonSource, autoflake_additional_imports, expand_star_imports=False, remove_all_unused_imports=True, remove_duplicate_keys = False, remove_unused_variables = False)
|
|
282
|
-
# pythonSource = python_minifier.minify(pythonSource, remove_annotations=False, hoist_literals=False)
|
|
283
|
-
writeStringToHere(pythonSource, pathFilename)
|
|
284
|
-
|
|
285
162
|
# END of acceptable classes and functions ======================================================
|
|
286
|
-
def removeUnusedParameters(ingredientsFunction: IngredientsFunction) -> IngredientsFunction:
|
|
287
|
-
"""
|
|
288
|
-
Removes unused parameters from a function's AST definition, return statement, and annotation.
|
|
289
|
-
|
|
290
|
-
This function analyzes the Abstract Syntax Tree (AST) of a given function and removes
|
|
291
|
-
any parameters that are not referenced within the function body. It updates the
|
|
292
|
-
function signature, the return statement (if it's a tuple containing unused variables),
|
|
293
|
-
and the return type annotation accordingly.
|
|
294
|
-
|
|
295
|
-
Parameters
|
|
296
|
-
----------
|
|
297
|
-
ingredientsFunction : IngredientsFunction
|
|
298
|
-
An object containing the AST representation of a function to be processed.
|
|
299
|
-
|
|
300
|
-
Returns
|
|
301
|
-
-------
|
|
302
|
-
IngredientsFunction
|
|
303
|
-
The modified IngredientsFunction object with unused parameters and corresponding
|
|
304
|
-
return elements/annotations removed from its AST.
|
|
305
|
-
|
|
306
|
-
The modification is done in-place on the original AST nodes within the IngredientsFunction object.
|
|
307
|
-
"""
|
|
308
|
-
list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
|
|
309
|
-
list_arg_arg: list[ast_Identifier] = [ast_arg.arg for ast_arg in list_argCuzMyBrainRefusesToThink]
|
|
310
|
-
listName: list[ast.Name] = []
|
|
311
|
-
fauxFunctionDef = deepcopy(ingredientsFunction.astFunctionDef)
|
|
312
|
-
NodeChanger(be.Return, Then.removeIt).visit(fauxFunctionDef)
|
|
313
|
-
NodeTourist(be.Name, Then.appendTo(listName)).visit(fauxFunctionDef)
|
|
314
|
-
list_Identifiers: list[ast_Identifier] = [astName.id for astName in listName]
|
|
315
|
-
list_IdentifiersNotUsed: list[ast_Identifier] = list(set(list_arg_arg) - set(list_Identifiers))
|
|
316
|
-
for arg_Identifier in list_IdentifiersNotUsed:
|
|
317
|
-
remove_arg = NodeChanger(ifThis.is_arg_Identifier(arg_Identifier), Then.removeIt)
|
|
318
|
-
remove_arg.visit(ingredientsFunction.astFunctionDef)
|
|
319
|
-
|
|
320
|
-
list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
|
|
321
|
-
|
|
322
|
-
listName: list[ast.Name] = [Make.Name(ast_arg.arg) for ast_arg in list_argCuzMyBrainRefusesToThink]
|
|
323
|
-
replaceReturn = NodeChanger(be.Return, Then.replaceWith(Make.Return(Make.Tuple(listName))))
|
|
324
|
-
replaceReturn.visit(ingredientsFunction.astFunctionDef)
|
|
325
|
-
|
|
326
|
-
list_annotation: list[ast.expr] = [ast_arg.annotation for ast_arg in list_argCuzMyBrainRefusesToThink if ast_arg.annotation is not None]
|
|
327
|
-
ingredientsFunction.astFunctionDef.returns = Make.Subscript(Make.Name('tuple'), Make.Tuple(list_annotation))
|
|
328
|
-
|
|
329
|
-
ast.fix_missing_locations(ingredientsFunction.astFunctionDef)
|
|
330
|
-
|
|
331
|
-
return ingredientsFunction
|
|
332
|
-
|
|
333
163
|
def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
334
164
|
# Figure out dynamic flow control to synthesized modules https://github.com/hunterhogan/mapFolding/issues/4
|
|
335
165
|
listAllIngredientsFunctions = [
|
|
@@ -356,7 +186,7 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
356
186
|
(recipeFlow.sourceCallableSequential, recipeFlow.callableSequential),]
|
|
357
187
|
for ingredients in listAllIngredientsFunctions:
|
|
358
188
|
for source_Identifier, recipe_Identifier in listFindReplace:
|
|
359
|
-
updateCallName = NodeChanger(
|
|
189
|
+
updateCallName = NodeChanger(IfThis.isCall_Identifier(source_Identifier), Grab.funcAttribute(Then.replaceWith(Make.Name(recipe_Identifier))))
|
|
360
190
|
updateCallName.visit(ingredients.astFunctionDef)
|
|
361
191
|
|
|
362
192
|
ingredientsDispatcher.astFunctionDef.name = recipeFlow.callableDispatcher
|
|
@@ -370,13 +200,13 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
370
200
|
(recipeFlow.sourceConcurrencyManagerNamespace, recipeFlow.concurrencyManagerNamespace),]
|
|
371
201
|
for ingredients in listAllIngredientsFunctions:
|
|
372
202
|
for source_Identifier, recipe_Identifier in listFindReplace:
|
|
373
|
-
updateName = NodeChanger(
|
|
374
|
-
update_arg = NodeChanger(
|
|
203
|
+
updateName = NodeChanger(IfThis.isName_Identifier(source_Identifier) , Grab.idAttribute(Then.replaceWith(recipe_Identifier)))
|
|
204
|
+
update_arg = NodeChanger(IfThis.isArgument_Identifier(source_Identifier), Grab.argAttribute(Then.replaceWith(recipe_Identifier)))
|
|
375
205
|
updateName.visit(ingredients.astFunctionDef)
|
|
376
206
|
update_arg.visit(ingredients.astFunctionDef)
|
|
377
207
|
|
|
378
|
-
updateConcurrencyManager = NodeChanger(
|
|
379
|
-
,
|
|
208
|
+
updateConcurrencyManager = NodeChanger(IfThis.isCallAttributeNamespace_Identifier(recipeFlow.sourceConcurrencyManagerNamespace, recipeFlow.sourceConcurrencyManagerIdentifier)
|
|
209
|
+
, Grab.funcAttribute(Then.replaceWith(Make.Attribute(Make.Name(recipeFlow.concurrencyManagerNamespace), recipeFlow.concurrencyManagerIdentifier))))
|
|
380
210
|
updateConcurrencyManager.visit(ingredientsDispatcher.astFunctionDef)
|
|
381
211
|
|
|
382
212
|
# shatter Dataclass =======================================================
|
|
@@ -398,7 +228,7 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
398
228
|
|
|
399
229
|
# parallelCallable =========================================================
|
|
400
230
|
if recipeFlow.removeDataclassParallel:
|
|
401
|
-
ingredientsParallel.astFunctionDef.args = Make.
|
|
231
|
+
ingredientsParallel.astFunctionDef.args = Make.arguments(args=shatteredDataclass.list_argAnnotated4ArgumentsSpecification)
|
|
402
232
|
|
|
403
233
|
ingredientsParallel.astFunctionDef = Z0Z_lameFindReplace(ingredientsParallel.astFunctionDef, shatteredDataclass.map_stateDOTfield2Name)
|
|
404
234
|
|
|
@@ -409,25 +239,25 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
409
239
|
|
|
410
240
|
listParameters = [parameter for parameter in shatteredDataclass.listName4Parameters if parameter.id in list_arg_arg]
|
|
411
241
|
|
|
412
|
-
replaceCall2concurrencyManager = NodeChanger(
|
|
242
|
+
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
243
|
|
|
414
244
|
def getIt(astCallConcurrencyResult: list[ast.Call]) -> Callable[[ast.AST], ast.AST]:
|
|
415
245
|
# TODO I cannot remember why I made this function. It doesn't fit with how I normally do things.
|
|
416
246
|
def workhorse(node: ast.AST) -> ast.AST:
|
|
417
|
-
NodeTourist(
|
|
247
|
+
NodeTourist(Be.Call, Then.appendTo(astCallConcurrencyResult)).visit(node)
|
|
418
248
|
return node
|
|
419
249
|
return workhorse
|
|
420
250
|
|
|
421
251
|
# NOTE I am dissatisfied with this logic for many reasons, including that it requires separate NodeCollector and NodeReplacer instances.
|
|
422
252
|
astCallConcurrencyResult: list[ast.Call] = []
|
|
423
|
-
get_astCallConcurrencyResult = NodeTourist(
|
|
253
|
+
get_astCallConcurrencyResult = NodeTourist(IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier(getTheOtherRecord_damn)), getIt(astCallConcurrencyResult))
|
|
424
254
|
get_astCallConcurrencyResult.visit(ingredientsDispatcher.astFunctionDef)
|
|
425
|
-
replaceAssignParallelCallable = NodeChanger(
|
|
255
|
+
replaceAssignParallelCallable = NodeChanger(IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier(getTheOtherRecord_damn)), Grab.valueAttribute(Then.replaceWith(astCallConcurrencyResult[0])))
|
|
426
256
|
replaceAssignParallelCallable.visit(ingredientsDispatcher.astFunctionDef)
|
|
427
|
-
changeReturnParallelCallable = NodeChanger(
|
|
257
|
+
changeReturnParallelCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(shatteredDataclass.countingVariableName)))
|
|
428
258
|
ingredientsParallel.astFunctionDef.returns = shatteredDataclass.countingVariableAnnotation
|
|
429
259
|
|
|
430
|
-
unpack4parallelCallable = NodeChanger(
|
|
260
|
+
unpack4parallelCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCallAttributeNamespace_Identifier(recipeFlow.concurrencyManagerNamespace, recipeFlow.concurrencyManagerIdentifier)), Then.insertThisAbove(shatteredDataclass.listUnpack))
|
|
431
261
|
|
|
432
262
|
unpack4parallelCallable.visit(ingredientsDispatcher.astFunctionDef)
|
|
433
263
|
replaceCall2concurrencyManager.visit(ingredientsDispatcher.astFunctionDef)
|
|
@@ -440,18 +270,18 @@ def makeNewFlow(recipeFlow: RecipeSynthesizeFlow) -> IngredientsModule:
|
|
|
440
270
|
return ingredientsModuleNumbaUnified
|
|
441
271
|
|
|
442
272
|
def removeDataclassFromFunction(ingredientsTarget: IngredientsFunction, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
443
|
-
ingredientsTarget.astFunctionDef.args = Make.
|
|
273
|
+
ingredientsTarget.astFunctionDef.args = Make.arguments(args=shatteredDataclass.list_argAnnotated4ArgumentsSpecification)
|
|
444
274
|
ingredientsTarget.astFunctionDef.returns = shatteredDataclass.signatureReturnAnnotation
|
|
445
|
-
changeReturnCallable = NodeChanger(
|
|
275
|
+
changeReturnCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(shatteredDataclass.fragments4AssignmentOrParameters)))
|
|
446
276
|
changeReturnCallable.visit(ingredientsTarget.astFunctionDef)
|
|
447
277
|
ingredientsTarget.astFunctionDef = Z0Z_lameFindReplace(ingredientsTarget.astFunctionDef, shatteredDataclass.map_stateDOTfield2Name)
|
|
448
278
|
return ingredientsTarget
|
|
449
279
|
|
|
450
280
|
def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFunction, targetCallableIdentifier: ast_Identifier, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
451
281
|
astCallTargetCallable = Make.Call(Make.Name(targetCallableIdentifier), shatteredDataclass.listName4Parameters)
|
|
452
|
-
replaceAssignTargetCallable = NodeChanger(
|
|
453
|
-
unpack4targetCallable = NodeChanger(
|
|
454
|
-
repack4targetCallable = NodeChanger(
|
|
282
|
+
replaceAssignTargetCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier)), Then.replaceWith(Make.Assign([shatteredDataclass.fragments4AssignmentOrParameters], value=astCallTargetCallable)))
|
|
283
|
+
unpack4targetCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier)), Then.insertThisAbove(shatteredDataclass.listUnpack))
|
|
284
|
+
repack4targetCallable = NodeChanger(IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier)), Then.insertThisBelow([shatteredDataclass.repack]))
|
|
455
285
|
replaceAssignTargetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
456
286
|
unpack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
457
287
|
repack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
@@ -491,7 +321,7 @@ def Z0Z_lameFindReplace(astTree: 个, mappingFindReplaceNodes: Mapping[ast.AST,
|
|
|
491
321
|
|
|
492
322
|
while keepGoing:
|
|
493
323
|
for nodeFind, nodeReplace in mappingFindReplaceNodes.items():
|
|
494
|
-
NodeChanger(
|
|
324
|
+
NodeChanger(IfThis.unparseIs(nodeFind), Then.replaceWith(nodeReplace)).visit(newTree)
|
|
495
325
|
|
|
496
326
|
if ast.unparse(newTree) == ast.unparse(astTree):
|
|
497
327
|
keepGoing = False
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: Map folding algorithm with code transformation framework for optimizing numerical computations
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
6
|
License: CC-BY-NC-4.0
|
|
@@ -31,6 +31,7 @@ Classifier: Typing :: Typed
|
|
|
31
31
|
Requires-Python: >=3.10
|
|
32
32
|
Description-Content-Type: text/markdown
|
|
33
33
|
License-File: LICENSE
|
|
34
|
+
Requires-Dist: astToolkit
|
|
34
35
|
Requires-Dist: autoflake
|
|
35
36
|
Requires-Dist: cytoolz
|
|
36
37
|
Requires-Dist: more_itertools
|
|
@@ -41,6 +42,7 @@ Requires-Dist: platformdirs
|
|
|
41
42
|
Requires-Dist: python_minifier
|
|
42
43
|
Requires-Dist: sympy
|
|
43
44
|
Requires-Dist: tomli
|
|
45
|
+
Requires-Dist: typeshed_client
|
|
44
46
|
Requires-Dist: Z0Z_tools
|
|
45
47
|
Provides-Extra: testing
|
|
46
48
|
Requires-Dist: mypy; extra == "testing"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
mapFolding/__init__.py,sha256=
|
|
1
|
+
mapFolding/__init__.py,sha256=B_Z9mhM5c_ro4rDOkIGADeg7tec8dkuY5UDp0JjjR4M,5456
|
|
2
2
|
mapFolding/basecamp.py,sha256=hs7hlTmbX7KTjI_eIRVU4xn7HR4l448SIpHk1cKDwRk,8071
|
|
3
3
|
mapFolding/beDRY.py,sha256=JQ7T9v4aKzweGjvpzyghyq4N9l3Wf9HZco_K_DWoiW0,15368
|
|
4
4
|
mapFolding/daoOfMapFolding.py,sha256=ncTIiBfTsM8SNVx9qefZ0bBcBtviWLSk4iPv3Z9nGiE,5442
|
|
@@ -22,20 +22,15 @@ mapFolding/reference/jobsCompleted/__init__.py,sha256=TU93ZGUW1xEkT6d9mQFn_rp5Dv
|
|
|
22
22
|
mapFolding/reference/jobsCompleted/[2x19]/p2x19.py,sha256=_tvYtfzMWVo2VtUbIAieoscb4N8FFflgTdW4-ljBUuA,19626
|
|
23
23
|
mapFolding/reference/jobsCompleted/p2x19/p2x19.py,sha256=eZEw4Me4ocTt6VXoK2-Sbd5SowZtxRIbN9dZmc7OCVg,6395
|
|
24
24
|
mapFolding/someAssemblyRequired/RecipeJob.py,sha256=6RD4F4Yde7K-Rz0F4IokQ62BVzRSx4vCCYY4H-Dfug4,10190
|
|
25
|
-
mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py,sha256=
|
|
26
|
-
mapFolding/someAssemblyRequired/__init__.py,sha256=
|
|
27
|
-
mapFolding/someAssemblyRequired/
|
|
28
|
-
mapFolding/someAssemblyRequired/
|
|
29
|
-
mapFolding/someAssemblyRequired/_tool_Then.py,sha256=8gdAQ7NPHzS6Q_NERbjzA3JtyO2N62jOmiDOx9Tq1l8,6168
|
|
30
|
-
mapFolding/someAssemblyRequired/_toolboxAST.py,sha256=Wm0XUqqxKbwu1kIQ1F6iXEP2z25qmr1JsZ2CeWMBtLg,2376
|
|
31
|
-
mapFolding/someAssemblyRequired/_toolboxAntecedents.py,sha256=i1jOdK1nJlA0blbVlCWJf-CeHyPgUf7QMQSFm1BrhQ8,16682
|
|
32
|
-
mapFolding/someAssemblyRequired/_toolboxContainers.py,sha256=Qtf1vGPIYQ9g2bOiupkm_-T4Qsr7p14SSI9eXcmT54M,30125
|
|
33
|
-
mapFolding/someAssemblyRequired/_toolboxPython.py,sha256=1K7IzqzmHNTaPA6qTo73GZYHCIQRYI2Rn8aYJ3VelqY,7873
|
|
25
|
+
mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py,sha256=Zx79EU4FTvnquAJMHr_rY1mzsyBsHEaeuu0LHRIFFSc,15804
|
|
26
|
+
mapFolding/someAssemblyRequired/__init__.py,sha256=GpYUilSfkAfITY-yJ2najnIlDGY4w0m706wrrOlhDmE,3397
|
|
27
|
+
mapFolding/someAssemblyRequired/_toolIfThis.py,sha256=IoCmO4vs4ElMPW7_ToPhWWnywCCzy0WZTSjcGD4kxZQ,2809
|
|
28
|
+
mapFolding/someAssemblyRequired/_toolboxContainers.py,sha256=83unP2rX8kJ_xSnPcZ3bJ8eanNQHwy0jLb9OP3cz5Gw,15872
|
|
34
29
|
mapFolding/someAssemblyRequired/getLLVMforNoReason.py,sha256=9RPU6vK_eUg64GtVFI_nZnvUryXw8gfHJs9NyDYHIvg,2745
|
|
35
|
-
mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=
|
|
36
|
-
mapFolding/someAssemblyRequired/synthesizeNumbaJob.py,sha256=
|
|
37
|
-
mapFolding/someAssemblyRequired/toolboxNumba.py,sha256=
|
|
38
|
-
mapFolding/someAssemblyRequired/transformationTools.py,sha256=
|
|
30
|
+
mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=7lF-5XLWrxbIukSClkkzjeSl8xBaot9Hg_4QrQ3UNe4,13846
|
|
31
|
+
mapFolding/someAssemblyRequired/synthesizeNumbaJob.py,sha256=nnTBe9XBFCNYKw-m_ZLAqfjHI9YEgAYx0rcUbihmG1Q,15667
|
|
32
|
+
mapFolding/someAssemblyRequired/toolboxNumba.py,sha256=QIpYCf1IFfgrQ5GVA0ON0ymn324iBfkyHVSfBW5CqOY,8961
|
|
33
|
+
mapFolding/someAssemblyRequired/transformationTools.py,sha256=snv0RB2Lfp50hIDL6BL7RVg3_gPkpQ2PPZF7-ldS7fI,20414
|
|
39
34
|
mapFolding/syntheticModules/__init__.py,sha256=evVFqhCGa-WZKDiLcnQWjs-Bj34eRnfSLqz_d7dFYZY,83
|
|
40
35
|
mapFolding/syntheticModules/daoOfMapFolding.py,sha256=cfWPABtXyCxJ0BwPI7rhfLh_2UYV_XKAL8lJ4GLNXaQ,5896
|
|
41
36
|
mapFolding/syntheticModules/dataPacking.py,sha256=J4WLJzQTOAm2d8itzWWSixTUcCGQl4KuEfqrzkb2tJQ,2294
|
|
@@ -44,7 +39,7 @@ mapFolding/syntheticModules/numbaCount.py,sha256=zM-bp07c9tEDdvidwzZ_bJTd0JC0VUk
|
|
|
44
39
|
mapFolding/syntheticModules/theorem2.py,sha256=9jrbZNNX4BWYZW1S0JjvRY2k7RU7I1RNUMV7JdCt1ZY,3017
|
|
45
40
|
mapFolding/syntheticModules/theorem2Numba.py,sha256=-cKjNyxgUMFhEyFVs0VJ7hw4LfrV0WSNK5tPYbQ1oNU,3369
|
|
46
41
|
mapFolding/syntheticModules/theorem2Trimmed.py,sha256=DHW3NxBdtABQYBKm2WRvfQ5kzc2_UwGI2h4ePuYEJoM,2685
|
|
47
|
-
mapfolding-0.
|
|
42
|
+
mapfolding-0.11.0.dist-info/licenses/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
|
|
48
43
|
tests/__init__.py,sha256=5VhHf0JJ2_DSh58zJ0rR5UkpoCon-0IkdljspTCzZ04,1950
|
|
49
44
|
tests/conftest.py,sha256=x8zMZQyTss3sn0GwHm_TSRwD9_LVlR8l_qF8r43Vxl4,14178
|
|
50
45
|
tests/test_computations.py,sha256=5sg1PpSp6aeOrXZeO5NwWK5ipPAe49wVKC2J7yT5MFg,6524
|
|
@@ -52,8 +47,8 @@ tests/test_filesystem.py,sha256=T2DkjBoI3lW6tCxd5BilPmUFrVukNKLjOOZVZxLM560,3004
|
|
|
52
47
|
tests/test_oeis.py,sha256=uxvwmgbnylSDdsVJfuAT0LuYLbIVFwSgdLxHm-xUGBM,5043
|
|
53
48
|
tests/test_other.py,sha256=UMlK4JPInalpOZuPvTnUrgXWCJOxAw-OsPs6CxMR254,3753
|
|
54
49
|
tests/test_tasks.py,sha256=tOQc4uomKXGwWnENfbcThaVa1XofwXNCkGZbg4yS6VI,2833
|
|
55
|
-
mapfolding-0.
|
|
56
|
-
mapfolding-0.
|
|
57
|
-
mapfolding-0.
|
|
58
|
-
mapfolding-0.
|
|
59
|
-
mapfolding-0.
|
|
50
|
+
mapfolding-0.11.0.dist-info/METADATA,sha256=8Blxgr_WJnTxgtvXDTLjxM-hh5c6GRhpig0B9za32Dg,7560
|
|
51
|
+
mapfolding-0.11.0.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
|
52
|
+
mapfolding-0.11.0.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
53
|
+
mapfolding-0.11.0.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
|
|
54
|
+
mapfolding-0.11.0.dist-info/RECORD,,
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
from mapFolding import astDOTParamSpec, astDOTTryStar, astDOTtype_param, astDOTTypeAlias, astDOTTypeVar, astDOTTypeVarTuple
|
|
2
|
-
from typing import Any, TypeAlias as typing_TypeAlias, TypeVar as typing_TypeVar
|
|
3
|
-
import ast
|
|
4
|
-
|
|
5
|
-
# TODO understand typing.
|
|
6
|
-
|
|
7
|
-
stuPyd: typing_TypeAlias = str
|
|
8
|
-
|
|
9
|
-
# NOTE An idea to subclass antecedents to effectively TypeGuard more than just the top level of the antecedent.
|
|
10
|
-
class ImaCallToName(ast.Call):
|
|
11
|
-
func: ast.Name # pyright: ignore[reportIncompatibleVariableOverride]
|
|
12
|
-
# assert isinstance(ast.Call.func, ast.Name), "brinkmanship"
|
|
13
|
-
# func: ast.Name
|
|
14
|
-
|
|
15
|
-
# Some common attributes of ast classes.
|
|
16
|
-
astClassHasDOTbody_expr: typing_TypeAlias = ast.Expression | ast.IfExp | ast.Lambda
|
|
17
|
-
astClassHasDOTbodyList_stmt: typing_TypeAlias = ast.AsyncFor | ast.AsyncWith | ast.ClassDef | ast.ExceptHandler | ast.For | ast.FunctionDef | ast.If | ast.Interactive | ast.match_case | ast.Module | ast.Try | astDOTTryStar | ast.While | ast.With
|
|
18
|
-
astClassHasDOTbody: typing_TypeAlias = astClassHasDOTbody_expr | astClassHasDOTbodyList_stmt
|
|
19
|
-
|
|
20
|
-
astClassHasDOTnameNotNameAlways: typing_TypeAlias = ast.alias | ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | astDOTParamSpec | astDOTTypeVar | astDOTTypeVarTuple
|
|
21
|
-
astClassHasDOTnameNotNameOptionally: typing_TypeAlias = ast.ExceptHandler | ast.MatchAs | ast.MatchStar
|
|
22
|
-
astClassHasDOTnameNotName: typing_TypeAlias = astClassHasDOTnameNotNameAlways | astClassHasDOTnameNotNameOptionally
|
|
23
|
-
|
|
24
|
-
astClassHasDOTtargetAttributeNameSubscript: typing_TypeAlias = ast.AnnAssign | ast.AugAssign
|
|
25
|
-
astClassHasDOTtarget_expr: typing_TypeAlias = ast.AsyncFor | ast.comprehension | ast.For
|
|
26
|
-
astClassHasDOTtarget: typing_TypeAlias = ast.NamedExpr | astClassHasDOTtarget_expr | astClassHasDOTtargetAttributeNameSubscript
|
|
27
|
-
|
|
28
|
-
astClassHasDOTvalue_expr: typing_TypeAlias = ast.Assign | ast.Attribute | ast.AugAssign | ast.Await | ast.DictComp | ast.Expr | ast.FormattedValue | ast.keyword | ast.MatchValue | ast.NamedExpr | ast.Starred | ast.Subscript | astDOTTypeAlias | ast.YieldFrom
|
|
29
|
-
astClassHasDOTvalue_exprNone: typing_TypeAlias = ast.AnnAssign | ast.Return | ast.Yield
|
|
30
|
-
astClassHasDOTvalue: typing_TypeAlias = ast.Constant | ast.MatchSingleton | astClassHasDOTvalue_expr | astClassHasDOTvalue_exprNone
|
|
31
|
-
|
|
32
|
-
# Type hints through TypeAlias or type "hints" through the identifier name.
|
|
33
|
-
ast_expr_Slice: typing_TypeAlias = ast.expr
|
|
34
|
-
ast_Identifier: typing_TypeAlias = str
|
|
35
|
-
intORlist_ast_type_paramORstr_orNone: typing_TypeAlias = Any
|
|
36
|
-
intORstr_orNone: typing_TypeAlias = Any
|
|
37
|
-
list_ast_type_paramORstr_orNone: typing_TypeAlias = Any
|
|
38
|
-
str_nameDOTname: typing_TypeAlias = stuPyd
|
|
39
|
-
|
|
40
|
-
# Limited success with TypeVar.
|
|
41
|
-
个 = typing_TypeVar('个', bound = ast.AST, covariant = True)
|
|
42
|
-
NodeORattribute = typing_TypeVar('NodeORattribute', bound = ast.AST | ast_expr_Slice | ast_Identifier | str_nameDOTname | bool | Any | None, covariant = True)
|
|
43
|
-
|
|
44
|
-
# For my reference, all ast classes by subgroup:
|
|
45
|
-
Ima_ast_boolop: typing_TypeAlias = ast.boolop | ast.And | ast.Or
|
|
46
|
-
Ima_ast_cmpop: typing_TypeAlias = ast.cmpop | ast.Eq | ast.NotEq | ast.Lt | ast.LtE | ast.Gt | ast.GtE | ast.Is | ast.IsNot | ast.In | ast.NotIn
|
|
47
|
-
Ima_ast_excepthandler: typing_TypeAlias = ast.excepthandler | ast.ExceptHandler
|
|
48
|
-
Ima_ast_expr_context: typing_TypeAlias = ast.expr_context | ast.Load | ast.Store | ast.Del
|
|
49
|
-
Ima_ast_expr: typing_TypeAlias = ast.expr | ast.Attribute | ast.Await | ast.BinOp | ast.BoolOp | ast.Call | ast.Compare | ast.Constant | ast.Dict | ast.DictComp | ast.FormattedValue | ast.GeneratorExp | ast.IfExp | ast.JoinedStr | ast.Lambda | ast.List | ast.ListComp | ast.Name | ast.NamedExpr | ast.Set | ast.SetComp | ast.Slice | ast.Starred | ast.Subscript | ast.Tuple | ast.UnaryOp | ast.Yield | ast.YieldFrom
|
|
50
|
-
Ima_ast_mod: typing_TypeAlias = ast.mod | ast.Expression | ast.FunctionType | ast.Interactive | ast.Module
|
|
51
|
-
Ima_ast_operator: typing_TypeAlias = ast.operator | ast.Add | ast.Sub | ast.Mult | ast.MatMult | ast.Div | ast.Mod | ast.Pow | ast.LShift | ast.RShift | ast.BitOr | ast.BitXor | ast.BitAnd | ast.FloorDiv
|
|
52
|
-
Ima_ast_orphan = ast.alias | ast.arg | ast.arguments | ast.comprehension | ast.keyword | ast.match_case | ast.withitem
|
|
53
|
-
iMa_ast_pattern: typing_TypeAlias = ast.pattern | ast.MatchAs | ast.MatchClass | ast.MatchMapping | ast.MatchOr | ast.MatchSequence | ast.MatchSingleton | ast.MatchStar | ast.MatchValue
|
|
54
|
-
Ima_ast_stmt: typing_TypeAlias = ast.stmt | ast.AnnAssign | ast.Assert | ast.Assign | ast.AsyncFor | ast.AsyncFunctionDef | ast.AsyncWith | ast.AugAssign | ast.Break | ast.ClassDef | ast.Continue | ast.Delete | ast.Expr | ast.For | ast.FunctionDef | ast.Global | ast.If | ast.Import | ast.ImportFrom | ast.Match | ast.Nonlocal | ast.Pass | ast.Raise | ast.Return | ast.Try | astDOTTryStar | astDOTTypeAlias | ast.While | ast.With
|
|
55
|
-
Ima_ast_type_ignore: typing_TypeAlias = ast.type_ignore | ast.TypeIgnore
|
|
56
|
-
Ima_ast_type_param: typing_TypeAlias = astDOTtype_param | astDOTParamSpec | astDOTTypeVar | astDOTTypeVarTuple
|
|
57
|
-
Ima_ast_unaryop: typing_TypeAlias = ast.unaryop | ast.Invert | ast.Not | ast.UAdd | ast.USub
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
AST Node Construction Utilities for Python Code Generation
|
|
3
|
-
|
|
4
|
-
This module provides the Make class with static methods for creating AST nodes with sane defaults. It abstracts away the
|
|
5
|
-
complexity of constructing AST nodes directly, making programmatic code generation more intuitive and less error-prone.
|
|
6
|
-
|
|
7
|
-
The Make class serves as a factory for creating various types of AST nodes needed in code generation, transformation,
|
|
8
|
-
and analysis workflows. Each method follows a consistent pattern that maps cleanly to Python's syntax while handling the
|
|
9
|
-
details of AST node construction.
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
from collections.abc import Sequence
|
|
13
|
-
from mapFolding.someAssemblyRequired import (
|
|
14
|
-
ast_expr_Slice,
|
|
15
|
-
ast_Identifier,
|
|
16
|
-
intORlist_ast_type_paramORstr_orNone,
|
|
17
|
-
intORstr_orNone,
|
|
18
|
-
list_ast_type_paramORstr_orNone,
|
|
19
|
-
str_nameDOTname,
|
|
20
|
-
)
|
|
21
|
-
from typing import Any
|
|
22
|
-
import ast
|
|
23
|
-
|
|
24
|
-
class Make:
|
|
25
|
-
"""Almost all parameters described here are only accessible through a method's `**keywordArguments` parameter.
|
|
26
|
-
|
|
27
|
-
Parameters:
|
|
28
|
-
context (ast.Load()): Are you loading from, storing to, or deleting the identifier? The `context` (also, `ctx`) value is `ast.Load()`, `ast.Store()`, or `ast.Del()`.
|
|
29
|
-
col_offset (0): int Position information specifying the column where an AST node begins.
|
|
30
|
-
end_col_offset (None): int|None Position information specifying the column where an AST node ends.
|
|
31
|
-
end_lineno (None): int|None Position information specifying the line number where an AST node ends.
|
|
32
|
-
level (0): int Module import depth level that controls relative vs absolute imports. Default 0 indicates absolute import.
|
|
33
|
-
lineno: int Position information manually specifying the line number where an AST node begins.
|
|
34
|
-
kind (None): str|None Used for type annotations in limited cases.
|
|
35
|
-
type_comment (None): str|None "type_comment is an optional string with the type annotation as a comment." or `# type: ignore`.
|
|
36
|
-
type_params: list[ast.type_param] Type parameters for generic type definitions.
|
|
37
|
-
|
|
38
|
-
The `ast._Attributes`, lineno, col_offset, end_lineno, and end_col_offset, hold position information; however, they are, importantly, _not_ `ast._fields`.
|
|
39
|
-
"""
|
|
40
|
-
@staticmethod
|
|
41
|
-
def alias(name: ast_Identifier, asname: ast_Identifier | None = None) -> ast.alias:
|
|
42
|
-
return ast.alias(name, asname)
|
|
43
|
-
|
|
44
|
-
@staticmethod
|
|
45
|
-
def AnnAssign(target: ast.Attribute | ast.Name | ast.Subscript, annotation: ast.expr, value: ast.expr | None = None, **keywordArguments: int) -> ast.AnnAssign: # `simple: int`: uses a clever int-from-boolean to assign the correct value to the `simple` attribute. So, don't make it a method parameter.
|
|
46
|
-
return ast.AnnAssign(target, annotation, value, simple=int(isinstance(target, ast.Name)), **keywordArguments)
|
|
47
|
-
|
|
48
|
-
@staticmethod
|
|
49
|
-
def arg(identifier: ast_Identifier, annotation: ast.expr | None = None, **keywordArguments: intORstr_orNone) -> ast.arg:
|
|
50
|
-
return ast.arg(identifier, annotation, **keywordArguments)
|
|
51
|
-
|
|
52
|
-
@staticmethod
|
|
53
|
-
def argumentsSpecification(posonlyargs:list[ast.arg]=[], args:list[ast.arg]=[], vararg:ast.arg|None=None, kwonlyargs:list[ast.arg]=[], kw_defaults:list[ast.expr|None]=[None], kwarg:ast.arg|None=None, defaults:list[ast.expr]=[]) -> ast.arguments:
|
|
54
|
-
return ast.arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, defaults)
|
|
55
|
-
|
|
56
|
-
@staticmethod
|
|
57
|
-
def Assign(listTargets: list[ast.expr], value: ast.expr, **keywordArguments: intORstr_orNone) -> ast.Assign:
|
|
58
|
-
return ast.Assign(listTargets, value, **keywordArguments)
|
|
59
|
-
|
|
60
|
-
@staticmethod
|
|
61
|
-
def Attribute(value: ast.expr, *attribute: ast_Identifier, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Attribute:
|
|
62
|
-
""" If two `ast_Identifier` are joined by a dot `.`, they are _usually_ an `ast.Attribute`, but see `ast.ImportFrom`.
|
|
63
|
-
Parameters:
|
|
64
|
-
value: the part before the dot (e.g., `ast.Name`.)
|
|
65
|
-
attribute: an `ast_Identifier` after a dot `.`; you can pass multiple `attribute` and they will be chained together.
|
|
66
|
-
"""
|
|
67
|
-
def addDOTattribute(chain: ast.expr, identifier: ast_Identifier, context: ast.expr_context, **keywordArguments: int) -> ast.Attribute:
|
|
68
|
-
return ast.Attribute(value=chain, attr=identifier, ctx=context, **keywordArguments)
|
|
69
|
-
buffaloBuffalo = addDOTattribute(value, attribute[0], context, **keywordArguments)
|
|
70
|
-
for identifier in attribute[1:None]:
|
|
71
|
-
buffaloBuffalo = addDOTattribute(buffaloBuffalo, identifier, context, **keywordArguments)
|
|
72
|
-
return buffaloBuffalo
|
|
73
|
-
|
|
74
|
-
@staticmethod
|
|
75
|
-
def AugAssign(target: ast.Attribute | ast.Name | ast.Subscript, operator: ast.operator, value: ast.expr, **keywordArguments: int) -> ast.AugAssign:
|
|
76
|
-
return ast.AugAssign(target, operator, value, **keywordArguments)
|
|
77
|
-
|
|
78
|
-
@staticmethod
|
|
79
|
-
def Call(callee: ast.expr, listArguments: Sequence[ast.expr] | None = None, list_astKeywords: Sequence[ast.keyword] | None = None) -> ast.Call:
|
|
80
|
-
return ast.Call(func=callee, args=list(listArguments) if listArguments else [], keywords=list(list_astKeywords) if list_astKeywords else [])
|
|
81
|
-
|
|
82
|
-
@staticmethod
|
|
83
|
-
def ClassDef(name: ast_Identifier, listBases: list[ast.expr]=[], list_keyword: list[ast.keyword]=[], body: list[ast.stmt]=[], decorator_list: list[ast.expr]=[], **keywordArguments: list_ast_type_paramORstr_orNone) -> ast.ClassDef:
|
|
84
|
-
return ast.ClassDef(name, listBases, list_keyword, body, decorator_list, **keywordArguments)
|
|
85
|
-
|
|
86
|
-
@staticmethod
|
|
87
|
-
def Constant(value: Any, **keywordArguments: intORstr_orNone) -> ast.Constant:
|
|
88
|
-
return ast.Constant(value, **keywordArguments)
|
|
89
|
-
|
|
90
|
-
@staticmethod
|
|
91
|
-
def Expr(value: ast.expr, **keywordArguments: int) -> ast.Expr:
|
|
92
|
-
return ast.Expr(value, **keywordArguments)
|
|
93
|
-
|
|
94
|
-
@staticmethod
|
|
95
|
-
def FunctionDef(name: ast_Identifier, argumentsSpecification:ast.arguments=ast.arguments(), body:list[ast.stmt]=[], decorator_list:list[ast.expr]=[], returns:ast.expr|None=None, **keywordArguments: intORlist_ast_type_paramORstr_orNone) -> ast.FunctionDef:
|
|
96
|
-
return ast.FunctionDef(name, argumentsSpecification, body, decorator_list, returns, **keywordArguments)
|
|
97
|
-
|
|
98
|
-
@staticmethod
|
|
99
|
-
def Import(moduleWithLogicalPath: str_nameDOTname, asname: ast_Identifier | None = None, **keywordArguments: int) -> ast.Import:
|
|
100
|
-
return ast.Import(names=[Make.alias(moduleWithLogicalPath, asname)], **keywordArguments)
|
|
101
|
-
|
|
102
|
-
@staticmethod
|
|
103
|
-
def ImportFrom(moduleWithLogicalPath: str_nameDOTname, list_astAlias: list[ast.alias], **keywordArguments: int) -> ast.ImportFrom:
|
|
104
|
-
return ast.ImportFrom(moduleWithLogicalPath, list_astAlias, **keywordArguments)
|
|
105
|
-
|
|
106
|
-
@staticmethod
|
|
107
|
-
def keyword(keywordArgument: ast_Identifier, value: ast.expr, **keywordArguments: int) -> ast.keyword:
|
|
108
|
-
return ast.keyword(arg=keywordArgument, value=value, **keywordArguments)
|
|
109
|
-
|
|
110
|
-
@staticmethod
|
|
111
|
-
def Module(body: list[ast.stmt] = [], type_ignores: list[ast.TypeIgnore] = []) -> ast.Module:
|
|
112
|
-
return ast.Module(body, type_ignores)
|
|
113
|
-
|
|
114
|
-
@staticmethod
|
|
115
|
-
def Name(identifier: ast_Identifier, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Name:
|
|
116
|
-
return ast.Name(identifier, context, **keywordArguments)
|
|
117
|
-
|
|
118
|
-
@staticmethod
|
|
119
|
-
def Return(value: ast.expr | None = None, **keywordArguments: int) -> ast.Return:
|
|
120
|
-
return ast.Return(value, **keywordArguments)
|
|
121
|
-
|
|
122
|
-
@staticmethod
|
|
123
|
-
def Subscript(value: ast.expr, slice: ast_expr_Slice, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Subscript:
|
|
124
|
-
return ast.Subscript(value, slice, context, **keywordArguments)
|
|
125
|
-
|
|
126
|
-
@staticmethod
|
|
127
|
-
def Tuple(elements: Sequence[ast.expr] = [], context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Tuple:
|
|
128
|
-
return ast.Tuple(list(elements), context, **keywordArguments)
|
|
129
|
-
|
|
130
|
-
@staticmethod
|
|
131
|
-
def While(test: ast.expr, doThis: list[ast.stmt], orElse: list[ast.stmt] = [], **keywordArguments: int) -> ast.While:
|
|
132
|
-
return ast.While(test, doThis, orElse, **keywordArguments)
|