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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -171,4 +174,4 @@ new-pretext-project
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
*.pdfsync
2 changes: 1 addition & 1 deletion pretext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
VERSION = get_version("pretext", Path(__file__).parent.parent)


CORE_COMMIT = "f96a117fce6e23c5af6df4038cad6ce87aec3ef9"
CORE_COMMIT = "de5a032b1da01c8352ea2e116eb99b9cb388282f"


def activate() -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ script_launch_mode = "subprocess"
[tool.mypy]
# See `files <https://mypy.readthedocs.io/en/stable/config_file.html#confval-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

Expand Down
40 changes: 14 additions & 26 deletions scripts/fetch_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,50 +61,38 @@ 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)

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."
Expand Down
20 changes: 7 additions & 13 deletions scripts/symlink_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from pathlib import Path

import pretext.resources
from scripts import utils

Expand All @@ -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}`")


Expand Down
6 changes: 6 additions & 0 deletions scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Loading