mapFolding 0.16.0__py3-none-any.whl → 0.16.2__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.
- easyRun/A000682.py +25 -0
- easyRun/A005316.py +20 -0
- easyRun/NOTcountingFolds.py +36 -0
- easyRun/__init__.py +0 -0
- easyRun/countFolds.py +41 -0
- easyRun/meanders.py +69 -0
- mapFolding/__init__.py +8 -51
- mapFolding/_dataPacking.py +68 -0
- mapFolding/_theSSOT.py +33 -37
- mapFolding/_theTypes.py +21 -4
- mapFolding/algorithms/matrixMeanders.py +86 -517
- mapFolding/algorithms/matrixMeandersBeDry.py +182 -0
- mapFolding/algorithms/matrixMeandersNumPy.py +333 -0
- mapFolding/algorithms/matrixMeandersPandas.py +334 -0
- mapFolding/algorithms/oeisIDbyFormula.py +50 -29
- mapFolding/algorithms/zCuzDocStoopidoeisIDbyFormula.py +51 -29
- mapFolding/basecamp.py +167 -206
- mapFolding/beDRY.py +2 -30
- mapFolding/dataBaskets.py +75 -49
- mapFolding/oeis.py +11 -32
- mapFolding/reference/A000682facts.py +787 -652
- mapFolding/reference/A005316facts.py +961 -3
- mapFolding/reference/matrixMeandersAnalysis/prefixNotationNotes.py +15 -0
- mapFolding/reference/matrixMeandersAnalysis/signatures.py +2030 -0
- mapFolding/reference/meandersDumpingGround/A005316JavaPort.py +1 -1
- mapFolding/reference/meandersDumpingGround/A005316imperative.py +1 -1
- mapFolding/reference/meandersDumpingGround/matrixMeandersNumPyV1finalForm.py +424 -0
- mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +3 -4
- mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +103 -29
- mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +18 -14
- mapFolding/someAssemblyRequired/RecipeJob.py +2 -2
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +7 -6
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +3 -4
- mapFolding/someAssemblyRequired/makingModules_count.py +88 -87
- mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +10 -9
- mapFolding/someAssemblyRequired/mapFolding/makeMapFoldingModules.py +3 -3
- mapFolding/someAssemblyRequired/meanders/__init__.py +0 -0
- mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +63 -0
- mapFolding/someAssemblyRequired/toolkitMakeModules.py +37 -37
- mapFolding/someAssemblyRequired/transformationTools.py +8 -8
- mapFolding/syntheticModules/A007822/algorithm.py +3 -3
- mapFolding/syntheticModules/A007822/algorithmNumba.py +1 -2
- mapFolding/syntheticModules/A007822/asynchronous.py +6 -4
- mapFolding/syntheticModules/A007822/asynchronousAnnex.py +5 -7
- mapFolding/syntheticModules/A007822/asynchronousAnnexNumba.py +70 -0
- mapFolding/syntheticModules/A007822/asynchronousNumba.py +79 -0
- mapFolding/syntheticModules/A007822/asynchronousTheorem2.py +15 -3
- mapFolding/syntheticModules/A007822/asynchronousTrimmed.py +12 -3
- mapFolding/syntheticModules/A007822/initializeState.py +1 -2
- mapFolding/syntheticModules/A007822/theorem2.py +7 -2
- mapFolding/syntheticModules/A007822/theorem2Numba.py +31 -4
- mapFolding/syntheticModules/A007822/theorem2Trimmed.py +8 -3
- mapFolding/syntheticModules/countParallelNumba.py +5 -2
- mapFolding/syntheticModules/dataPacking.py +1 -1
- mapFolding/syntheticModules/dataPackingA007822.py +92 -26
- mapFolding/syntheticModules/meanders/__init__.py +1 -0
- mapFolding/syntheticModules/meanders/bigInt.py +52 -0
- mapFolding/syntheticModules/theorem2.py +6 -0
- mapFolding/syntheticModules/theorem2Numba.py +8 -2
- mapFolding/syntheticModules/theorem2Trimmed.py +6 -0
- mapFolding/tests/conftest.py +28 -13
- mapFolding/tests/test_computations.py +68 -61
- mapFolding/tests/test_oeis.py +6 -6
- mapFolding/zCuzDocStoopid/__init__.py +4 -1
- mapFolding/zCuzDocStoopid/makeDocstrings.py +35 -28
- mapfolding-0.16.2.dist-info/METADATA +99 -0
- mapfolding-0.16.2.dist-info/RECORD +115 -0
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/top_level.txt +1 -0
- mapFolding/algorithms/getBucketsTotal.py +0 -137
- mapFolding/reference/matrixMeandersAnalysis/evenEven.py +0 -144
- mapFolding/reference/matrixMeandersAnalysis/oddEven.py +0 -54
- mapFolding/trim_memory.py +0 -62
- mapfolding-0.16.0.dist-info/METADATA +0 -85
- mapfolding-0.16.0.dist-info/RECORD +0 -100
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.0.dist-info → mapfolding-0.16.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -11,8 +11,7 @@ from hunterMakesPy import raiseIfNone
|
|
|
11
11
|
from mapFolding import packageSettings
|
|
12
12
|
from mapFolding.someAssemblyRequired import (
|
|
13
13
|
identifierCallableSourceDEFAULT, identifierCountingDEFAULT, IfThis, ShatteredDataclass)
|
|
14
|
-
from mapFolding.someAssemblyRequired.
|
|
15
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import findDataclass, getPathFilename
|
|
14
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import findDataclass, getLogicalPath, getPathFilename
|
|
16
15
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
|
|
17
16
|
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
18
17
|
removeDataclassFromFunction, shatter_dataclassesDOTdataclass, unpackDataclassCallFunctionRepackDataclass)
|
|
@@ -21,29 +20,16 @@ from pathlib import PurePath
|
|
|
21
20
|
from typing import cast
|
|
22
21
|
import ast
|
|
23
22
|
|
|
24
|
-
def
|
|
25
|
-
"""Generate Numba-optimized sequential implementation of
|
|
26
|
-
|
|
27
|
-
(AI generated docstring)
|
|
28
|
-
|
|
29
|
-
Creates a high-performance sequential version of the map folding algorithm by
|
|
30
|
-
decomposing dataclass parameters into individual primitive values, removing
|
|
31
|
-
dataclass dependencies that are incompatible with Numba, applying Numba
|
|
32
|
-
decorators for just-in-time compilation, and optionally including a dispatcher
|
|
33
|
-
function for dataclass integration.
|
|
34
|
-
|
|
35
|
-
The generated module provides significant performance improvements over the
|
|
36
|
-
original dataclass-based implementation while maintaining algorithmic correctness.
|
|
37
|
-
The transformation preserves all computational logic while restructuring data
|
|
38
|
-
access patterns for optimal Numba compilation.
|
|
23
|
+
def makeMapFoldingNumba(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
24
|
+
"""Generate Numba-optimized sequential implementation of an algorithm.
|
|
39
25
|
|
|
40
26
|
Parameters
|
|
41
27
|
----------
|
|
42
28
|
astModule : ast.Module
|
|
43
29
|
Source module containing the base algorithm.
|
|
44
|
-
|
|
30
|
+
identifierModule : str
|
|
45
31
|
Name for the generated optimized module.
|
|
46
|
-
|
|
32
|
+
identifierCallable : str | None = None
|
|
47
33
|
Name for the main computational function.
|
|
48
34
|
logicalPathInfix : PathLike[str] | PurePath | str | None = None
|
|
49
35
|
Directory path for organizing the generated module.
|
|
@@ -56,9 +42,9 @@ def makeDaoOfMapFoldingNumba(astModule: ast.Module, moduleIdentifier: str, calla
|
|
|
56
42
|
Filesystem path where the optimized module was written.
|
|
57
43
|
|
|
58
44
|
"""
|
|
59
|
-
sourceCallableIdentifier:
|
|
45
|
+
sourceCallableIdentifier: str = identifierCallableSourceDEFAULT
|
|
60
46
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
61
|
-
ingredientsFunction.astFunctionDef.name =
|
|
47
|
+
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
62
48
|
|
|
63
49
|
shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(*findDataclass(ingredientsFunction))
|
|
64
50
|
|
|
@@ -88,46 +74,46 @@ def makeDaoOfMapFoldingNumba(astModule: ast.Module, moduleIdentifier: str, calla
|
|
|
88
74
|
|
|
89
75
|
ingredientsModule.removeImportFromModule('numpy')
|
|
90
76
|
|
|
91
|
-
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix,
|
|
77
|
+
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
92
78
|
|
|
93
79
|
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
94
80
|
|
|
95
81
|
return pathFilename
|
|
96
82
|
|
|
97
|
-
def makeTheorem2(astModule: ast.Module,
|
|
83
|
+
def makeTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
98
84
|
"""Generate module by applying optimization predicted by Theorem 2.
|
|
99
85
|
|
|
100
86
|
Parameters
|
|
101
87
|
----------
|
|
102
88
|
astModule : ast.Module
|
|
103
89
|
Source module containing the base algorithm.
|
|
104
|
-
|
|
90
|
+
identifierModule : str
|
|
105
91
|
Name for the generated theorem-optimized module.
|
|
106
|
-
|
|
92
|
+
identifierCallable : str | None = None
|
|
107
93
|
Name for the optimized computational function.
|
|
108
94
|
logicalPathInfix : PathLike[str] | PurePath | str | None = None
|
|
109
95
|
Directory path for organizing the generated module.
|
|
110
96
|
sourceCallableDispatcher : str | None = None
|
|
111
|
-
|
|
97
|
+
Optional dispatcher function identifier.
|
|
112
98
|
|
|
113
99
|
Returns
|
|
114
100
|
-------
|
|
115
101
|
pathFilename : PurePath
|
|
116
102
|
Filesystem path where the theorem-optimized module was written.
|
|
103
|
+
"""
|
|
104
|
+
identifierCallableInitializeDataclassHARDCODED = 'transitionOnGroupsOfFolds'
|
|
105
|
+
identifierModuleInitializeDataclassHARDCODED = 'initializeState'
|
|
117
106
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
NotImplementedError
|
|
121
|
-
If `sourceCallableDispatcher` is provided.
|
|
107
|
+
identifierCallableInitializeDataclass = identifierCallableInitializeDataclassHARDCODED
|
|
108
|
+
identifierModuleInitializeDataclass = identifierModuleInitializeDataclassHARDCODED
|
|
122
109
|
|
|
123
|
-
"""
|
|
124
110
|
sourceCallableIdentifier = identifierCallableSourceDEFAULT
|
|
125
111
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
126
|
-
ingredientsFunction.astFunctionDef.name =
|
|
112
|
+
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
127
113
|
|
|
128
|
-
dataclassInstanceIdentifier:
|
|
114
|
+
dataclassInstanceIdentifier: str = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
129
115
|
|
|
130
|
-
theCountingIdentifier:
|
|
116
|
+
theCountingIdentifier: str = identifierCountingDEFAULT
|
|
131
117
|
doubleTheCount: ast.AugAssign = Make.AugAssign(Make.Attribute(Make.Name(dataclassInstanceIdentifier), theCountingIdentifier), Make.Mult(), Make.Constant(2))
|
|
132
118
|
|
|
133
119
|
NodeChanger(
|
|
@@ -171,40 +157,41 @@ def makeTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifie
|
|
|
171
157
|
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
172
158
|
|
|
173
159
|
if sourceCallableDispatcher is not None:
|
|
174
|
-
|
|
175
|
-
|
|
160
|
+
ingredientsFunctionDispatcher: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableDispatcher)
|
|
161
|
+
targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
|
|
176
162
|
|
|
177
|
-
|
|
163
|
+
# Update any calls to the original function name with the new target function name
|
|
164
|
+
NodeChanger(
|
|
165
|
+
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(identifierCallableSourceDEFAULT)))
|
|
166
|
+
, doThat = Grab.funcAttribute(Grab.idAttribute(Then.replaceWith(targetCallableIdentifier)))
|
|
167
|
+
).visit(ingredientsFunctionDispatcher.astFunctionDef)
|
|
178
168
|
|
|
179
|
-
|
|
169
|
+
AssignInitializedDataclass: ast.Assign = Make.Assign([Make.Name(dataclassInstanceIdentifier)], value=Make.Call(Make.Name(identifierCallableInitializeDataclass), [Make.Name(dataclassInstanceIdentifier)]))
|
|
180
170
|
|
|
181
|
-
|
|
171
|
+
# Insert the transitionOnGroupsOfFolds call at the beginning of the function
|
|
172
|
+
ingredientsFunctionDispatcher.astFunctionDef.body.insert(0, AssignInitializedDataclass)
|
|
182
173
|
|
|
183
|
-
|
|
184
|
-
|
|
174
|
+
dotModule: identifierDotAttribute = getLogicalPath(packageSettings.identifierPackage, logicalPathInfix, identifierModuleInitializeDataclass)
|
|
175
|
+
ingredientsFunctionDispatcher.imports.addImportFrom_asStr(dotModule, identifierCallableInitializeDataclass)
|
|
176
|
+
|
|
177
|
+
ingredientsModule.appendIngredientsFunction(ingredientsFunctionDispatcher)
|
|
178
|
+
|
|
179
|
+
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
185
180
|
|
|
186
|
-
(
|
|
181
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
187
182
|
|
|
188
|
-
|
|
189
|
-
mathematical optimizations of Theorem 2 with Numba just-in-time compilation.
|
|
190
|
-
The transformation includes dataclass decomposition to convert structured
|
|
191
|
-
parameters into primitives, removal of Python object dependencies incompatible
|
|
192
|
-
with Numba, application of Numba decorators for maximum performance, and type
|
|
193
|
-
annotation optimization for efficient compilation.
|
|
183
|
+
return pathFilename
|
|
194
184
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
application and computational efficiency through Numba acceleration.
|
|
198
|
-
The result is suitable for production use in high-performance computing
|
|
199
|
-
environments where maximum speed is required.
|
|
185
|
+
def numbaOnTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
186
|
+
"""Generate Numba-accelerated Theorem 2 implementation with dataclass decomposition.
|
|
200
187
|
|
|
201
188
|
Parameters
|
|
202
189
|
----------
|
|
203
190
|
astModule : ast.Module
|
|
204
191
|
Source module containing the Theorem 2 implementation.
|
|
205
|
-
|
|
192
|
+
identifierModule : str
|
|
206
193
|
Name for the generated Numba-accelerated module.
|
|
207
|
-
|
|
194
|
+
identifierCallable : str | None = None
|
|
208
195
|
Name for the accelerated computational function.
|
|
209
196
|
logicalPathInfix : PathLike[str] | PurePath | str | None = None
|
|
210
197
|
Directory path for organizing the generated module.
|
|
@@ -218,54 +205,55 @@ def numbaOnTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdenti
|
|
|
218
205
|
|
|
219
206
|
"""
|
|
220
207
|
sourceCallableIdentifier = identifierCallableSourceDEFAULT
|
|
221
|
-
if callableIdentifier is None:
|
|
222
|
-
callableIdentifier = sourceCallableIdentifier
|
|
223
208
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
224
|
-
ingredientsFunction.astFunctionDef.name =
|
|
209
|
+
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
225
210
|
|
|
226
|
-
|
|
211
|
+
logicalPathDataclass, identifierDataclass, identifierDataclassInstance = findDataclass(ingredientsFunction)
|
|
212
|
+
|
|
213
|
+
shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(logicalPathDataclass, identifierDataclass, identifierDataclassInstance)
|
|
227
214
|
|
|
228
215
|
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
229
216
|
ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclass)
|
|
230
|
-
|
|
231
|
-
if sourceCallableDispatcher is not None:
|
|
232
|
-
NodeChanger(
|
|
233
|
-
findThis=IfThis.isCallIdentifier(sourceCallableDispatcher)
|
|
234
|
-
, doThat=Then.replaceWith(astExprCall_filterAsymmetricFoldsLeafBelow)
|
|
235
|
-
).visit(ingredientsFunction.astFunctionDef)
|
|
236
|
-
|
|
237
217
|
ingredientsFunction = removeUnusedParameters(ingredientsFunction)
|
|
238
218
|
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
239
219
|
|
|
240
220
|
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
241
221
|
ingredientsModule.removeImportFromModule('numpy')
|
|
242
222
|
|
|
243
|
-
|
|
223
|
+
if sourceCallableDispatcher is not None:
|
|
224
|
+
ingredientsFunctionDispatcher: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableDispatcher)
|
|
225
|
+
ingredientsFunctionDispatcher.imports.update(shatteredDataclass.imports)
|
|
226
|
+
targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
|
|
227
|
+
ingredientsFunctionDispatcher = unpackDataclassCallFunctionRepackDataclass(ingredientsFunctionDispatcher, targetCallableIdentifier, shatteredDataclass)
|
|
228
|
+
astTuple: ast.Tuple = cast('ast.Tuple', raiseIfNone(NodeTourist(Be.Return.valueIs(Be.Tuple)
|
|
229
|
+
, doThat=Then.extractIt(DOT.value)).captureLastMatch(ingredientsFunction.astFunctionDef)))
|
|
230
|
+
astTuple.ctx = Make.Store()
|
|
231
|
+
|
|
232
|
+
changeAssignCallToTarget = NodeChanger(
|
|
233
|
+
findThis = Be.Assign.valueIs(IfThis.isCallIdentifier(targetCallableIdentifier))
|
|
234
|
+
, doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts))))
|
|
235
|
+
changeAssignCallToTarget.visit(ingredientsFunctionDispatcher.astFunctionDef)
|
|
236
|
+
|
|
237
|
+
ingredientsModule.appendIngredientsFunction(ingredientsFunctionDispatcher)
|
|
238
|
+
|
|
239
|
+
ingredientsModule.removeImportFromModule('numpy')
|
|
240
|
+
|
|
241
|
+
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
244
242
|
|
|
245
243
|
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
246
244
|
|
|
247
245
|
return pathFilename
|
|
248
246
|
|
|
249
|
-
def trimTheorem2(astModule: ast.Module,
|
|
247
|
+
def trimTheorem2(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
250
248
|
"""Generate constrained Theorem 2 implementation by removing unnecessary logic.
|
|
251
249
|
|
|
252
|
-
(AI generated docstring)
|
|
253
|
-
|
|
254
|
-
Creates a trimmed version of the Theorem 2 implementation by eliminating conditional logic that is not needed under specific
|
|
255
|
-
constraint assumptions. This transformation removes checks for unconstrained dimensions, simplifying the algorithm for cases
|
|
256
|
-
where dimensional constraints are guaranteed to be satisfied by external conditions.
|
|
257
|
-
|
|
258
|
-
The trimming operation is particularly valuable for generating lean implementations where the calling context ensures that
|
|
259
|
-
certain conditions will always be met, allowing the removal of defensive programming constructs that add computational
|
|
260
|
-
overhead without providing benefits in the constrained environment.
|
|
261
|
-
|
|
262
250
|
Parameters
|
|
263
251
|
----------
|
|
264
252
|
astModule : ast.Module
|
|
265
253
|
Source module containing the Theorem 2 implementation.
|
|
266
|
-
|
|
254
|
+
identifierModule : str
|
|
267
255
|
Name for the generated trimmed module.
|
|
268
|
-
|
|
256
|
+
identifierCallable : str | None = None
|
|
269
257
|
Name for the trimmed computational function.
|
|
270
258
|
logicalPathInfix : PathLike[str] | PurePath | str | None = None
|
|
271
259
|
Directory path for organizing the generated module.
|
|
@@ -278,20 +266,33 @@ def trimTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifie
|
|
|
278
266
|
Filesystem path where the trimmed module was written.
|
|
279
267
|
|
|
280
268
|
"""
|
|
281
|
-
sourceCallableIdentifier = identifierCallableSourceDEFAULT
|
|
269
|
+
sourceCallableIdentifier: str = identifierCallableSourceDEFAULT
|
|
282
270
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
283
|
-
ingredientsFunction.astFunctionDef.name =
|
|
271
|
+
ingredientsFunction.astFunctionDef.name = identifierCallable or sourceCallableIdentifier
|
|
284
272
|
|
|
285
|
-
|
|
273
|
+
identifierDataclassInstance: str = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
286
274
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
275
|
+
NodeChanger(
|
|
276
|
+
findThis = IfThis.isIfUnaryNotAttributeNamespaceIdentifier(identifierDataclassInstance, 'dimensionsUnconstrained')
|
|
277
|
+
, doThat = Then.removeIt
|
|
278
|
+
).visit(ingredientsFunction.astFunctionDef)
|
|
290
279
|
|
|
291
280
|
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
292
281
|
ingredientsModule.removeImportFromModule('numpy')
|
|
293
282
|
|
|
294
|
-
|
|
283
|
+
if sourceCallableDispatcher is not None:
|
|
284
|
+
ingredientsFunctionDispatcher: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableDispatcher)
|
|
285
|
+
targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
|
|
286
|
+
|
|
287
|
+
# Update any calls to the original function name with the new target function name
|
|
288
|
+
NodeChanger(
|
|
289
|
+
findThis = Be.Call.funcIs(Be.Name.idIs(IfThis.isIdentifier(identifierCallableSourceDEFAULT)))
|
|
290
|
+
, doThat = Grab.funcAttribute(Grab.idAttribute(Then.replaceWith(targetCallableIdentifier)))
|
|
291
|
+
).visit(ingredientsFunctionDispatcher.astFunctionDef)
|
|
292
|
+
|
|
293
|
+
ingredientsModule.appendIngredientsFunction(ingredientsFunctionDispatcher)
|
|
294
|
+
|
|
295
|
+
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
295
296
|
|
|
296
297
|
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
297
298
|
|
|
@@ -17,7 +17,7 @@ from pathlib import PurePath
|
|
|
17
17
|
from typing import cast
|
|
18
18
|
import ast
|
|
19
19
|
|
|
20
|
-
def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix:
|
|
20
|
+
def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
21
21
|
"""Generate initialization module for counting variable setup.
|
|
22
22
|
|
|
23
23
|
(AI generated docstring)
|
|
@@ -65,8 +65,7 @@ def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableId
|
|
|
65
65
|
|
|
66
66
|
return pathFilename
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
def makeUnRePackDataclass(astImportFrom: ast.ImportFrom, moduleIdentifier: str = identifierModuleDataPackingDEFAULT) -> None:
|
|
68
|
+
def makeUnRePackDataclass(astImportFrom: ast.ImportFrom, moduleIdentifier: str = identifierModuleDataPackingDEFAULT) -> PurePath:
|
|
70
69
|
"""Generate interface module for dataclass unpacking and repacking operations.
|
|
71
70
|
|
|
72
71
|
Parameters
|
|
@@ -74,19 +73,21 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom, moduleIdentifier: str =
|
|
|
74
73
|
astImportFrom : ast.ImportFrom
|
|
75
74
|
Import statement specifying the target optimized function to call.
|
|
76
75
|
|
|
76
|
+
moduleIdentifier : str = identifierModuleDataPackingDEFAULT
|
|
77
|
+
Name for the generated interface module.
|
|
78
|
+
|
|
77
79
|
Returns
|
|
78
80
|
-------
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
pathFilename : PurePath
|
|
82
|
+
Filesystem path where the interface module was written.
|
|
82
83
|
"""
|
|
83
84
|
callableIdentifierHARDCODED: str = 'sequential'
|
|
84
85
|
|
|
85
86
|
algorithmSourceModule: identifierDotAttribute = identifierModuleSourceAlgorithmDEFAULT
|
|
86
|
-
callableIdentifier:
|
|
87
|
+
callableIdentifier: str = callableIdentifierHARDCODED
|
|
87
88
|
logicalPathInfix: identifierDotAttribute = logicalPathInfixDEFAULT
|
|
88
89
|
logicalPathInfixAlgorithm: identifierDotAttribute = logicalPathInfixAlgorithmDEFAULT
|
|
89
|
-
sourceCallableIdentifier:
|
|
90
|
+
sourceCallableIdentifier: str = identifierCallableSourceDispatcherDEFAULT
|
|
90
91
|
|
|
91
92
|
logicalPathSourceModule: identifierDotAttribute = '.'.join([packageSettings.identifierPackage, logicalPathInfixAlgorithm, algorithmSourceModule]) # noqa: FLY002
|
|
92
93
|
|
|
@@ -116,5 +117,5 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom, moduleIdentifier: str =
|
|
|
116
117
|
|
|
117
118
|
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
118
119
|
|
|
119
|
-
|
|
120
|
+
return pathFilename
|
|
120
121
|
|
|
@@ -10,7 +10,7 @@ from mapFolding.someAssemblyRequired import (
|
|
|
10
10
|
DeReConstructField2ast, identifierCallableSourceDEFAULT, identifierCallableSourceDispatcherDEFAULT, IfThis,
|
|
11
11
|
logicalPathInfixDEFAULT, ShatteredDataclass)
|
|
12
12
|
from mapFolding.someAssemblyRequired.makingModules_count import (
|
|
13
|
-
|
|
13
|
+
makeMapFoldingNumba, makeTheorem2, numbaOnTheorem2, trimTheorem2)
|
|
14
14
|
from mapFolding.someAssemblyRequired.makingModules_doTheNeedful import makeInitializeState, makeUnRePackDataclass
|
|
15
15
|
from mapFolding.someAssemblyRequired.toolkitMakeModules import getLogicalPath, getModule, getPathFilename
|
|
16
16
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
|
|
@@ -196,7 +196,7 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
196
196
|
def makeMapFoldingModules() -> None:
|
|
197
197
|
"""Make multidimensional map folding modules."""
|
|
198
198
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
199
|
-
pathFilename: PurePath =
|
|
199
|
+
pathFilename: PurePath = makeMapFoldingNumba(astModule, 'daoOfMapFoldingNumba', None, logicalPathInfixDEFAULT, identifierCallableSourceDispatcherDEFAULT)
|
|
200
200
|
|
|
201
201
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
202
202
|
pathFilename = makeDaoOfMapFoldingParallelNumba(astModule, 'countParallelNumba', None, logicalPathInfixDEFAULT, identifierCallableSourceDispatcherDEFAULT)
|
|
@@ -205,7 +205,7 @@ def makeMapFoldingModules() -> None:
|
|
|
205
205
|
makeInitializeState(astModule, 'initializeState', 'transitionOnGroupsOfFolds', logicalPathInfixDEFAULT)
|
|
206
206
|
|
|
207
207
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
208
|
-
pathFilename = makeTheorem2(astModule, 'theorem2', None, logicalPathInfixDEFAULT,
|
|
208
|
+
pathFilename = makeTheorem2(astModule, 'theorem2', None, logicalPathInfixDEFAULT, identifierCallableSourceDispatcherDEFAULT)
|
|
209
209
|
|
|
210
210
|
astModule = parsePathFilename2astModule(pathFilename)
|
|
211
211
|
pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', None, logicalPathInfixDEFAULT, None)
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""makeMeandersModules."""
|
|
2
|
+
from astToolkit import (
|
|
3
|
+
astModuleToIngredientsFunction, Be, Grab, identifierDotAttribute, Make, NodeChanger, NodeTourist, Then)
|
|
4
|
+
from hunterMakesPy import raiseIfNone
|
|
5
|
+
from mapFolding import packageSettings
|
|
6
|
+
from mapFolding.someAssemblyRequired import (
|
|
7
|
+
identifierCallableSourceDEFAULT, identifierCallableSourceDispatcherDEFAULT, IfThis, logicalPathInfixDEFAULT)
|
|
8
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import (
|
|
9
|
+
findDataclass, getModule, getPathFilename, write_astModule)
|
|
10
|
+
from pathlib import PurePath
|
|
11
|
+
import ast
|
|
12
|
+
|
|
13
|
+
identifierDataclassNumPyHARDCODED = 'MatrixMeandersNumPyState'
|
|
14
|
+
|
|
15
|
+
logicalPathInfixMeanders: str = logicalPathInfixDEFAULT + '.meanders'
|
|
16
|
+
|
|
17
|
+
def makeCountBigInt(astModule: ast.Module, identifierModule: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
18
|
+
"""Make `countBigInt` module for meanders using `MatrixMeandersNumPyState` dataclass."""
|
|
19
|
+
identifierDataclassNumPy: str = identifierDataclassNumPyHARDCODED
|
|
20
|
+
_logicalPathDataclass, identifierDataclassOld, identifierDataclassInstance = findDataclass(astModuleToIngredientsFunction(astModule, raiseIfNone(sourceCallableDispatcher)))
|
|
21
|
+
|
|
22
|
+
NodeChanger(findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(identifierCallableSourceDEFAULT))
|
|
23
|
+
, doThat=Grab.nameAttribute(Then.replaceWith(raiseIfNone(callableIdentifier)))
|
|
24
|
+
).visit(astModule)
|
|
25
|
+
|
|
26
|
+
# Remove `doTheNeedful`
|
|
27
|
+
NodeChanger(Be.FunctionDef.nameIs(IfThis.isIdentifier(sourceCallableDispatcher)), Then.removeIt).visit(astModule)
|
|
28
|
+
|
|
29
|
+
# Change to `MatrixMeandersNumPyState`
|
|
30
|
+
NodeChanger(Be.Name.idIs(IfThis.isIdentifier(identifierDataclassOld))
|
|
31
|
+
, Grab.idAttribute(Then.replaceWith(identifierDataclassNumPy))
|
|
32
|
+
).visit(astModule)
|
|
33
|
+
|
|
34
|
+
NodeChanger(Be.alias.nameIs(IfThis.isIdentifier(identifierDataclassOld))
|
|
35
|
+
, Grab.nameAttribute(Then.replaceWith(identifierDataclassNumPy))
|
|
36
|
+
).visit(astModule)
|
|
37
|
+
|
|
38
|
+
# while (state.boundary > 0 and areIntegersWide(state)): # noqa: ERA001
|
|
39
|
+
Call_areIntegersWide: ast.Call = Make.Call(Make.Name('areIntegersWide'), listParameters=[Make.Name('state')])
|
|
40
|
+
astCompare: ast.Compare = raiseIfNone(NodeTourist(
|
|
41
|
+
findThis=IfThis.isAttributeNamespaceIdentifierGreaterThan0(identifierDataclassInstance, 'boundary')
|
|
42
|
+
, doThat=Then.extractIt
|
|
43
|
+
).captureLastMatch(astModule))
|
|
44
|
+
newTest: ast.expr = Make.And.join([astCompare, Call_areIntegersWide])
|
|
45
|
+
|
|
46
|
+
NodeChanger(IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(identifierDataclassInstance, 'boundary')
|
|
47
|
+
, Grab.testAttribute(Then.replaceWith(newTest))
|
|
48
|
+
).visit(astModule)
|
|
49
|
+
|
|
50
|
+
# from mapFolding.algorithms.matrixMeandersBeDry import areIntegersWide # noqa: ERA001
|
|
51
|
+
astModule.body.insert(0, Make.ImportFrom('mapFolding.algorithms.matrixMeandersBeDry', list_alias=[Make.alias('areIntegersWide')]))
|
|
52
|
+
|
|
53
|
+
pathFilename: PurePath = getPathFilename(logicalPathInfix=logicalPathInfix, identifierModule=identifierModule)
|
|
54
|
+
|
|
55
|
+
write_astModule(astModule, pathFilename, packageSettings.identifierPackage)
|
|
56
|
+
|
|
57
|
+
return pathFilename
|
|
58
|
+
|
|
59
|
+
if __name__ == '__main__':
|
|
60
|
+
astModule: ast.Module = getModule(logicalPathInfix='algorithms', identifierModule='matrixMeanders')
|
|
61
|
+
pathFilename: PurePath = makeCountBigInt(astModule, 'bigInt', 'countBigInt', logicalPathInfixMeanders, identifierCallableSourceDispatcherDEFAULT)
|
|
62
|
+
|
|
63
|
+
|
|
@@ -42,16 +42,21 @@ from pathlib import PurePath
|
|
|
42
42
|
from typing import Any
|
|
43
43
|
import ast
|
|
44
44
|
import io
|
|
45
|
+
import isort
|
|
45
46
|
|
|
46
|
-
def findDataclass(ingredientsFunction: IngredientsFunction) -> tuple[
|
|
47
|
-
"""
|
|
47
|
+
def findDataclass(ingredientsFunction: IngredientsFunction) -> tuple[identifierDotAttribute, str, str]:
|
|
48
|
+
"""Dynamically extract information about a `dataclass`: the instance identifier, the identifier, and the logical path module.
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
Like many things in the "IngredientsFunction/IngredientsModule" ecosystem, this has specific requirements.
|
|
51
|
+
`ingredientsFunction` must have the dataclass as its first parameter. The `LedgerOfImports` in `ingredientsFunction` must have
|
|
52
|
+
the import information for the dataclass. If you are not using `IngredientsFunction`, you can still use this function to get
|
|
53
|
+
the information you want.
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
```python
|
|
56
|
+
from astToolkit import astModuleToIngredientsFunction
|
|
57
|
+
|
|
58
|
+
tupleInformation = findDataclass(astModuleToIngredientsFunction(astAST, identifier))
|
|
59
|
+
```
|
|
55
60
|
|
|
56
61
|
Parameters
|
|
57
62
|
----------
|
|
@@ -60,58 +65,52 @@ def findDataclass(ingredientsFunction: IngredientsFunction) -> tuple[str, str, s
|
|
|
60
65
|
|
|
61
66
|
Returns
|
|
62
67
|
-------
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Raises
|
|
71
|
-
------
|
|
72
|
-
ValueError
|
|
73
|
-
If dataclass information cannot be extracted from the function.
|
|
74
|
-
|
|
68
|
+
logicalPathDataclass : identifierDotAttribute
|
|
69
|
+
Logical path from which the `dataclass` is imported, which might not be the real source of the `dataclass`.
|
|
70
|
+
identifierDataclass : str
|
|
71
|
+
Identifier of the `dataclass`.
|
|
72
|
+
identifierDataclassInstance : str
|
|
73
|
+
Identifier of the `dataclass` instance.
|
|
75
74
|
"""
|
|
76
75
|
dataclassName: ast.expr = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
identifierDataclass: str = raiseIfNone(NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName))
|
|
77
|
+
logicalPathDataclass = None
|
|
79
78
|
for moduleWithLogicalPath, listNameTuples in ingredientsFunction.imports._dictionaryImportFrom.items(): # noqa: SLF001
|
|
80
79
|
for nameTuple in listNameTuples:
|
|
81
|
-
if nameTuple[0] ==
|
|
82
|
-
|
|
80
|
+
if nameTuple[0] == identifierDataclass:
|
|
81
|
+
logicalPathDataclass = moduleWithLogicalPath
|
|
83
82
|
break
|
|
84
|
-
if
|
|
83
|
+
if logicalPathDataclass:
|
|
85
84
|
break
|
|
86
|
-
|
|
87
|
-
return raiseIfNone(
|
|
85
|
+
identifierDataclassInstance: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
86
|
+
return raiseIfNone(logicalPathDataclass), identifierDataclass, identifierDataclassInstance
|
|
88
87
|
|
|
89
|
-
def getLogicalPath(identifierPackage: str | None = None, logicalPathInfix:
|
|
88
|
+
def getLogicalPath(identifierPackage: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, *identifierModule: str | None) -> identifierDotAttribute:
|
|
90
89
|
"""Get logical path from components."""
|
|
91
90
|
listLogicalPathParts: list[str] = []
|
|
92
91
|
if identifierPackage:
|
|
93
92
|
listLogicalPathParts.append(identifierPackage)
|
|
94
93
|
if logicalPathInfix:
|
|
95
94
|
listLogicalPathParts.append(logicalPathInfix)
|
|
96
|
-
if
|
|
97
|
-
listLogicalPathParts.extend([module for module in
|
|
95
|
+
if identifierModule:
|
|
96
|
+
listLogicalPathParts.extend([module for module in identifierModule if module is not None])
|
|
98
97
|
return '.'.join(listLogicalPathParts)
|
|
99
98
|
|
|
100
|
-
def getModule(identifierPackage: str | None = packageSettings.identifierPackage, logicalPathInfix:
|
|
99
|
+
def getModule(identifierPackage: str | None = packageSettings.identifierPackage, logicalPathInfix: identifierDotAttribute | None = logicalPathInfixDEFAULT, identifierModule: str | None = identifierModuleSourceAlgorithmDEFAULT) -> ast.Module:
|
|
101
100
|
"""Get Module."""
|
|
102
|
-
logicalPathSourceModule: identifierDotAttribute = getLogicalPath(identifierPackage, logicalPathInfix,
|
|
101
|
+
logicalPathSourceModule: identifierDotAttribute = getLogicalPath(identifierPackage, logicalPathInfix, identifierModule)
|
|
103
102
|
astModule: ast.Module = parseLogicalPath2astModule(logicalPathSourceModule)
|
|
104
103
|
return astModule
|
|
105
104
|
|
|
106
|
-
def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.pathPackage, logicalPathInfix:
|
|
105
|
+
def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.pathPackage, logicalPathInfix: identifierDotAttribute | None = None, identifierModule: str = '', fileExtension: str = packageSettings.fileExtension) -> PurePath:
|
|
107
106
|
"""Construct filesystem path from logical path.
|
|
108
107
|
|
|
109
108
|
Parameters
|
|
110
109
|
----------
|
|
111
110
|
pathRoot : PathLike[str] | PurePath | None = packageSettings.pathPackage
|
|
112
111
|
Base directory for the package structure.
|
|
113
|
-
logicalPathInfix :
|
|
114
|
-
|
|
112
|
+
logicalPathInfix : identifierDotAttribute | None = None
|
|
113
|
+
Logical path in dot notation.
|
|
115
114
|
moduleIdentifier : str = ''
|
|
116
115
|
Name of the specific module file.
|
|
117
116
|
fileExtension : str = packageSettings.fileExtension
|
|
@@ -123,7 +122,7 @@ def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.
|
|
|
123
122
|
Complete filesystem path for the generated module file.
|
|
124
123
|
|
|
125
124
|
"""
|
|
126
|
-
pathFilename = PurePath(
|
|
125
|
+
pathFilename = PurePath(identifierModule + fileExtension)
|
|
127
126
|
if logicalPathInfix:
|
|
128
127
|
pathFilename = PurePath(*(str(logicalPathInfix).split('.')), pathFilename)
|
|
129
128
|
if pathRoot:
|
|
@@ -131,7 +130,7 @@ def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.
|
|
|
131
130
|
return pathFilename
|
|
132
131
|
|
|
133
132
|
def write_astModule(astModule: ast.Module, pathFilename: PathLike[Any] | PurePath | io.TextIOBase, packageName: str | None = None) -> None:
|
|
134
|
-
"""Prototype.
|
|
133
|
+
"""Prototype that will likely be moved to astToolkit.
|
|
135
134
|
|
|
136
135
|
Parameters
|
|
137
136
|
----------
|
|
@@ -148,5 +147,6 @@ def write_astModule(astModule: ast.Module, pathFilename: PathLike[Any] | PurePat
|
|
|
148
147
|
if packageName:
|
|
149
148
|
autoflake_additional_imports.append(packageName)
|
|
150
149
|
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)
|
|
151
|
-
|
|
150
|
+
pythonSource = isort.code(pythonSource)
|
|
151
|
+
writeStringToHere(pythonSource + '\n', pathFilename)
|
|
152
152
|
|
|
@@ -34,7 +34,7 @@ from mapFolding.someAssemblyRequired import DeReConstructField2ast, IfThis, Shat
|
|
|
34
34
|
import ast
|
|
35
35
|
import dataclasses
|
|
36
36
|
|
|
37
|
-
def shatter_dataclassesDOTdataclass(
|
|
37
|
+
def shatter_dataclassesDOTdataclass(logicalPathDataclass: identifierDotAttribute, identifierDataclass: str, identifierDataclassInstance: str) -> ShatteredDataclass:
|
|
38
38
|
"""Decompose a dataclass definition into AST components for manipulation and code generation.
|
|
39
39
|
|
|
40
40
|
(AI generated docstring)
|
|
@@ -77,19 +77,19 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: identifierDotAttribute, d
|
|
|
77
77
|
Official_fieldOrder: list[str] = []
|
|
78
78
|
dictionaryDeReConstruction: dict[str, DeReConstructField2ast] = {}
|
|
79
79
|
|
|
80
|
-
dataclassClassDef: ast.ClassDef | None = extractClassDef(parseLogicalPath2astModule(
|
|
80
|
+
dataclassClassDef: ast.ClassDef | None = extractClassDef(parseLogicalPath2astModule(logicalPathDataclass), identifierDataclass)
|
|
81
81
|
if not dataclassClassDef:
|
|
82
|
-
message = f"I could not find `{
|
|
82
|
+
message = f"I could not find `{identifierDataclass = }` in `{logicalPathDataclass = }`."
|
|
83
83
|
raise ValueError(message)
|
|
84
84
|
|
|
85
85
|
countingVariable = None
|
|
86
|
-
for aField in dataclasses.fields(importLogicalPath2Identifier(
|
|
86
|
+
for aField in dataclasses.fields(importLogicalPath2Identifier(logicalPathDataclass, identifierDataclass)): # pyright: ignore [reportArgumentType]
|
|
87
87
|
Official_fieldOrder.append(aField.name)
|
|
88
|
-
dictionaryDeReConstruction[aField.name] = DeReConstructField2ast(
|
|
88
|
+
dictionaryDeReConstruction[aField.name] = DeReConstructField2ast(logicalPathDataclass, dataclassClassDef, identifierDataclassInstance, aField)
|
|
89
89
|
if aField.metadata.get('theCountingIdentifier', False):
|
|
90
90
|
countingVariable = dictionaryDeReConstruction[aField.name].name
|
|
91
91
|
if countingVariable is None:
|
|
92
|
-
message = f"I could not find the counting variable in `{
|
|
92
|
+
message = f"I could not find the counting variable in `{identifierDataclass = }` in `{logicalPathDataclass = }`."
|
|
93
93
|
raise ValueError(message)
|
|
94
94
|
|
|
95
95
|
shatteredDataclass = ShatteredDataclass(
|
|
@@ -105,11 +105,11 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: identifierDotAttribute, d
|
|
|
105
105
|
map_stateDOTfield2Name={dictionaryDeReConstruction[field].ast_nameDOTname: dictionaryDeReConstruction[field].astName for field in Official_fieldOrder},
|
|
106
106
|
)
|
|
107
107
|
shatteredDataclass.fragments4AssignmentOrParameters = Make.Tuple(shatteredDataclass.listName4Parameters, ast.Store())
|
|
108
|
-
shatteredDataclass.repack = Make.Assign([Make.Name(
|
|
108
|
+
shatteredDataclass.repack = Make.Assign([Make.Name(identifierDataclassInstance)], value=Make.Call(Make.Name(identifierDataclass), list_keyword=shatteredDataclass.list_keyword_field__field4init))
|
|
109
109
|
shatteredDataclass.signatureReturnAnnotation = Make.Subscript(Make.Name('tuple'), Make.Tuple(shatteredDataclass.listAnnotations))
|
|
110
110
|
|
|
111
111
|
shatteredDataclass.imports.update(*(dictionaryDeReConstruction[field].ledger for field in Official_fieldOrder))
|
|
112
|
-
shatteredDataclass.imports.addImportFrom_asStr(
|
|
112
|
+
shatteredDataclass.imports.addImportFrom_asStr(logicalPathDataclass, identifierDataclass)
|
|
113
113
|
|
|
114
114
|
return shatteredDataclass
|
|
115
115
|
|