mapFolding 0.9.4__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/__init__.py +41 -7
- mapFolding/basecamp.py +100 -9
- mapFolding/beDRY.py +7 -15
- mapFolding/dataBaskets.py +12 -0
- mapFolding/datatypes.py +4 -4
- mapFolding/oeis.py +2 -7
- mapFolding/someAssemblyRequired/RecipeJob.py +97 -3
- mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py +143 -42
- mapFolding/someAssemblyRequired/__init__.py +38 -49
- mapFolding/someAssemblyRequired/_astTypes.py +117 -0
- mapFolding/someAssemblyRequired/_theTypes.py +12 -41
- 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 +124 -29
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +274 -0
- mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +12 -11
- mapFolding/someAssemblyRequired/toolboxNumba.py +4 -28
- mapFolding/someAssemblyRequired/transformationTools.py +46 -155
- mapFolding/syntheticModules/daoOfMapFolding.py +74 -0
- mapFolding/syntheticModules/dataPacking.py +1 -1
- mapFolding/syntheticModules/theorem2Numba.py +2 -8
- mapFolding/syntheticModules/theorem2Trimmed.py +43 -0
- mapFolding/toolFactory/astFactory.py +493 -0
- mapFolding/toolFactory/astFactory_annex.py +63 -0
- mapFolding/toolFactory/astFactory_docstrings.py +63 -0
- {mapfolding-0.9.4.dist-info → mapfolding-0.10.0.dist-info}/METADATA +2 -1
- mapfolding-0.10.0.dist-info/RECORD +66 -0
- {mapfolding-0.9.4.dist-info → mapfolding-0.10.0.dist-info}/WHEEL +1 -1
- tests/test_computations.py +1 -1
- mapFolding/Z0Z_flowControl.py +0 -117
- mapFolding/someAssemblyRequired/_tool_Make.py +0 -134
- mapFolding/someAssemblyRequired/_tool_Then.py +0 -157
- mapFolding/someAssemblyRequired/_toolboxAntecedents.py +0 -387
- mapfolding-0.9.4.dist-info/RECORD +0 -57
- {mapfolding-0.9.4.dist-info → mapfolding-0.10.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.9.4.dist-info → mapfolding-0.10.0.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.9.4.dist-info → mapfolding-0.10.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
mapFolding/__init__.py,sha256=vIUZ4w4Hr12xPhSXIrnoG7-jg59VeEl5KbaOfmMRjTA,5403
|
|
2
|
+
mapFolding/basecamp.py,sha256=hs7hlTmbX7KTjI_eIRVU4xn7HR4l448SIpHk1cKDwRk,8071
|
|
3
|
+
mapFolding/beDRY.py,sha256=JQ7T9v4aKzweGjvpzyghyq4N9l3Wf9HZco_K_DWoiW0,15368
|
|
4
|
+
mapFolding/daoOfMapFolding.py,sha256=ncTIiBfTsM8SNVx9qefZ0bBcBtviWLSk4iPv3Z9nGiE,5442
|
|
5
|
+
mapFolding/dataBaskets.py,sha256=80ALoRqaOfNEgz8QTdDJPsyVBnm8MkWLtRHD3DPPoRw,5073
|
|
6
|
+
mapFolding/datatypes.py,sha256=-TdXqAlEWEwUP_VUb9-X5pvaBBedbZOQbBuu5j1ZoTA,962
|
|
7
|
+
mapFolding/oeis.py,sha256=zHk5Mygd7qpDj1NYXsvY_l3e8jg3tHDQ1Cpt6NrWiuc,17019
|
|
8
|
+
mapFolding/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
mapFolding/theDao.py,sha256=kc3rzTX3yts0PxgPCXFbgWvaqsBexsiU5ib2pzpvID0,10019
|
|
10
|
+
mapFolding/theSSOT.py,sha256=rbv8esQeBG6uLWpFZu_ncMA4zIuQG3lj4FZNzC_6JGI,16138
|
|
11
|
+
mapFolding/toolboxFilesystem.py,sha256=kVZoU-NBvfYSvI4R8mEpMXRUZee-1JV0fjtMFWPhk8Y,9818
|
|
12
|
+
mapFolding/reference/__init__.py,sha256=GKcSgYE49NcTISx-JZbELXyq-eRkMeTL5g4DXInWFw0,2206
|
|
13
|
+
mapFolding/reference/flattened.py,sha256=QK1xG9SllqCoi68e86Hyl9d9ATUAAFNpTQI-3zmcp5I,16072
|
|
14
|
+
mapFolding/reference/hunterNumba.py,sha256=iLfyqwGdAh6c5GbapnKsWhAsNsR3O-fyGGHAdohluLw,7258
|
|
15
|
+
mapFolding/reference/irvineJavaPort.py,sha256=UEfIX4QbPLl5jnyfYIyX5YRR3_rYvPUikK8jLehsFko,4076
|
|
16
|
+
mapFolding/reference/jaxCount.py,sha256=TuDNKOnyhQfuixKmIxO9Algv7dvy7KMGhgsV3h96FGE,14853
|
|
17
|
+
mapFolding/reference/lunnonNumpy.py,sha256=mMgrgbrBpe4nmo72ThEI-MGH0OwEHmfMPczSXHp2qKo,4357
|
|
18
|
+
mapFolding/reference/lunnonWhile.py,sha256=ZL8GAQtPs5nJZSgoDl5USrLSS_zs03y98y1Z9E4jOmQ,3799
|
|
19
|
+
mapFolding/reference/rotatedEntryPoint.py,sha256=5ughpKUT2JQhoAKgoDUdYNjgWQYPGV8v-7dWEAdDmfE,10274
|
|
20
|
+
mapFolding/reference/total_countPlus1vsPlusN.py,sha256=yJZAVLVdoXqHag2_N6_6CT-Q6HXBgRro-eny93-Rlpw,9307
|
|
21
|
+
mapFolding/reference/jobsCompleted/__init__.py,sha256=TU93ZGUW1xEkT6d9mQFn_rp5DvRy0ZslEB2Q6MF5ZDc,2596
|
|
22
|
+
mapFolding/reference/jobsCompleted/[2x19]/p2x19.py,sha256=_tvYtfzMWVo2VtUbIAieoscb4N8FFflgTdW4-ljBUuA,19626
|
|
23
|
+
mapFolding/reference/jobsCompleted/p2x19/p2x19.py,sha256=eZEw4Me4ocTt6VXoK2-Sbd5SowZtxRIbN9dZmc7OCVg,6395
|
|
24
|
+
mapFolding/someAssemblyRequired/RecipeJob.py,sha256=6RD4F4Yde7K-Rz0F4IokQ62BVzRSx4vCCYY4H-Dfug4,10190
|
|
25
|
+
mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py,sha256=ni7twaO2Pkrhg-BXuxysF-reNLb79_jcpQp6AcHJ98E,15770
|
|
26
|
+
mapFolding/someAssemblyRequired/__init__.py,sha256=4PIwIa8iAX3h3O2_bdWjsfiFtHwnXCY85x6EdJrmh0g,3882
|
|
27
|
+
mapFolding/someAssemblyRequired/_astTypes.py,sha256=EwLxEtbZwUtaRlt4tWwiTvaoeGR4_V3hdX8Xi3Z8w1E,7809
|
|
28
|
+
mapFolding/someAssemblyRequired/_theTypes.py,sha256=8Ako7EVwciwdNoXLTpAQaOgMTgQv2HysXzPPYMwBv68,3107
|
|
29
|
+
mapFolding/someAssemblyRequired/_toolBe.py,sha256=bT64xwj_lGJZZB6FyY46alFZENZ2LlJdb2kO47L643Q,16400
|
|
30
|
+
mapFolding/someAssemblyRequired/_toolDOT.py,sha256=JpEpW0mZRFFYzlIhQQtD15rKSzEESXfzX6i0aH95YK0,12727
|
|
31
|
+
mapFolding/someAssemblyRequired/_toolGrab.py,sha256=oMrTMVky5BIEo9GEXA3AVlElGtPd10gIR6jIEWWsFV8,25327
|
|
32
|
+
mapFolding/someAssemblyRequired/_toolIfThis.py,sha256=DsvXHvi27YGC8TZMm6WlV6YsK0ruVPVPQRip0wrpvlk,10223
|
|
33
|
+
mapFolding/someAssemblyRequired/_toolMake.py,sha256=X54TBZysYEcVOmtBSTZoW80kmJJS-yYFwRvN_19uU_8,18282
|
|
34
|
+
mapFolding/someAssemblyRequired/_toolThen.py,sha256=RFp1h8FQroBIR3F-TtXJo3j7wS_XKFAvLWly93PkZiE,2584
|
|
35
|
+
mapFolding/someAssemblyRequired/_toolboxAST.py,sha256=-hlKH0gYCY4Srx1azL8SK2RLbYYRw0a0i3qaYcnx8L0,2376
|
|
36
|
+
mapFolding/someAssemblyRequired/_toolboxContainers.py,sha256=5Y9-X-SyCkrxpn164PICvcimPE89Tgcnksm7N5wqOnU,30117
|
|
37
|
+
mapFolding/someAssemblyRequired/_toolboxPython.py,sha256=1K7IzqzmHNTaPA6qTo73GZYHCIQRYI2Rn8aYJ3VelqY,7873
|
|
38
|
+
mapFolding/someAssemblyRequired/getLLVMforNoReason.py,sha256=9RPU6vK_eUg64GtVFI_nZnvUryXw8gfHJs9NyDYHIvg,2745
|
|
39
|
+
mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=5j3fLdiVHv7OlH-RR-fjeevRXnLrmUJpeXleHytDoF4,13830
|
|
40
|
+
mapFolding/someAssemblyRequired/synthesizeNumbaJob.py,sha256=9D0VLOAttfyTcf8GFko_QhRS5steSQo6FvWHD5xQLGc,15597
|
|
41
|
+
mapFolding/someAssemblyRequired/toolboxNumba.py,sha256=QIpYCf1IFfgrQ5GVA0ON0ymn324iBfkyHVSfBW5CqOY,8961
|
|
42
|
+
mapFolding/someAssemblyRequired/transformationTools.py,sha256=Kd_eVIgBHMdsZwOIe9hxST0x1JfqgCR26OyNBYjDSY0,29307
|
|
43
|
+
mapFolding/syntheticModules/__init__.py,sha256=evVFqhCGa-WZKDiLcnQWjs-Bj34eRnfSLqz_d7dFYZY,83
|
|
44
|
+
mapFolding/syntheticModules/daoOfMapFolding.py,sha256=cfWPABtXyCxJ0BwPI7rhfLh_2UYV_XKAL8lJ4GLNXaQ,5896
|
|
45
|
+
mapFolding/syntheticModules/dataPacking.py,sha256=J4WLJzQTOAm2d8itzWWSixTUcCGQl4KuEfqrzkb2tJQ,2294
|
|
46
|
+
mapFolding/syntheticModules/initializeCount.py,sha256=nWSlJMMfIM3DvZxMn6ISQusUJqRYAjKQyLF5hwLEdBQ,3119
|
|
47
|
+
mapFolding/syntheticModules/numbaCount.py,sha256=zM-bp07c9tEDdvidwzZ_bJTd0JC0VUkYEEiHG--P1tQ,15525
|
|
48
|
+
mapFolding/syntheticModules/theorem2.py,sha256=9jrbZNNX4BWYZW1S0JjvRY2k7RU7I1RNUMV7JdCt1ZY,3017
|
|
49
|
+
mapFolding/syntheticModules/theorem2Numba.py,sha256=-cKjNyxgUMFhEyFVs0VJ7hw4LfrV0WSNK5tPYbQ1oNU,3369
|
|
50
|
+
mapFolding/syntheticModules/theorem2Trimmed.py,sha256=DHW3NxBdtABQYBKm2WRvfQ5kzc2_UwGI2h4ePuYEJoM,2685
|
|
51
|
+
mapFolding/toolFactory/astFactory.py,sha256=3FJUx_O7L7rM9gyeUvYGB1rRm0gmqiTos4_CjboQ4KI,28777
|
|
52
|
+
mapFolding/toolFactory/astFactory_annex.py,sha256=pTULZ8bJ4ioojK2VQ2636rvlHflT0GbSeHYjm2kooqE,5948
|
|
53
|
+
mapFolding/toolFactory/astFactory_docstrings.py,sha256=aX2JR5cXMe2znIrvWxLeK74jQebMWwGX4U0sk-iexWQ,3406
|
|
54
|
+
mapfolding-0.10.0.dist-info/licenses/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
|
|
55
|
+
tests/__init__.py,sha256=5VhHf0JJ2_DSh58zJ0rR5UkpoCon-0IkdljspTCzZ04,1950
|
|
56
|
+
tests/conftest.py,sha256=x8zMZQyTss3sn0GwHm_TSRwD9_LVlR8l_qF8r43Vxl4,14178
|
|
57
|
+
tests/test_computations.py,sha256=5sg1PpSp6aeOrXZeO5NwWK5ipPAe49wVKC2J7yT5MFg,6524
|
|
58
|
+
tests/test_filesystem.py,sha256=T2DkjBoI3lW6tCxd5BilPmUFrVukNKLjOOZVZxLM560,3004
|
|
59
|
+
tests/test_oeis.py,sha256=uxvwmgbnylSDdsVJfuAT0LuYLbIVFwSgdLxHm-xUGBM,5043
|
|
60
|
+
tests/test_other.py,sha256=UMlK4JPInalpOZuPvTnUrgXWCJOxAw-OsPs6CxMR254,3753
|
|
61
|
+
tests/test_tasks.py,sha256=tOQc4uomKXGwWnENfbcThaVa1XofwXNCkGZbg4yS6VI,2833
|
|
62
|
+
mapfolding-0.10.0.dist-info/METADATA,sha256=jcIwCSmk1EYzJDUvvQ3BE5-VYswynF9onfnMS7Humlg,7534
|
|
63
|
+
mapfolding-0.10.0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
|
64
|
+
mapfolding-0.10.0.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
65
|
+
mapfolding-0.10.0.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
|
|
66
|
+
mapfolding-0.10.0.dist-info/RECORD,,
|
tests/test_computations.py
CHANGED
|
@@ -102,7 +102,7 @@ if __name__ == '__main__':
|
|
|
102
102
|
def test_algorithmSourceParallel(mapShapeTestParallelization: tuple[int, ...], useAlgorithmSourceDispatcher: None) -> None:
|
|
103
103
|
standardizedEqualToCallableReturn(getFoldsTotalKnown(mapShapeTestParallelization), countFolds, mapShapeTestParallelization, None, 'maximum', None)
|
|
104
104
|
|
|
105
|
-
@pytest.mark.parametrize('flow', ['daoOfMapFolding', 'theorem2', 'theorem2numba'])
|
|
105
|
+
@pytest.mark.parametrize('flow', ['daoOfMapFolding', 'theorem2', 'theorem2Trimmed', 'theorem2numba'])
|
|
106
106
|
def test_flowControl(mapShapeTestCountFolds: tuple[int, ...], flow: Literal['daoOfMapFolding'] | Literal['theorem2'] | Literal['theorem2numba']) -> None:
|
|
107
107
|
standardizedEqualToCallableReturn(getFoldsTotalKnown(mapShapeTestCountFolds), countFolds, None, None, None, None, mapShapeTestCountFolds, None, None, flow)
|
|
108
108
|
|
mapFolding/Z0Z_flowControl.py
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
from collections.abc import Sequence
|
|
2
|
-
from mapFolding import (
|
|
3
|
-
ComputationState,
|
|
4
|
-
getPathFilenameFoldsTotal,
|
|
5
|
-
outfitCountFolds,
|
|
6
|
-
saveFoldsTotal,
|
|
7
|
-
saveFoldsTotalFAILearly,
|
|
8
|
-
setProcessorLimit,
|
|
9
|
-
The,
|
|
10
|
-
validateListDimensions,
|
|
11
|
-
)
|
|
12
|
-
from os import PathLike
|
|
13
|
-
from pathlib import PurePath
|
|
14
|
-
|
|
15
|
-
def countFolds(listDimensions: Sequence[int] | None = None
|
|
16
|
-
, pathLikeWriteFoldsTotal: PathLike[str] | PurePath | None = None
|
|
17
|
-
, computationDivisions: int | str | None = None
|
|
18
|
-
, CPUlimit: int | float | bool | None = None
|
|
19
|
-
# , * I need to improve `standardizedEqualToCallableReturn` so it will work with keyword arguments
|
|
20
|
-
, mapShape: tuple[int, ...] | None = None
|
|
21
|
-
, oeisID: str | None = None
|
|
22
|
-
, oeis_n: int | None = None
|
|
23
|
-
, flow: str | None = None
|
|
24
|
-
) -> int:
|
|
25
|
-
|
|
26
|
-
# mapShape =====================================================================
|
|
27
|
-
|
|
28
|
-
if mapShape:
|
|
29
|
-
pass
|
|
30
|
-
else:
|
|
31
|
-
if oeisID and oeis_n:
|
|
32
|
-
from mapFolding.oeis import settingsOEIS
|
|
33
|
-
try:
|
|
34
|
-
mapShape = settingsOEIS[oeisID]['getMapShape'](oeis_n)
|
|
35
|
-
except KeyError:
|
|
36
|
-
pass
|
|
37
|
-
if not mapShape and listDimensions:
|
|
38
|
-
mapShape = validateListDimensions(listDimensions)
|
|
39
|
-
|
|
40
|
-
if mapShape is None:
|
|
41
|
-
raise ValueError(f"""I received these values:
|
|
42
|
-
`{listDimensions = }`,
|
|
43
|
-
`{mapShape = }`,
|
|
44
|
-
`{oeisID = }` and `{oeis_n = }`,
|
|
45
|
-
but I was unable to select a map for which to count the folds.""")
|
|
46
|
-
|
|
47
|
-
# task division instructions ===============================================
|
|
48
|
-
|
|
49
|
-
if computationDivisions:
|
|
50
|
-
# NOTE `The.concurrencyPackage`
|
|
51
|
-
concurrencyLimit: int = setProcessorLimit(CPUlimit, The.concurrencyPackage)
|
|
52
|
-
from mapFolding.beDRY import getLeavesTotal, getTaskDivisions
|
|
53
|
-
leavesTotal: int = getLeavesTotal(mapShape)
|
|
54
|
-
taskDivisions = getTaskDivisions(computationDivisions, concurrencyLimit, leavesTotal)
|
|
55
|
-
del leavesTotal
|
|
56
|
-
else:
|
|
57
|
-
concurrencyLimit = 1
|
|
58
|
-
taskDivisions = 0
|
|
59
|
-
|
|
60
|
-
# memorialization instructions ===========================================
|
|
61
|
-
|
|
62
|
-
if pathLikeWriteFoldsTotal is not None:
|
|
63
|
-
pathFilenameFoldsTotal = getPathFilenameFoldsTotal(mapShape, pathLikeWriteFoldsTotal)
|
|
64
|
-
saveFoldsTotalFAILearly(pathFilenameFoldsTotal)
|
|
65
|
-
else:
|
|
66
|
-
pathFilenameFoldsTotal = None
|
|
67
|
-
|
|
68
|
-
# Flow control until I can figure out a good way ===============================
|
|
69
|
-
|
|
70
|
-
if flow == 'daoOfMapFolding':
|
|
71
|
-
from mapFolding.dataBaskets import MapFoldingState
|
|
72
|
-
mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
|
|
73
|
-
|
|
74
|
-
from mapFolding.daoOfMapFolding import doTheNeedful
|
|
75
|
-
mapFoldingState = doTheNeedful(mapFoldingState)
|
|
76
|
-
foldsTotal = mapFoldingState.foldsTotal
|
|
77
|
-
|
|
78
|
-
elif flow == 'theorem2' and any((dimension > 2 for dimension in mapShape)):
|
|
79
|
-
from mapFolding.dataBaskets import MapFoldingState
|
|
80
|
-
mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
|
|
81
|
-
|
|
82
|
-
from mapFolding.syntheticModules.initializeCount import initializeGroupsOfFolds
|
|
83
|
-
mapFoldingState = initializeGroupsOfFolds(mapFoldingState)
|
|
84
|
-
|
|
85
|
-
from mapFolding.syntheticModules.theorem2 import count
|
|
86
|
-
mapFoldingState = count(mapFoldingState)
|
|
87
|
-
|
|
88
|
-
foldsTotal = mapFoldingState.foldsTotal
|
|
89
|
-
|
|
90
|
-
elif (flow == 'theorem2Numba' or taskDivisions == 0) and any((dimension > 2 for dimension in mapShape)):
|
|
91
|
-
from mapFolding.dataBaskets import MapFoldingState
|
|
92
|
-
mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
|
|
93
|
-
|
|
94
|
-
from mapFolding.syntheticModules.initializeCount import initializeGroupsOfFolds
|
|
95
|
-
mapFoldingState = initializeGroupsOfFolds(mapFoldingState)
|
|
96
|
-
|
|
97
|
-
from mapFolding.syntheticModules.dataPacking import doTheNeedful
|
|
98
|
-
mapFoldingState = doTheNeedful(mapFoldingState)
|
|
99
|
-
|
|
100
|
-
foldsTotal = mapFoldingState.foldsTotal
|
|
101
|
-
|
|
102
|
-
# NOTE treat this as a default?
|
|
103
|
-
# flow based on `The` and `ComputationState` ====================================
|
|
104
|
-
|
|
105
|
-
else:
|
|
106
|
-
computationStateInitialized: ComputationState = outfitCountFolds(mapShape, computationDivisions, concurrencyLimit)
|
|
107
|
-
computationStateComplete: ComputationState = The.dispatcher(computationStateInitialized)
|
|
108
|
-
|
|
109
|
-
computationStateComplete.getFoldsTotal()
|
|
110
|
-
foldsTotal = computationStateComplete.foldsTotal
|
|
111
|
-
|
|
112
|
-
# Follow memorialization instructions ===========================================
|
|
113
|
-
|
|
114
|
-
if pathFilenameFoldsTotal is not None:
|
|
115
|
-
saveFoldsTotal(pathFilenameFoldsTotal, foldsTotal)
|
|
116
|
-
|
|
117
|
-
return foldsTotal
|
|
@@ -1,134 +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
|
|
5
|
-
with sane defaults. It abstracts away the complexity of constructing AST nodes
|
|
6
|
-
directly, making programmatic code generation more intuitive and less error-prone.
|
|
7
|
-
|
|
8
|
-
The Make class serves as a factory for creating various types of AST nodes needed
|
|
9
|
-
in code generation, transformation, and analysis workflows. Each method follows
|
|
10
|
-
a consistent pattern that maps cleanly to Python's syntax while handling the
|
|
11
|
-
details of AST node construction.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
from collections.abc import Sequence
|
|
15
|
-
from mapFolding.someAssemblyRequired import (
|
|
16
|
-
ast_expr_Slice,
|
|
17
|
-
ast_Identifier,
|
|
18
|
-
intORlist_ast_type_paramORstr_orNone,
|
|
19
|
-
intORstr_orNone,
|
|
20
|
-
list_ast_type_paramORstr_orNone,
|
|
21
|
-
str_nameDOTname,
|
|
22
|
-
)
|
|
23
|
-
from typing import Any
|
|
24
|
-
import ast
|
|
25
|
-
|
|
26
|
-
class Make:
|
|
27
|
-
"""Almost all parameters described here are only accessible through a method's `**keywordArguments` parameter.
|
|
28
|
-
|
|
29
|
-
Parameters:
|
|
30
|
-
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()`.
|
|
31
|
-
col_offset (0): int Position information specifying the column where an AST node begins.
|
|
32
|
-
end_col_offset (None): int|None Position information specifying the column where an AST node ends.
|
|
33
|
-
end_lineno (None): int|None Position information specifying the line number where an AST node ends.
|
|
34
|
-
level (0): int Module import depth level that controls relative vs absolute imports. Default 0 indicates absolute import.
|
|
35
|
-
lineno: int Position information manually specifying the line number where an AST node begins.
|
|
36
|
-
kind (None): str|None Used for type annotations in limited cases.
|
|
37
|
-
type_comment (None): str|None "type_comment is an optional string with the type annotation as a comment." or `# type: ignore`.
|
|
38
|
-
type_params: list[ast.type_param] Type parameters for generic type definitions.
|
|
39
|
-
|
|
40
|
-
The `ast._Attributes`, lineno, col_offset, end_lineno, and end_col_offset, hold position information; however, they are, importantly, _not_ `ast._fields`.
|
|
41
|
-
"""
|
|
42
|
-
@staticmethod
|
|
43
|
-
def alias(name: ast_Identifier, asname: ast_Identifier | None = None) -> ast.alias:
|
|
44
|
-
return ast.alias(name, asname)
|
|
45
|
-
|
|
46
|
-
@staticmethod
|
|
47
|
-
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.
|
|
48
|
-
return ast.AnnAssign(target, annotation, value, simple=int(isinstance(target, ast.Name)), **keywordArguments)
|
|
49
|
-
|
|
50
|
-
@staticmethod
|
|
51
|
-
def arg(identifier: ast_Identifier, annotation: ast.expr | None = None, **keywordArguments: intORstr_orNone) -> ast.arg:
|
|
52
|
-
return ast.arg(identifier, annotation, **keywordArguments)
|
|
53
|
-
|
|
54
|
-
@staticmethod
|
|
55
|
-
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:
|
|
56
|
-
return ast.arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, defaults)
|
|
57
|
-
|
|
58
|
-
@staticmethod
|
|
59
|
-
def Assign(listTargets: list[ast.expr], value: ast.expr, **keywordArguments: intORstr_orNone) -> ast.Assign:
|
|
60
|
-
return ast.Assign(listTargets, value, **keywordArguments)
|
|
61
|
-
|
|
62
|
-
@staticmethod
|
|
63
|
-
def Attribute(value: ast.expr, *attribute: ast_Identifier, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Attribute:
|
|
64
|
-
""" If two `ast_Identifier` are joined by a dot `.`, they are _usually_ an `ast.Attribute`, but see `ast.ImportFrom`.
|
|
65
|
-
Parameters:
|
|
66
|
-
value: the part before the dot (e.g., `ast.Name`.)
|
|
67
|
-
attribute: an `ast_Identifier` after a dot `.`; you can pass multiple `attribute` and they will be chained together.
|
|
68
|
-
"""
|
|
69
|
-
def addDOTattribute(chain: ast.expr, identifier: ast_Identifier, context: ast.expr_context, **keywordArguments: int) -> ast.Attribute:
|
|
70
|
-
return ast.Attribute(value=chain, attr=identifier, ctx=context, **keywordArguments)
|
|
71
|
-
buffaloBuffalo = addDOTattribute(value, attribute[0], context, **keywordArguments)
|
|
72
|
-
for identifier in attribute[1:None]:
|
|
73
|
-
buffaloBuffalo = addDOTattribute(buffaloBuffalo, identifier, context, **keywordArguments)
|
|
74
|
-
return buffaloBuffalo
|
|
75
|
-
|
|
76
|
-
@staticmethod
|
|
77
|
-
def AugAssign(target: ast.Attribute | ast.Name | ast.Subscript, operator: ast.operator, value: ast.expr, **keywordArguments: int) -> ast.AugAssign:
|
|
78
|
-
return ast.AugAssign(target, operator, value, **keywordArguments)
|
|
79
|
-
|
|
80
|
-
@staticmethod
|
|
81
|
-
def Call(callee: ast.expr, listArguments: Sequence[ast.expr] | None = None, list_astKeywords: Sequence[ast.keyword] | None = None) -> ast.Call:
|
|
82
|
-
return ast.Call(func=callee, args=list(listArguments) if listArguments else [], keywords=list(list_astKeywords) if list_astKeywords else [])
|
|
83
|
-
|
|
84
|
-
@staticmethod
|
|
85
|
-
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:
|
|
86
|
-
return ast.ClassDef(name, listBases, list_keyword, body, decorator_list, **keywordArguments)
|
|
87
|
-
|
|
88
|
-
@staticmethod
|
|
89
|
-
def Constant(value: Any, **keywordArguments: intORstr_orNone) -> ast.Constant:
|
|
90
|
-
return ast.Constant(value, **keywordArguments)
|
|
91
|
-
|
|
92
|
-
@staticmethod
|
|
93
|
-
def Expr(value: ast.expr, **keywordArguments: int) -> ast.Expr:
|
|
94
|
-
return ast.Expr(value, **keywordArguments)
|
|
95
|
-
|
|
96
|
-
@staticmethod
|
|
97
|
-
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:
|
|
98
|
-
return ast.FunctionDef(name, argumentsSpecification, body, decorator_list, returns, **keywordArguments)
|
|
99
|
-
|
|
100
|
-
@staticmethod
|
|
101
|
-
def Import(moduleWithLogicalPath: str_nameDOTname, asname: ast_Identifier | None = None, **keywordArguments: int) -> ast.Import:
|
|
102
|
-
return ast.Import(names=[Make.alias(moduleWithLogicalPath, asname)], **keywordArguments)
|
|
103
|
-
|
|
104
|
-
@staticmethod
|
|
105
|
-
def ImportFrom(moduleWithLogicalPath: str_nameDOTname, list_astAlias: list[ast.alias], **keywordArguments: int) -> ast.ImportFrom:
|
|
106
|
-
return ast.ImportFrom(moduleWithLogicalPath, list_astAlias, **keywordArguments)
|
|
107
|
-
|
|
108
|
-
@staticmethod
|
|
109
|
-
def keyword(keywordArgument: ast_Identifier, value: ast.expr, **keywordArguments: int) -> ast.keyword:
|
|
110
|
-
return ast.keyword(arg=keywordArgument, value=value, **keywordArguments)
|
|
111
|
-
|
|
112
|
-
@staticmethod
|
|
113
|
-
def Module(body: list[ast.stmt] = [], type_ignores: list[ast.TypeIgnore] = []) -> ast.Module:
|
|
114
|
-
return ast.Module(body, type_ignores)
|
|
115
|
-
|
|
116
|
-
@staticmethod
|
|
117
|
-
def Name(identifier: ast_Identifier, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Name:
|
|
118
|
-
return ast.Name(identifier, context, **keywordArguments)
|
|
119
|
-
|
|
120
|
-
@staticmethod
|
|
121
|
-
def Return(value: ast.expr | None = None, **keywordArguments: int) -> ast.Return:
|
|
122
|
-
return ast.Return(value, **keywordArguments)
|
|
123
|
-
|
|
124
|
-
@staticmethod
|
|
125
|
-
def Subscript(value: ast.expr, slice: ast_expr_Slice, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Subscript:
|
|
126
|
-
return ast.Subscript(value, slice, context, **keywordArguments)
|
|
127
|
-
|
|
128
|
-
@staticmethod
|
|
129
|
-
def Tuple(elements: Sequence[ast.expr] = [], context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Tuple:
|
|
130
|
-
return ast.Tuple(list(elements), context, **keywordArguments)
|
|
131
|
-
|
|
132
|
-
@staticmethod
|
|
133
|
-
def While(test: ast.expr, doThis: list[ast.stmt], orElse: list[ast.stmt] = [], **keywordArguments: int) -> ast.While:
|
|
134
|
-
return ast.While(test, doThis, orElse, **keywordArguments)
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
AST Node Transformation Actions for Python Code Manipulation
|
|
3
|
-
|
|
4
|
-
This module provides the Then class with static methods for generating callable
|
|
5
|
-
action functions that specify what to do with AST nodes that match predicates.
|
|
6
|
-
These action functions are used primarily with NodeChanger and NodeTourist to
|
|
7
|
-
transform or extract information from AST nodes.
|
|
8
|
-
|
|
9
|
-
The module also contains the grab class that provides functions for modifying
|
|
10
|
-
specific attributes of AST nodes while preserving their structure, enabling
|
|
11
|
-
fine-grained control when transforming AST structures.
|
|
12
|
-
|
|
13
|
-
Together, these classes provide a complete system for manipulating AST nodes
|
|
14
|
-
once they have been identified using predicate functions from ifThis.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from collections.abc import Callable, Sequence
|
|
18
|
-
from mapFolding.someAssemblyRequired import ast_Identifier, astClassHasDOTvalue, ImaCallToName, NodeORattribute
|
|
19
|
-
from typing import Any, overload
|
|
20
|
-
import ast
|
|
21
|
-
|
|
22
|
-
class grab:
|
|
23
|
-
"""
|
|
24
|
-
Modify specific attributes of AST nodes while preserving the node structure.
|
|
25
|
-
|
|
26
|
-
The grab class provides static methods that create transformation functions to modify
|
|
27
|
-
specific attributes of AST nodes. Unlike DOT which provides read-only access,
|
|
28
|
-
grab allows for targeted modifications of node attributes without replacing the
|
|
29
|
-
entire node.
|
|
30
|
-
|
|
31
|
-
Each method returns a function that takes a node, applies a transformation to a
|
|
32
|
-
specific attribute of that node, and returns the modified node. This enables fine-grained
|
|
33
|
-
control when transforming AST structures.
|
|
34
|
-
"""
|
|
35
|
-
@staticmethod
|
|
36
|
-
def andDoAllOf(listOfActions: list[Callable[[NodeORattribute], NodeORattribute]]) -> Callable[[NodeORattribute], NodeORattribute]:
|
|
37
|
-
def workhorse(node: NodeORattribute) -> NodeORattribute:
|
|
38
|
-
for action in listOfActions:
|
|
39
|
-
node = action(node)
|
|
40
|
-
return node
|
|
41
|
-
return workhorse
|
|
42
|
-
|
|
43
|
-
@staticmethod
|
|
44
|
-
def argAttribute(action: Callable[[ast_Identifier | None], ast_Identifier]) -> Callable[[ast.arg | ast.keyword], ast.arg | ast.keyword]:
|
|
45
|
-
def workhorse(node: ast.arg | ast.keyword) -> ast.arg | ast.keyword:
|
|
46
|
-
node.arg = action(node.arg)
|
|
47
|
-
return node
|
|
48
|
-
return workhorse
|
|
49
|
-
|
|
50
|
-
@staticmethod
|
|
51
|
-
def attrAttribute(action: Callable[[ast_Identifier], ast_Identifier]) -> Callable[[ast.Attribute], ast.Attribute]:
|
|
52
|
-
def workhorse(node: ast.Attribute) -> ast.Attribute:
|
|
53
|
-
node.attr = action(node.attr)
|
|
54
|
-
return node
|
|
55
|
-
return workhorse
|
|
56
|
-
|
|
57
|
-
@staticmethod
|
|
58
|
-
def comparatorsAttribute(action: Callable[[list[ast.expr]], list[ast.expr]]) -> Callable[[ast.Compare], ast.Compare]:
|
|
59
|
-
def workhorse(node: ast.Compare) -> ast.Compare:
|
|
60
|
-
node.comparators = action(node.comparators)
|
|
61
|
-
return node
|
|
62
|
-
return workhorse
|
|
63
|
-
|
|
64
|
-
@staticmethod
|
|
65
|
-
def funcAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[ast.Call], ast.Call]:
|
|
66
|
-
def workhorse(node: ast.Call) -> ast.Call:
|
|
67
|
-
node.func = action(node.func)
|
|
68
|
-
return node
|
|
69
|
-
return workhorse
|
|
70
|
-
|
|
71
|
-
@staticmethod
|
|
72
|
-
def funcDOTidAttribute(action: Callable[[ast_Identifier], Any]) -> Callable[[ImaCallToName], ImaCallToName]:
|
|
73
|
-
def workhorse(node: ImaCallToName) -> ImaCallToName:
|
|
74
|
-
node.func = grab.idAttribute(action)(node.func)
|
|
75
|
-
return node
|
|
76
|
-
return workhorse
|
|
77
|
-
|
|
78
|
-
@staticmethod
|
|
79
|
-
def idAttribute(action: Callable[[ast_Identifier], ast_Identifier]) -> Callable[[ast.Name], ast.Name]:
|
|
80
|
-
def workhorse(node: ast.Name) -> ast.Name:
|
|
81
|
-
node.id = action(node.id)
|
|
82
|
-
return node
|
|
83
|
-
return workhorse
|
|
84
|
-
|
|
85
|
-
@staticmethod
|
|
86
|
-
def leftAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[ast.BinOp | ast.Compare], ast.BinOp | ast.Compare]:
|
|
87
|
-
def workhorse(node: ast.BinOp | ast.Compare) -> ast.BinOp | ast.Compare:
|
|
88
|
-
node.left = action(node.left)
|
|
89
|
-
return node
|
|
90
|
-
return workhorse
|
|
91
|
-
|
|
92
|
-
@staticmethod
|
|
93
|
-
def opsAttribute(action: Callable[[list[ast.cmpop]], list[ast.cmpop]]) -> Callable[[ast.Compare], ast.Compare]:
|
|
94
|
-
def workhorse(node: ast.Compare) -> ast.Compare:
|
|
95
|
-
node.ops = action(node.ops)
|
|
96
|
-
return node
|
|
97
|
-
return workhorse
|
|
98
|
-
|
|
99
|
-
@staticmethod
|
|
100
|
-
def testAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[ast.Assert | ast.If | ast.IfExp | ast.While], ast.Assert | ast.If | ast.IfExp | ast.While]:
|
|
101
|
-
def workhorse(node: ast.Assert | ast.If | ast.IfExp | ast.While) -> ast.Assert | ast.If | ast.IfExp | ast.While:
|
|
102
|
-
node.test = action(node.test)
|
|
103
|
-
return node
|
|
104
|
-
return workhorse
|
|
105
|
-
|
|
106
|
-
@staticmethod
|
|
107
|
-
def valueAttribute(action: Callable[[Any], Any]) -> Callable[[astClassHasDOTvalue], astClassHasDOTvalue]:
|
|
108
|
-
def workhorse(node: astClassHasDOTvalue) -> astClassHasDOTvalue:
|
|
109
|
-
node.value = action(node.value)
|
|
110
|
-
return node
|
|
111
|
-
return workhorse
|
|
112
|
-
|
|
113
|
-
class Then:
|
|
114
|
-
"""
|
|
115
|
-
Provide action functions that specify what to do with AST nodes that match predicates.
|
|
116
|
-
|
|
117
|
-
The Then class contains static methods that generate action functions used with
|
|
118
|
-
NodeChanger and NodeTourist to transform or extract information from AST nodes
|
|
119
|
-
that match specific predicates. These actions include node replacement, insertion,
|
|
120
|
-
extraction, and collection operations.
|
|
121
|
-
|
|
122
|
-
When paired with predicates from the ifThis class, Then methods complete the
|
|
123
|
-
pattern-matching-and-action workflow for AST manipulation.
|
|
124
|
-
"""
|
|
125
|
-
@staticmethod
|
|
126
|
-
def appendTo(listOfAny: list[Any]) -> Callable[[ast.AST | ast_Identifier], ast.AST | ast_Identifier]:
|
|
127
|
-
def workhorse(node: ast.AST | ast_Identifier) -> ast.AST | ast_Identifier:
|
|
128
|
-
listOfAny.append(node)
|
|
129
|
-
return node
|
|
130
|
-
return workhorse
|
|
131
|
-
|
|
132
|
-
@staticmethod
|
|
133
|
-
def extractIt(node: NodeORattribute) -> NodeORattribute:
|
|
134
|
-
return node
|
|
135
|
-
|
|
136
|
-
@staticmethod
|
|
137
|
-
def insertThisAbove(list_astAST: Sequence[ast.AST]) -> Callable[[ast.AST], Sequence[ast.AST]]:
|
|
138
|
-
return lambda aboveMe: [*list_astAST, aboveMe]
|
|
139
|
-
|
|
140
|
-
@staticmethod
|
|
141
|
-
def insertThisBelow(list_astAST: Sequence[ast.AST]) -> Callable[[ast.AST], Sequence[ast.AST]]:
|
|
142
|
-
return lambda belowMe: [belowMe, *list_astAST]
|
|
143
|
-
|
|
144
|
-
@staticmethod
|
|
145
|
-
def removeIt(_removeMe: ast.AST) -> None:
|
|
146
|
-
return None
|
|
147
|
-
|
|
148
|
-
@staticmethod
|
|
149
|
-
def replaceWith(astAST: NodeORattribute) -> Callable[[NodeORattribute], NodeORattribute]:
|
|
150
|
-
return lambda _replaceMe: astAST
|
|
151
|
-
|
|
152
|
-
@staticmethod
|
|
153
|
-
def updateKeyValueIn(key: Callable[..., Any], value: Callable[..., Any], dictionary: dict[Any, Any]) -> Callable[[ast.AST], dict[Any, Any]]:
|
|
154
|
-
def workhorse(node: ast.AST) -> dict[Any, Any]:
|
|
155
|
-
dictionary.setdefault(key(node), value(node))
|
|
156
|
-
return dictionary
|
|
157
|
-
return workhorse
|