Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ These instructions cover the mapFolding package. Top-level `Z0Z_*` folders are a

# Generated modules

- `mapFolding/oeis/byFormula.py`, `tests/test_byFormula.py`, `tests/test_relationsTriangle.py`, and `tests/dataSamples/oeis.py` are generated by `mapFolding.kitAST.oeis.oeisModules.makeModulesOEIS`. Tests and test data for `_symbolicRelations.py` come only from these generators: when a kind of relation has no test, extend the generator. Derive limits from stored terms and metadata, and propose to Hunter any limit that cannot be derived.
- `mapFolding/oeis/byFormula.py`, `tests/test_byFormula.py`, `tests/test_relationsTriangle.py`, and `tests/dataSamples/oeis.py` are generated by `mapFolding.kitAST.oeis.makeModules.makeModulesOEIS`. Tests and test data for `_symbolicRelations.py` come only from these generators: when a kind of relation has no test, extend the generator. Derive limits from stored terms and metadata, and propose to Hunter any limit that cannot be derived.
- After regenerating, run `easyRun\synthesizeModules.cmd`. It runs Ruff on `byFormula.py` to restore the formatting that regeneration changes, and it is safe to run at any time.

# AST generation in `mapFolding.kitAST`
Expand Down
2 changes: 1 addition & 1 deletion easyRun/synthesizeModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from mapFolding.kitAST.mapFoldingSymmetric.makeModulesAsynchronous import makeModulesFoldsSymmetricAsynchronous
from mapFolding.kitAST.matrixMeanders.makeModules import makeModulesMeanders
from mapFolding.kitAST.matrixMeanders.makeModulesAxis import makeModulesAxis
from mapFolding.kitAST.oeis.oeisModules import makeModulesOEIS
from mapFolding.kitAST.oeis.makeModules import makeModulesOEIS
from mapFolding.oeis import update_oeisdata

print("update_oeisdata")
Expand Down
2 changes: 1 addition & 1 deletion mapFolding/kitAST/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@
# isort: split
from mapFolding.kitAST._beDRY import (
removeFunctionDef as removeFunctionDef, renameFunctionDef as renameFunctionDef, renameName as renameName,
setDatatypeViaImport as setDatatypeViaImport, toDisk as toDisk)
resolvePathFilenameModule as resolvePathFilenameModule, setDatatypeViaImport as setDatatypeViaImport, toDisk as toDisk)
19 changes: 16 additions & 3 deletions mapFolding/kitAST/_beDRY.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
Rename a function definition in `node` when the function name matches `identifier`.
renameName
Rename matching name nodes in the supplied syntax tree.
resolvePathFilenameModule
Resolve the filename of a generated module from the caller's `**override` and `identifiers`.
setDatatypeViaImport
Replace datatype import aliases in generated function and module containers.
toDisk
Expand Down Expand Up @@ -188,9 +190,20 @@ def toDisk(ingredientsModule: IngredientsModule, identifiers: Default, override:
toDisk(ingredientsModule, identifiers, override, 名Module)
```
"""
return ingredientsModule.write_astModule(resolvePathFilenameModule(identifiers, override, 名Module)
, override.get('名Package') or identifiers['module']['package'])

def resolvePathFilenameModule(identifiers: Default, override: DefaultOverride, 名Module: str) -> PurePath:
"""Resolve the filename of a generated module from the caller's `**override` and `identifiers`.

(AI generated docstring)

An explicit truthy `pathFilename` in `override` is the filename. Otherwise, truthy values of `logicalPathInfix`,
`pathRoot`, and `fileExtension` in `override` precede `identifiers['logicalPath']['synthetic']`,
`identifiers['filesystem']['pathRoot']`, and `settingsPackage.fileExtension`, and
`mapFolding.kitAST.paths.makePathFilenameModule` constructs the filename with the stem `名Module`.
"""
logicalPathInfix: identifierDotAttribute = override.get('logicalPathInfix') or identifiers['logicalPath']['synthetic']
pathRoot: PathLike[str] = override.get('pathRoot') or identifiers['filesystem']['pathRoot']
名Package: str = override.get('名Package') or identifiers['module']['package']
fileExtension: str = override.get('fileExtension') or settingsPackage.fileExtension
pathFilename: PurePath = override.get('pathFilename') or makePathFilenameModule(pathRoot, logicalPathInfix, 名Module, fileExtension)
return ingredientsModule.write_astModule(pathFilename, 名Package)
return override.get('pathFilename') or makePathFilenameModule(pathRoot, logicalPathInfix, 名Module, fileExtension)
19 changes: 13 additions & 6 deletions mapFolding/kitAST/_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,9 @@ class IngredientsModule:
"""
Summary and description of the generated module.

The generated module opens with this text and a `Contents` section. The `Contents` section lists each public
function of the generated module with the summary line of the docstring of that function.
The generated module opens with this text and, when the module has a public function, a `Contents` section. The
`Contents` section lists each public function of the generated module with the summary line of the docstring of that
function.
"""

settings_autoflake: dict[str, Any] | None = dataclasses.field(default_factory=settings_autoflakeDEFAULT.copy)
Expand Down Expand Up @@ -793,8 +794,10 @@ def _makeDocstringModule(self, list_stmt: list[ast.stmt]) -> str:
"""I use this method to append the `Contents` section to `docstring` from the public functions in `list_stmt`."""
boxOfFunctionDefPublic: list[ast.FunctionDef] = sorted(filterfalse(Be.FunctionDef.nameIs(methodcaller('startswith', '_'))
, filter(Be.FunctionDef, list_stmt)), key=attrgetter('name'))
return '\n'.join([raiseIfNone(self.docstring).rstrip(), '', 'Contents', '--------', 'Functions'
, *map(_makeEntryContents, boxOfFunctionDefPublic), ''])
listLines: list[str] = [raiseIfNone(self.docstring).rstrip(), '']
if boxOfFunctionDefPublic:
listLines.extend(['Contents', '--------', 'Functions', *map(_makeEntryContents, boxOfFunctionDefPublic), ''])
return '\n'.join(listLines)

@property
def type_ignores(self) -> list[ast.TypeIgnore]:
Expand Down Expand Up @@ -883,8 +886,12 @@ def astModuleToIngredientsFunction(astAST: ast.AST, identifier: str) -> Ingredie
return IngredientsFunction(astFunctionDef, LedgerOfImports(astAST))

def _makeEntryContents(astFunctionDef: ast.FunctionDef) -> str:
"""I use this function to list `astFunctionDef` in the `Contents` section of a generated module docstring."""
return f'\t{astFunctionDef.name}\n\t\t{(ast.get_docstring(astFunctionDef) or "").partition("\n")[0]}'
"""I use this function to list `astFunctionDef` and its summary line, if any, in the `Contents` section of a generated module docstring."""
listLines: list[str] = [f'\t{astFunctionDef.name}']
summary: str = (ast.get_docstring(astFunctionDef) or '').partition('\n')[0]
if summary:
listLines.append(f'\t\t{summary}')
return '\n'.join(listLines)

def getBodySansDocstring(astModule: ast.Module) -> list[ast.stmt]:
"""Get the statements of `astModule` without its module docstring.
Expand Down
14 changes: 8 additions & 6 deletions mapFolding/kitAST/oeis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

Modules
-------
oeisIDByFormula
Generate sequence-formula source from the symbolic relations.
oeisModules
Write the formula module, its tests, and its reference samples.
oeisTests
Generate the tests of the formulas and of the triangle relations, and their reference samples.
makeModules
Regenerate the formula module, its tests, and their samples.
_byFormula
Generate the functions of `mapFolding.oeis.byFormula` from the solved relations.
_parametersTest
Select the parameters of the tests of the formulas and of the triangle relations.
_tests
Generate the test modules and the samples that they read.
"""

from __future__ import annotations
Loading