Skip to content
Merged

Ww bug #1141

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
77 changes: 67 additions & 10 deletions .github/workflows/deploy-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,68 @@ on:
- "oscarlevin/pretext"

jobs:
prepare:
name: Prepare nightly source
runs-on: ubuntu-latest
outputs:
ready: ${{ steps.prep.outputs.ready }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Install poetry 1.8.4
run: |
python -m pip install --upgrade pip
python -m pip install poetry==1.8.4

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get -y install python3-louis librsvg2-bin libcairo2-dev

- name: Install dependencies
shell: bash
run: python -m poetry install --all-extras

- name: Run prep-nightly script
id: prep
shell: bash
run: |
echo "Updating core commit and version; building"
output=$(poetry run python scripts/prep_nightly.py ${{ inputs.core-repo }})
echo "$output"
echo "Finished steps to prep nightly deployment"
if [[ $output == *"Ready to deploy"* ]]; then
echo "ready=true" >> "$GITHUB_OUTPUT"
else
echo "ready=false" >> "$GITHUB_OUTPUT"
fi

- name: Upload prepared source
if: ${{ steps.prep.outputs.ready == 'true' }}
uses: actions/upload-artifact@v4
with:
name: nightly-prepared-source
path: |
pretext/
tests/examples/core/
templates/
pyproject.toml

tests:
needs: prepare
if: ${{ needs.prepare.outputs.ready == 'true' }}
name: Run tests
uses: ./.github/workflows/tests.yml
with:
source-artifact: nightly-prepared-source

deploy:
needs: tests
needs: [prepare, tests]
if: ${{ needs.prepare.outputs.ready == 'true' }}
name: Deploy to pypi
runs-on: ubuntu-latest
steps:
Expand All @@ -45,19 +101,20 @@ jobs:
sudo apt-get update
sudo apt-get -y install python3-louis librsvg2-bin libcairo2-dev

- name: Download prepared source
uses: actions/download-artifact@v4
with:
name: nightly-prepared-source
path: .

- name: Install dependencies
shell: bash
run: python -m poetry install --all-extras

- name: Run prep-nightly script and publish if ready
- name: Publish nightly build
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
echo "Updating core commit and version; building"
output=$(poetry run python scripts/prep_nightly.py ${{ inputs.core-repo }})
echo "Finished steps to prep nightly deployment"
if [[ $output == *"Ready to deploy"* ]]; then
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
echo "Published to pypi"
fi
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
echo "Published to pypi"
53 changes: 43 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ on:
workflow_dispatch:
# Allows usage from other workflows
workflow_call:
inputs:
source-artifact:
description: Prepared source artifact to test instead of fetching core into a fresh checkout.
required: false
type: string
default: ""

jobs:
format-and-types:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Download prepared source
if: ${{ inputs.source-artifact != '' }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.source-artifact }}
path: .
- uses: actions/setup-node@v4
with:
node-version: '22'
Expand All @@ -25,10 +37,11 @@ jobs:
run: python -m pip install flake8 black mypy
- name: Install poetry
run: python -m pip install poetry
- name: Install dependencies
run: python -m poetry install
- name: Initialize project
run: |
python -m poetry install
python -m poetry run python scripts/fetch_core.py
if: ${{ inputs.source-artifact == '' }}
run: python -m poetry run python scripts/fetch_core.py
- name: Check formatting with black
run: python -m poetry run black --check --diff $(git ls-files "*.py")
- name: Check for lint
Expand All @@ -43,6 +56,12 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Download prepared source
if: ${{ inputs.source-artifact != '' }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.source-artifact }}
path: .

- name: Report Python version
run: python --version
Expand All @@ -67,9 +86,10 @@ jobs:

- name: Install dependencies
shell: bash
run: |
poetry install --all-extras
poetry run python scripts/fetch_core.py
run: poetry install --all-extras
- name: Initialize project
if: ${{ inputs.source-artifact == '' }}
run: poetry run python scripts/fetch_core.py

- name: Ensure dependencies are present
run: |
Expand Down Expand Up @@ -102,6 +122,12 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Download prepared source
if: ${{ inputs.source-artifact != '' }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.source-artifact }}
path: .

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down Expand Up @@ -130,9 +156,10 @@ jobs:

- name: Install dependencies
shell: bash
run: |
python -m poetry install --all-extras
python -m poetry run python scripts/fetch_core.py
run: python -m poetry install --all-extras
- name: Initialize project
if: ${{ inputs.source-artifact == '' }}
run: python -m poetry run python scripts/fetch_core.py

- name: Initialize playwright
run: |
Expand All @@ -156,6 +183,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download prepared source
if: ${{ inputs.source-artifact != '' }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.source-artifact }}
path: .
- uses: awalsh128/cache-apt-pkgs-action@v1.4.3
with:
packages: jing trang
Expand All @@ -166,4 +199,4 @@ jobs:
cmp ./schema/project-ptx.rng ./tmp-project-ptx.rng
- name: Verify template `project.ptx` match schema via JING
run: |
for i in $(find ./templates -name "project.ptx"); do jing ./schema/project-ptx.rng "$i"; done
for i in $(find ./templates -name "project.ptx"); do jing ./schema/project-ptx.rng "$i"; done
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Instructions: Add a subsection under `[Unreleased]` for additions, fixes, change

## [Unreleased]

### Added

- Better support for building latex from pretext: detects when latex needs to be rerun multiple times.

### Fixed

- Bug that failed to detect webwork problems authored as local pg files.
- epub fillinmath and sfrac rendering.

## [2.38.2] - 2026-04-07

Includes updates to core through commit: [22c2cd3](https://github.com/PreTeXtBook/pretext/commit/22c2cd36f996308ae16df2b77aa60ee9af5a8e69)
Expand Down
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 = "22c2cd36f996308ae16df2b77aa60ee9af5a8e69"
CORE_COMMIT = "f22ebc5d4ac96835c69e141ce89bd313c33210a2"


def activate() -> None:
Expand Down
5 changes: 3 additions & 2 deletions pretext/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"datafile",
"myopenmath",
"dynamic-subs",
"qrcode",
],
"pdf": [
"webwork",
Expand Down Expand Up @@ -143,7 +144,7 @@
}

ASSET_TO_XPATH = {
"webwork": ".//webwork[*|@*]",
"webwork": ".//webwork[*|@*|text()]",
"latex-image": ".//latex-image",
"sageplot": ".//sageplot",
"asymptote": ".//asymptote",
Expand All @@ -152,7 +153,7 @@
"codelens": ".//program[@interactive = 'codelens']",
"datafile": ".//datafile",
"interactive": ".//interactive",
"qrcode": ".//audio[@source|@href]|.//video[@source|@href|@youtube|@youtubeplaylist|@vimeo]|.//interactive",
"qrcode": ".//audio[@source|@href]|.//video[@source|@href|@youtube|@youtubeplaylist|@vimeo]|.//interactive|.//program[@interactive]",
"mermaid": ".//mermaid",
"myopenmath": ".//myopenmath",
"dynamic-subs": ".//statement[.//fillin and ancestor::exercise/evaluation]",
Expand Down
45 changes: 24 additions & 21 deletions pretext/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ def ensure_webwork_reps(self) -> None:
"""
Ensures that the webwork representation file is present if the source contains webwork problems. This is needed to build or generate other assets.
"""
if self.source_element().xpath(".//webwork[@*|*]"):
# NB: need to include `text()` as well as `@*|*` in the xpath, since some webwork problems are only included as text/pg source.
if self.source_element().xpath(".//webwork[@*|*|text()]"):
log.debug("Source contains webwork problems")
if not (
self.generated_dir_abspath() / "webwork" / "webwork-representations.xml"
Expand Down Expand Up @@ -1093,7 +1094,29 @@ def generate_assets(
f"Unable to extract some dynamic exercise substitutions: \n{e}"
)
log.debug(e, exc_info=True)
if "qrcode" in assets_to_generate:
log.warning("Now generating QR codes")
try:
# Warn if trying to generate qrcodes without a base URL.
base_url = self._read_publication_file_subset().baseurl
if base_url is None:
log.warning(
"You are trying to generate qrcodes, but the publication file does not have a base URL. "
+ "This will result in qrcodes that do not point to anything meaningful."
)
core.qrcode(
xml_source=self.source_abspath(),
pub_file=self.publication_abspath().as_posix(),
stringparams=stringparams_copy,
xmlid_root=xmlid,
dest_dir=self.generated_dir_abspath() / "qrcode",
)
successful_assets.append("qrcode")
except Exception as e:
log.error(f"Unable to generate some qrcodes:\n {e}")
log.debug(e, exc_info=True)
if "latex-image" in assets_to_generate:
log.warning("Now generating latex images")
try:
for outformat in asset_formats["latex-image"]:
core.latex_image_conversion(
Expand Down Expand Up @@ -1207,26 +1230,6 @@ def generate_assets(
log.debug(e, exc_info=True)
# youtube also requires the play button.
self.ensure_play_button()
if "qrcode" in assets_to_generate:
try:
# Warn if trying to generate qrcodes without a base URL.
base_url = self._read_publication_file_subset().baseurl
if base_url is None:
log.warning(
"You are trying to generate qrcodes, but the publication file does not have a base URL. "
+ "This will result in qrcodes that do not point to anything meaningful."
)
core.qrcode(
xml_source=self.source_abspath(),
pub_file=self.publication_abspath().as_posix(),
stringparams=stringparams_copy,
xmlid_root=xmlid,
dest_dir=self.generated_dir_abspath() / "qrcode",
)
successful_assets.append("qrcode")
except Exception as e:
log.error(f"Unable to generate some qrcodes:\n {e}")
log.debug(e, exc_info=True)
if "mermaid" in assets_to_generate:
try:
for outformat in asset_formats["mermaid"]:
Expand Down
Loading