From 60ef77b3e2dcf8f8222883976f0619004eaf005b Mon Sep 17 00:00:00 2001 From: Oscar Levin Date: Thu, 4 Jun 2026 12:52:38 -0500 Subject: [PATCH 1/2] update fetch_core script to include new core python modules for building --- .gitignore | 5 ++++- pretext/__init__.py | 2 +- scripts/fetch_core.py | 40 ++++++++++++++-------------------------- scripts/symlink_core.py | 20 +++++++------------- scripts/utils.py | 6 ++++++ 5 files changed, 32 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 9ce1e8fd..8053e201 100644 --- a/.gitignore +++ b/.gitignore @@ -139,6 +139,9 @@ cython_debug/ #pretext-core pretext/core/pretext.py pretext/core/braille_format.py +pretext/core/common.py +pretext/core/stack.py +pretext/core/webwork.py tests/examples/core #zipped resources pretext/resources/*.zip @@ -171,4 +174,4 @@ new-pretext-project *.synctex(busy) *.synctex.gz *.synctex.gz(busy) -*.pdfsync \ No newline at end of file +*.pdfsync diff --git a/pretext/__init__.py b/pretext/__init__.py index 1be6f8a0..bcfe3aed 100644 --- a/pretext/__init__.py +++ b/pretext/__init__.py @@ -19,7 +19,7 @@ VERSION = get_version("pretext", Path(__file__).parent.parent) -CORE_COMMIT = "f96a117fce6e23c5af6df4038cad6ce87aec3ef9" +CORE_COMMIT = "de5a032b1da01c8352ea2e116eb99b9cb388282f" def activate() -> None: diff --git a/scripts/fetch_core.py b/scripts/fetch_core.py index 7cddcd82..3c70a9a2 100644 --- a/scripts/fetch_core.py +++ b/scripts/fetch_core.py @@ -61,9 +61,6 @@ def main(args: any = None, update_templates: bool = False) -> None: print(f"Requesting core {repo_name} commit {CORE_COMMIT} from GitHub.") core_zip_path = Path("pretext").resolve() / "resources" / "core.zip" core_zip = requests.get(f"https://github.com/{repo_name}/archive/{CORE_COMMIT}.zip") - # remove current core/pretext.py file in case it is a link - utils.remove_path(Path("pretext").resolve() / "core" / "pretext.py") - utils.remove_path(Path("pretext").resolve() / "core" / "braille_format.py") with open(core_zip_path, "wb") as f: f.write(core_zip.content) @@ -71,40 +68,31 @@ def main(args: any = None, update_templates: bool = False) -> None: with tempfile.TemporaryDirectory(prefix="ptxcli_") as tmpdirname: with zipfile.ZipFile(core_zip_path) as archive: archive.extractall(tmpdirname) - # Run the cssbuilder script: - # update_css(tmpdirname) - - shutil.copyfile( - Path(tmpdirname) - / f"pretext-{CORE_COMMIT}" - / "pretext" - / "lib" - / "pretext.py", - Path("pretext").resolve() / "core" / "pretext.py", - ) - shutil.copyfile( - Path(tmpdirname) - / f"pretext-{CORE_COMMIT}" - / "pretext" - / "lib" - / "braille_format.py", - Path("pretext").resolve() / "core" / "braille_format.py", - ) + + extracted_core_path = Path(tmpdirname) / f"pretext-{CORE_COMMIT}" + source_core_lib_path = extracted_core_path / "pretext" / "lib" + local_core_path = Path("pretext").resolve() / "core" + for existing_file in utils.core_python_files(local_core_path): + utils.remove_path(existing_file) + # Get all core python files from the extracted core (except __init__.py) and copy them to the local core directory + for source_file in utils.core_python_files(source_core_lib_path): + shutil.copyfile(source_file, local_core_path / source_file.name) + # Get the remaining core files: shutil.copytree( - Path(tmpdirname) / f"pretext-{CORE_COMMIT}" / "examples", + extracted_core_path / "examples", Path("tests").resolve() / "examples" / "core" / "examples", dirs_exist_ok=True, ) shutil.rmtree( - Path(tmpdirname) / f"pretext-{CORE_COMMIT}" / "examples", + extracted_core_path / "examples", ) shutil.copytree( - Path(tmpdirname) / f"pretext-{CORE_COMMIT}" / "doc", + extracted_core_path / "doc", Path("tests").resolve() / "examples" / "core" / "doc", dirs_exist_ok=True, ) shutil.rmtree( - Path(tmpdirname) / f"pretext-{CORE_COMMIT}" / "doc", + extracted_core_path / "doc", ) print( "Successfully updated core PreTeXtBook/pretext files from GitHub.\n Now zippping core resources." diff --git a/scripts/symlink_core.py b/scripts/symlink_core.py index 20e2add2..b945b2e8 100644 --- a/scripts/symlink_core.py +++ b/scripts/symlink_core.py @@ -1,5 +1,6 @@ import sys from pathlib import Path + import pretext.resources from scripts import utils @@ -15,19 +16,12 @@ def main(core_path: Path = Path("../pretext")) -> None: # Create a symlink to the core directory link_path.symlink_to(core_path) - # Remove the current pretext/core/pretext.py file - script_link_path = Path("pretext").resolve() / "core" / "pretext.py" - script_core_path = core_path / "pretext" / "lib" / "pretext.py" - utils.remove_path(script_link_path) - # Link to the local core python script - script_link_path.symlink_to(script_core_path) - - # Repeat for braille_format the current pretext/core/pretext.py file - script_link_path = Path("pretext").resolve() / "core" / "braille_format.py" - script_core_path = core_path / "pretext" / "lib" / "braille_format.py" - utils.remove_path(script_link_path) - # Link to the local core python script - script_link_path.symlink_to(script_core_path) + source_core_lib_path = core_path / "pretext" / "lib" + local_core_path = Path("pretext").resolve() / "core" + for existing_file in utils.core_python_files(local_core_path): + utils.remove_path(existing_file) + for source_file in utils.core_python_files(source_core_lib_path): + (local_core_path / source_file.name).symlink_to(source_file) print(f"Linked local core pretext directory `{core_path}`") diff --git a/scripts/utils.py b/scripts/utils.py index fe513c15..82f137fd 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -7,3 +7,9 @@ def remove_path(path: Path) -> None: path.unlink() # remove the file elif path.is_dir(): shutil.rmtree(path) # remove dir and all it contains + + +def core_python_files(core_lib_path: Path) -> list[Path]: + return sorted( + path for path in core_lib_path.glob("*.py") if path.name != "__init__.py" + ) From 455da471d0a69465052b5cd6e067c17cd67a550e Mon Sep 17 00:00:00 2001 From: Oscar Levin Date: Thu, 4 Jun 2026 13:02:54 -0500 Subject: [PATCH 2/2] fix mypy exclusions --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9cbc4482..aee6de48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,7 +105,7 @@ script_launch_mode = "subprocess" [tool.mypy] # See `files `_. files = "pretext,tests" -exclude = ["^pretext/core/pretext\\.py$", "^pretext/core/__init__\\.py$", "^pretext/core/braille_format\\.py$"] +exclude = ["^pretext/core/.*\\.py$",] check_untyped_defs = true disallow_untyped_defs = true