mapFolding 0.12.2__py3-none-any.whl → 0.13.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.
Files changed (33) hide show
  1. mapFolding/__init__.py +4 -2
  2. mapFolding/_theSSOT.py +32 -88
  3. mapFolding/{datatypes.py → _theTypes.py} +25 -3
  4. mapFolding/basecamp.py +38 -33
  5. mapFolding/beDRY.py +79 -54
  6. mapFolding/dataBaskets.py +123 -93
  7. mapFolding/filesystemToolkit.py +140 -91
  8. mapFolding/oeis.py +243 -145
  9. mapFolding/reference/flattened.py +1 -1
  10. mapFolding/someAssemblyRequired/RecipeJob.py +116 -100
  11. mapFolding/someAssemblyRequired/__init__.py +40 -15
  12. mapFolding/someAssemblyRequired/_toolIfThis.py +82 -54
  13. mapFolding/someAssemblyRequired/_toolkitContainers.py +19 -16
  14. mapFolding/someAssemblyRequired/getLLVMforNoReason.py +35 -26
  15. mapFolding/someAssemblyRequired/makeAllModules.py +353 -283
  16. mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +83 -84
  17. mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +256 -0
  18. mapFolding/someAssemblyRequired/toolkitNumba.py +80 -50
  19. mapFolding/someAssemblyRequired/transformationTools.py +63 -40
  20. {tests → mapFolding/tests}/__init__.py +2 -2
  21. {tests → mapFolding/tests}/conftest.py +232 -63
  22. {tests → mapFolding/tests}/test_computations.py +58 -18
  23. {tests → mapFolding/tests}/test_filesystem.py +10 -13
  24. {tests → mapFolding/tests}/test_oeis.py +5 -18
  25. {tests → mapFolding/tests}/test_other.py +9 -9
  26. {tests → mapFolding/tests}/test_tasks.py +7 -9
  27. {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/METADATA +24 -37
  28. mapfolding-0.13.0.dist-info/RECORD +54 -0
  29. {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/top_level.txt +0 -1
  30. mapfolding-0.12.2.dist-info/RECORD +0 -53
  31. {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/WHEEL +0 -0
  32. {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/entry_points.txt +0 -0
  33. {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +1,8 @@
1
1
  """
2
2
  Persistent storage infrastructure for map folding computation results.
3
3
 
4
+ (AI generated docstring)
5
+
4
6
  As computational state management orchestrates the complex recursive analysis,
5
7
  this module ensures that the valuable results of potentially multi-day computations
6
8
  are safely preserved and reliably retrievable. Map folding problems can require
@@ -27,47 +29,57 @@ import os
27
29
  import platformdirs
28
30
 
29
31
  def getFilenameFoldsTotal(mapShape: tuple[int, ...]) -> str:
30
- """
31
- Create a standardized filename for a computed `foldsTotal` value.
32
+ """Create a standardized filename for a computed `foldsTotal` value.
33
+
34
+ (AI generated docstring)
32
35
 
33
36
  This function generates a consistent, filesystem-safe filename based on map dimensions. Standardizing filenames
34
37
  ensures that results can be reliably stored and retrieved, avoiding potential filesystem incompatibilities or Python
35
38
  naming restrictions.
36
39
 
37
- Parameters:
38
- mapShape: A sequence of integers representing the dimensions of the map.
40
+ Parameters
41
+ ----------
42
+ mapShape : tuple[int, ...]
43
+ A sequence of integers representing the dimensions of the map.
44
+
45
+ Returns
46
+ -------
47
+ filenameFoldsTotal : str
48
+ A filename string in format 'pMxN.foldsTotal' where M,N are sorted dimensions.
39
49
 
40
- Returns:
41
- filenameFoldsTotal: A filename string in format 'pMxN.foldsTotal' where M,N are sorted dimensions.
50
+ Notes
51
+ -----
52
+ The filename format ensures no spaces in the filename, safe filesystem characters, unique extension (.foldsTotal),
53
+ Python-safe strings (no starting with numbers, no reserved words), and the 'p' prefix comes from Lunnon's original code.
42
54
 
43
- Notes:
44
- The filename format ensures:
45
- - No spaces in the filename
46
- - Safe filesystem characters
47
- - Unique extension (.foldsTotal)
48
- - Python-safe strings (no starting with numbers, no reserved words)
49
- - The 'p' prefix comes from Lunnon's original code.
50
55
  """
51
56
  return 'p' + 'x'.join(str(dimension) for dimension in sorted(mapShape)) + '.foldsTotal'
52
57
 
53
58
  def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal: PathLike[str] | PurePath | None = None) -> Path:
54
- """
55
- Get a standardized path and filename for the computed `foldsTotal` value.
59
+ """Get a standardized path and filename for the computed `foldsTotal` value.
60
+
61
+ (AI generated docstring)
56
62
 
57
63
  This function resolves paths for storing computation results, handling different input types including directories,
58
64
  absolute paths, or relative paths. It ensures that all parent directories exist in the resulting path.
59
- Parameters:
60
- mapShape: A sequence of integers representing the map dimensions.
61
- pathLikeWriteFoldsTotal (getPathRootJobDEFAULT): Path, filename, or relative path and filename. If None, uses
62
- default path. If a directory, appends standardized filename.
63
65
 
64
- Returns:
65
- pathFilenameFoldsTotal: Absolute path and filename for storing the `foldsTotal` value.
66
+ Parameters
67
+ ----------
68
+ mapShape : tuple[int, ...]
69
+ A sequence of integers representing the map dimensions.
70
+ pathLikeWriteFoldsTotal : PathLike[str] | PurePath | None = getPathRootJobDEFAULT()
71
+ Path, filename, or relative path and filename. If None, uses default path. If a directory, appends standardized filename.
66
72
 
67
- Notes:
68
- The function creates any necessary directories in the path if they don't exist.
69
- """
73
+ Returns
74
+ -------
75
+ pathFilenameFoldsTotal : Path
76
+ Absolute path and filename for storing the `foldsTotal` value.
70
77
 
78
+ Notes
79
+ -----
80
+ The function creates any necessary directories in the path if they don't exist.
81
+
82
+ """
71
83
  if pathLikeWriteFoldsTotal is None:
72
84
  pathFilenameFoldsTotal = getPathRootJobDEFAULT() / getFilenameFoldsTotal(mapShape)
73
85
  else:
@@ -83,133 +95,170 @@ def getPathFilenameFoldsTotal(mapShape: tuple[int, ...], pathLikeWriteFoldsTotal
83
95
  return pathFilenameFoldsTotal
84
96
 
85
97
  def getPathRootJobDEFAULT() -> Path:
86
- """
87
- Get the default root directory for map folding computation jobs.
98
+ """Get the default root directory for map folding computation jobs.
99
+
100
+ (AI generated docstring)
88
101
 
89
102
  This function determines the appropriate default directory for storing computation results based on the current
90
103
  runtime environment. It uses platform-specific directories for normal environments and adapts to special
91
104
  environments like Google Colab.
92
105
 
93
- Returns:
94
- pathJobDEFAULT: Path to the default directory for storing computation results
106
+ Returns
107
+ -------
108
+ pathJobDEFAULT : Path
109
+ Path to the default directory for storing computation results.
110
+
111
+ Notes
112
+ -----
113
+ For standard environments, uses `platformdirs` to find appropriate user data directory.
114
+ For Google Colab, uses a specific path in Google Drive.
115
+ Creates the directory if it doesn't exist.
95
116
 
96
- Notes:
97
- - For standard environments, uses `platformdirs` to find appropriate user data directory.
98
- - For Google Colab, uses a specific path in Google Drive.
99
- - Creates the directory if it doesn't exist.
100
117
  """
101
- pathJobDEFAULT = Path(platformdirs.user_data_dir(appname=packageSettings.packageName, appauthor=False, ensure_exists=True))
118
+ pathJobDEFAULT = Path(platformdirs.user_data_dir(appname=packageSettings.identifierPackage, appauthor=False, ensure_exists=True))
102
119
  if 'google.colab' in sysModules:
103
- pathJobDEFAULT = Path("/content/drive/MyDrive") / packageSettings.packageName
120
+ pathJobDEFAULT = Path("/content/drive/MyDrive") / packageSettings.identifierPackage
104
121
  pathJobDEFAULT.mkdir(parents=True, exist_ok=True)
105
122
  return pathJobDEFAULT
106
123
 
107
124
  def _saveFoldsTotal(pathFilename: PathLike[str] | PurePath, foldsTotal: int) -> None:
108
- """
109
- Internal function to save a `foldsTotal` value to a file.
125
+ """Save a `foldsTotal` value to a file.
126
+
127
+ (AI generated docstring)
110
128
 
111
129
  This function provides the core file writing functionality used by the public `saveFoldsTotal` function. It handles
112
130
  the basic operations of creating parent directories and writing the integer value as text to the specified file
113
131
  location.
114
132
 
115
- Parameters:
116
- pathFilename: Path where the `foldsTotal` value should be saved.
117
- foldsTotal: The integer value to save.
133
+ Parameters
134
+ ----------
135
+ pathFilename : PathLike[str] | PurePath
136
+ Path where the `foldsTotal` value should be saved.
137
+ foldsTotal : int
138
+ The integer value to save.
139
+
140
+ Notes
141
+ -----
142
+ This is an internal function that doesn't include error handling or fallback mechanisms. Use `saveFoldsTotal`
143
+ for production code that requires robust error handling.
118
144
 
119
- Notes:
120
- This is an internal function that doesn't include error handling or fallback mechanisms. Use `saveFoldsTotal`
121
- for production code that requires robust error handling.
122
145
  """
123
146
  pathFilenameFoldsTotal = Path(pathFilename)
124
147
  pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
125
148
  pathFilenameFoldsTotal.write_text(str(foldsTotal))
126
149
 
127
150
  def saveFoldsTotal(pathFilename: PathLike[str] | PurePath, foldsTotal: int) -> None:
128
- """
129
- Save `foldsTotal` value to disk with multiple fallback mechanisms.
151
+ """Save `foldsTotal` value to disk with multiple fallback mechanisms.
152
+
153
+ (AI generated docstring)
130
154
 
131
155
  This function attempts to save the computed `foldsTotal` value to the specified location, with backup strategies in
132
156
  case the primary save attempt fails. The robustness is critical since these computations may take days to complete.
133
- Parameters:
134
- pathFilename: Target save location for the `foldsTotal` value.
135
- foldsTotal: The computed value to save.
136
- Notes:
137
- If the primary save fails, the function will attempt alternative save methods:
138
- 1. Print the value prominently to `stdout`.
139
- 2. Create a fallback file in the current working directory.
140
- 3. As a last resort, simply print the value.
141
-
142
- The fallback filename includes a unique identifier based on the value itself to prevent conflicts.
157
+
158
+ Parameters
159
+ ----------
160
+ pathFilename : PathLike[str] | PurePath
161
+ Target save location for the `foldsTotal` value.
162
+ foldsTotal : int
163
+ The computed value to save.
164
+
165
+ Notes
166
+ -----
167
+ If the primary save fails, the function will attempt alternative save methods.
168
+ Print the value prominently to `stdout`.
169
+ Create a fallback file in the current working directory.
170
+ As a last resort, simply print the value.
171
+
172
+ The fallback filename includes a unique identifier based on the value itself to prevent conflicts.
173
+
143
174
  """
144
175
  try:
145
176
  _saveFoldsTotal(pathFilename, foldsTotal)
146
- except Exception as ERRORmessage:
177
+ except Exception as ERRORmessage: # noqa: BLE001
147
178
  try:
148
- print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
149
- print(ERRORmessage)
150
- print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n")
179
+ print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n") # noqa: T201
180
+ print(ERRORmessage) # noqa: T201
181
+ print(f"\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n\n{foldsTotal = }\n\nfoldsTotal foldsTotal foldsTotal foldsTotal foldsTotal\n") # noqa: T201
151
182
  randomnessPlanB = (int(str(foldsTotal).strip()[-1]) + 1) * ['YO_']
152
183
  filenameInfixUnique = ''.join(randomnessPlanB)
153
- pathFilenamePlanB = os.path.join(os.getcwd(), 'foldsTotal' + filenameInfixUnique + '.txt')
154
- writeStreamFallback = open(pathFilenamePlanB, 'w')
184
+ pathFilenamePlanB = os.path.join(os.getcwd(), 'foldsTotal' + filenameInfixUnique + '.txt') # noqa: PTH109, PTH118
185
+ writeStreamFallback = open(pathFilenamePlanB, 'w') # noqa: PTH123, SIM115
155
186
  writeStreamFallback.write(str(foldsTotal))
156
187
  writeStreamFallback.close()
157
- print(str(pathFilenamePlanB))
158
- except Exception:
159
- print(foldsTotal)
160
- return None
188
+ print(str(pathFilenamePlanB)) # noqa: T201
189
+ except Exception: # noqa: BLE001
190
+ print(foldsTotal) # noqa: T201
161
191
 
162
192
  def saveFoldsTotalFAILearly(pathFilename: PathLike[str] | PurePath) -> None:
163
- """
164
- Preemptively test file write capabilities before beginning computation.
193
+ """Preemptively test file write capabilities before beginning computation.
165
194
 
166
- This function performs validation checks on the target file location before a potentially long-running computation
167
- begins. It tests several critical aspects of filesystem functionality to ensure results can be saved:
195
+ (AI generated docstring)
168
196
 
197
+ This function performs validation checks on the target file location before a potentially long-running computation
198
+ begins. It tests several critical aspects of filesystem functionality to ensure results can be saved.
199
+
200
+ Parameters
201
+ ----------
202
+ pathFilename : PathLike[str] | PurePath
203
+ The path and filename where computation results will be saved.
204
+
205
+ Raises
206
+ ------
207
+ FileExistsError
208
+ If the target file already exists.
209
+ FileNotFoundError
210
+ If parent directories don't exist or if write tests fail.
211
+
212
+ Notes
213
+ -----
214
+ Checks performed:
169
215
  1. Checks if the file already exists to prevent accidental overwrites.
170
216
  2. Verifies that parent directories exist.
171
217
  3. Tests if the system can write a test value to the file.
172
218
  4. Confirms that the written value can be read back correctly.
173
219
 
174
- Parameters:
175
- pathFilename: The path and filename where computation results will be saved.
220
+ This function helps prevent a situation where a computation runs for hours or days only to discover at the end
221
+ that results cannot be saved. The test value used is a large integer that exercises both the writing and
222
+ reading mechanisms thoroughly.
176
223
 
177
- Raises:
178
- FileExistsError: If the target file already exists.
179
- FileNotFoundError: If parent directories don't exist or if write tests fail.
180
- Notes:
181
- This function helps prevent a situation where a computation runs for hours or days only to discover at the end
182
- that results cannot be saved. The test value used is a large integer that exercises both the writing and
183
- reading mechanisms thoroughly.
184
224
  """
185
225
  if Path(pathFilename).exists():
186
- raise FileExistsError(f"`{pathFilename = }` exists: a battle of overwriting might cause tears.")
226
+ message = f"`{pathFilename = }` exists: a battle of overwriting might cause tears."
227
+ raise FileExistsError(message)
187
228
  if not Path(pathFilename).parent.exists():
188
- raise FileNotFoundError(f"I received `{pathFilename = }` 0.000139 seconds ago from a function that promised it created the parent directory, but the parent directory does not exist. Fix that now, so your computation doesn't get deleted later. And be compassionate to others.")
229
+ message = f"I received `{pathFilename = }` 0.000139 seconds ago from a function that promised it created the parent directory, but the parent directory does not exist. Fix that now, so your computation doesn't get deleted later. And be compassionate to others."
230
+ raise FileNotFoundError(message)
189
231
  foldsTotal = 149302889205120
190
232
  _saveFoldsTotal(pathFilename, foldsTotal)
191
233
  if not Path(pathFilename).exists():
192
- raise FileNotFoundError(f"I just wrote a test file to `{pathFilename = }`, but it does not exist. Fix that now, so your computation doesn't get deleted later. And continually improve your empathy skills.")
193
- foldsTotalRead = int(Path(pathFilename).read_text())
234
+ message = f"I just wrote a test file to `{pathFilename = }`, but it does not exist. Fix that now, so your computation doesn't get deleted later. And continually improve your empathy skills."
235
+ raise FileNotFoundError(message)
236
+ foldsTotalRead = int(Path(pathFilename).read_text(encoding="utf-8"))
194
237
  if foldsTotalRead != foldsTotal:
195
- raise FileNotFoundError(f"I wrote a test file to `{pathFilename = }` with contents of `{str(foldsTotal) = }`, but I read `{foldsTotalRead = }` from the file. Python says the values are not equal. Fix that now, so your computation doesn't get corrupted later. And be pro-social.")
238
+ message = f"I wrote a test file to `{pathFilename = }` with contents of `{str(foldsTotal) = }`, but I read `{foldsTotalRead = }` from the file. Python says the values are not equal. Fix that now, so your computation doesn't get corrupted later. And be pro-social."
239
+ raise FileNotFoundError(message)
196
240
 
197
241
  def writeStringToHere(this: str, pathFilename: PathLike[str] | PurePath) -> None:
198
- """
199
- Write a string to a file, creating parent directories if needed.
242
+ """Write a string to a file, creating parent directories if needed.
243
+
244
+ (AI generated docstring)
200
245
 
201
246
  This utility function provides a consistent interface for writing string content to files across the package. It
202
247
  handles path creation and ensures proper string conversion.
203
248
 
204
- Parameters:
205
- this: The string content to write to the file.
206
- pathFilename: The target file path where the string should be written.
249
+ Parameters
250
+ ----------
251
+ this : str
252
+ The string content to write to the file.
253
+ pathFilename : PathLike[str] | PurePath
254
+ The target file path where the string should be written.
255
+
256
+ Notes
257
+ -----
258
+ This function creates all parent directories in the path if they don't exist, making it safe to use with newly
259
+ created directory structures.
207
260
 
208
- Notes:
209
- This function creates all parent directories in the path if they don't exist, making it safe to use with newly
210
- created directory structures.
211
261
  """
212
262
  pathFilename = Path(pathFilename)
213
263
  pathFilename.parent.mkdir(parents=True, exist_ok=True)
214
264
  pathFilename.write_text(str(this))
215
- return None