Skip to content

Commit 616545d

Browse files
authored
use assembled source for the source_element() method, to work with versions (#959)
* use assembled source for the source_element() method, to work with versions * update changelog * fix tests
1 parent ab65e7e commit 616545d

14 files changed

Lines changed: 63 additions & 27 deletions

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Instructions: Add a subsection under `[Unreleased]` for additions, fixes, change
99

1010
## [Unreleased]
1111

12+
### Changed
13+
14+
- The CLI now uses your assembled source in case you use "versions" for checking for some source errors and deciding whether assets must be regenerated. For example, if you change an asset in a component that is not part of a version, it will not trigger rebuilding all assets.
15+
16+
### Fixed
17+
18+
- Fixed a bug with the denver theme that displayed some tasks with their headings not inline.
19+
1220
## [2.16.1] - 2025-04-08
1321

1422
Includes updates to core through commit: [7017d8f](https://github.com/PreTeXtBook/pretext/commit/7017d8fcc7005984ffc7fad81d0a37062a529a9d)

pretext/project/__init__.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,16 @@ def post_validate(self) -> None:
346346
raise ValueError(
347347
"Only one <document-id> is allowed in a PreTeXt document."
348348
)
349-
d = d_list[0]
350-
assert isinstance(d, str)
351-
# Use the correct number of `../` to undo the project's `output-dir`, so the output from the build is located in the correct directory of `published/document-id`.
352-
self.output_dir = Path(
353-
f"{'../'*len(self._project.output_dir.parents)}published/{d}"
354-
)
349+
# NB as of 2025-04-08, we are no longer setting the output directory automatically for
350+
# Runestone targets. This must be managed by the project.ptx file or by a client script.
351+
# The commented code below is how we used to do this.
352+
353+
# d = d_list[0]
354+
# assert isinstance(d, str)
355+
# # Use the correct number of `../` to undo the project's `output-dir`, so the output from the build is located in the correct directory of `published/document-id`.
356+
# self.output_dir = Path(
357+
# f"{'../'*len(self._project.output_dir.parents)}published/{d}"
358+
# )
355359
else:
356360
raise ValueError(
357361
"The <document-id> must be defined for the Runestone format."
@@ -360,12 +364,28 @@ def post_validate(self) -> None:
360364
def source_abspath(self) -> Path:
361365
return self._project.source_abspath() / self.source
362366

363-
def source_element(self) -> ET._Element:
367+
def original_source_element(self) -> ET._Element:
368+
"""
369+
Returns the root element of the original source document without running through pretext assembly.
370+
"""
364371
source_doc = ET.parse(self.source_abspath())
365372
for _ in range(25):
366373
source_doc.xinclude()
374+
print("Type of source_doc: ", type(source_doc))
367375
return source_doc.getroot()
368376

377+
def source_element(self) -> ET._Element:
378+
"""
379+
Returns the root element for the assembled source, after processing with the "version-only" assembly.
380+
"""
381+
assembled = core.assembly_internal(
382+
xml=self.source_abspath(),
383+
pub_file=self.publication_abspath().as_posix(),
384+
stringparams=self.stringparams.copy(),
385+
method="version",
386+
)
387+
return assembled.getroot()
388+
369389
def publication_abspath(self) -> Path:
370390
return self._project.publication_abspath() / self.publication
371391

@@ -446,7 +466,7 @@ def load_asset_table(self) -> pt.AssetTable:
446466

447467
def generate_asset_table(self) -> pt.AssetTable:
448468
"""
449-
Returns a hash table (dictionary) with keys the asset types present in the current target's source, each with value a hash of all the assets of that type.
469+
Returns a hash table (dictionary) with keys the asset types present in the current target's *assembled* source, each with value a hash of all the assets of that type.
450470
ex: {latex-image: <hash>, asymptote: <hash>}.
451471
452472
NOTE: This is a change in behavior starting in 2.13; previously the keys were dictionaries mapping xml:id's to hashes of individual assets.
@@ -455,7 +475,7 @@ def generate_asset_table(self) -> pt.AssetTable:
455475
ns = {"pf": "https://prefigure.org"}
456476
for asset in constants.ASSET_TO_XPATH.keys():
457477
# everything else can be updated individually.
458-
# get all the nodes for the asset attribute
478+
# get all the nodes for the asset attribute (using assembled source)
459479
source_assets = self.source_element().xpath(
460480
constants.ASSET_TO_XPATH[asset], namespaces=ns
461481
)

pretext/resources/resource_hash_table.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,17 @@
116116
"installPandoc.sh": "0dfd2cf2455efeff82293ba2b3724bc94e20620ed9f87c4cd3ee967d0dedd076",
117117
"installLatex.sh": "89fc36da1ac5bf3c79e70990d760f288b94afb71dac03f0651424efbf55663aa",
118118
"installSage.sh": "7f2b791271aaf21a0b6c742e9758d4f131b59216c261902fe43c8461143cb407"
119+
},
120+
"2.16.2": {
121+
"project.ptx": "72285565f5bcd94eedb2b91f88cea37e7af21604bcb5eb9e99c286fe1291ebb3",
122+
"codechat_config.yaml": "2fb7c39582a71b878d6d5105b5ac5dae51d5c4f4ee3354f50ba0a9dfe80ce70c",
123+
".gitignore": "c9dd727d2357c9c7d8022a688ae71f17d17aa2d70bccf978cb366b49b43feda2",
124+
"devcontainer.json": "ae45a61196b3121a5644ddf4dec62843a9178185e6f9cd8ed4d6e0bcaa6f24b9",
125+
"pretext-cli.yml": "b9bb9deb5e64ed8fa2fe472688029ae4f77731cf6a006a5c58c80c55bdb85131",
126+
"pretext-deploy.yml": "dbf18a18cf30b9301fff84890ad99334ba08f6ab0cdfa88b5d0cb233fc378c60",
127+
"installPretext.sh": "0bab8bf900bd81c83039656740082742afea4c99f577324d5498ae7e8644073d",
128+
"installPandoc.sh": "b36cfab7b0a9c0536777aea982e466186184d0f317867f598e06709bf4332b75",
129+
"installLatex.sh": "1fa5ba1cbf5d7f0d5dc71e988558281fc16e4a131b09ae9fe917b5c692e08a47",
130+
"installSage.sh": "797938aeab7a1f2e109e40a3f116f0c66fe96e49af59968833ede70a786130ff"
119131
}
120132
}

templates/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file was automatically generated with PreTeXt 2.16.1.
1+
# This file was automatically generated with PreTeXt 2.16.2.
22
# If you modify this file, PreTeXt will no longer automatically update it.
33
#
44
# Boilerplate list of files in a PreTeXt project for git to ignore

templates/codechat_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file was automatically generated with PreTeXt 2.16.1.
1+
# This file was automatically generated with PreTeXt 2.16.2.
22
# If you modify this file, PreTeXt will no longer automatically update it.
33
#
44
#############################################################

templates/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was automatically generated with PreTeXt 2.16.1.
1+
// This file was automatically generated with PreTeXt 2.16.2.
22
// If you modify this file, PreTeXt will no longer automatically update it.
33
//
44
//////////////////////////////////////////////////////////////

templates/installLatex.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env bash
22

3-
# This file was automatically generated with PreTeXt 2.16.1.
3+
# This file was automatically generated with PreTeXt 2.16.2.
44
# If you modify this file, PreTeXt will no longer automatically update it.
55

66
# We use TinyTeX (https://yihui.org/tinytex/)
77
wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh
88

9-
tlmgr install adjustbox amscdx bold-extra braket bussproofs cancel carlisle cases chessfss circuitikz colortbl enumitem extpfeil fontawesome5 fontaxes gensymb imakeidx kastrup lambda-lists listings listingsutf8 marvosym mathalpha mathtools menukeys mhchem microtype musicography newpx newtx nicematrix pdfcol pdfpages pdflscape pgfplots phaistos physics polyglossia pstricks realscripts relsize siunitx skak skaknew smartdiagram snapshot stmaryrd tcolorbox tikzfill titlesec txfonts ulem upquote was xfrac xltxtra xpatch xstring
9+
tlmgr install adjustbox amscdx bold-extra braket bussproofs cancel carlisle cases chessfss circuitikz colortbl enumitem extpfeil fontawesome5 fontaxes gensymb imakeidx jknapltx kastrup lambda-lists listings listingsutf8 marvosym mathalpha mathtools menukeys mhchem microtype musicography newpx newtx nicematrix pdfcol pdfpages pdflscape pgfplots phaistos physics polyglossia pstricks realscripts relsize siunitx skak skaknew smartdiagram snapshot stmaryrd tcolorbox tikzfill titlesec txfonts ulem upquote was xfrac xltxtra xpatch xstring
1010

1111
tlmgr path add
1212

templates/installPandoc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# This file was automatically generated with PreTeXt 2.16.1.
3+
# This file was automatically generated with PreTeXt 2.16.2.
44
# If you modify this file, PreTeXt will no longer automatically update it.
55

66
wget https://github.com/jgm/pandoc/releases/download/3.6.4/pandoc-3.6.4-1-amd64.deb -O pandoc.deb

templates/installPretext.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# This file was automatically generated with PreTeXt 2.16.1.
3+
# This file was automatically generated with PreTeXt 2.16.2.
44
# If you modify this file, PreTeXt will no longer automatically update it.
55

66
sudo apt-get update

templates/installSage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# This file was automatically generated with PreTeXt 2.16.1.
3+
# This file was automatically generated with PreTeXt 2.16.2.
44
# If you modify this file, PreTeXt will no longer automatically update it.
55

66
# Conda should already be installed in the codespace. We need to add the conda-forge channel

0 commit comments

Comments
 (0)