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
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ cython_debug/
# Hide PyPI token
.pypitoken

#pretext-core
pretext/core/pretext.py
pretext/core/braille_format.py
pretext/core/common.py
pretext/core/stack.py
pretext/core/webwork.py
#pretext-core: almost everything...
pretext/core/*
# ... but not the __init__.py file
!pretext/core/__init__.py
tests/examples/core
#zipped resources
#zipped resourcescd
pretext/resources/*.zip
#xml resources (rs_file)
pretext/resources/*.xml
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ Instructions: Add a subsection under `[Unreleased]` for additions, fixes, change

## [Unreleased]

### Fixed

- SCORM with assessment tracking now works with Blackboard.

### Added

- Improvements to the Braille output format.
- Improvements to the EPUB output format.
- Improvements to the Jupyter notebook output format.
- Upgrade to latest release of revealjs for slideshow targets. Includes support of single-file, offline slideshows and other slideshow improvements.
- Improvements to Fill-In-The-Blank questions.
- Asymptote support for offscreen rendering of images.
- Hypothesis.is support via publication file setting.


## [2.44.0] - 2026-07-08

Includes updates to core through commit: [07c8b5c](https://github.com/PreTeXtBook/pretext/commit/07c8b5c9a9a55e95ec27073e88bd5c9c61b9c161)
Expand Down
54 changes: 47 additions & 7 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
# Using PreTeXt as a library
# Using pretext-cli as a Python library

The PreTeXt-CLI includes `Project` and `Target` classes which can be used when this package is imported as a library.
The `pretext-cli` package can be used directly from Python, without spawning
CLI subprocesses.

More details are coming soon.
The two main entry points are:

- `Project.parse(...)`: load an existing `project.ptx` manifest.
- `Project(...)` + `new_target(...)`: build projects programmatically when no
manifest exists.

## Quick start

```python
from pathlib import Path
from pretext import project as pr

# Case 1: You already have project.ptx
project = pr.Project.parse(Path("."))
project.get_target("web").build()

# Case 2: No project.ptx (for example, core/examples/epub)
project = pr.Project(ptx_version="2", source=Path(""), publication=Path(""))
target = project.new_target(
"ebook",
"epub",
source=Path("epub-sampler.xml"),
publication=Path("publication.xml"),
)
target.build()
```

## Why set `source` and `publication` to `Path("")`?

`Project` prepends its own base paths to each target's `source` and
`publication` paths.

- Default `Project.source` is `source/`.
- Default `Project.publication` is `publication/`.

When your files live directly in the project root (as in the core EPUB
example), setting both to `Path("")` makes target paths resolve from that root.

## Logging

This package uses python's logging library and implements a logger with name `"ptxlogger"`. To get the same messages as the CLI gives (with default level of `INFO`), you can include the following.
To mirror CLI-style log output in library usage:

```python
import logging
Expand All @@ -17,12 +54,15 @@ logger.add_log_stream_handler()
log.setLevel(logging.INFO)
```

The `logger.add_log_stream_handler()` function simply creates a stream-handler that outputs to stdout. You could set up `log` however you like using the options provided by the `logging` library. If you would like to get spit out the logs to a file as the CLI does, you could include the line
To also log to files:

```python
logger.add_log_file_handler(path_to_log_directory)
```

## Report pretext version
## Version reporting

If you want the running CLI version in your app logs, either:

If you want to include the current running version of PreTeXt in your app, you can call `utils.report_version` to get a info-level log report of the version, or import `VERSION` from the base of the project and use that in your own log message.
- call `utils.report_version()` for the built-in message, or
- import `VERSION` and log it yourself.
2 changes: 1 addition & 1 deletion pretext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

VERSION = get_version("pretext", Path(__file__).parent.parent)

CORE_COMMIT = "c605c6f4f7fc5e3afc377372a952dd40c902dc2b"
CORE_COMMIT = "eec74773ac46acb74bb423b7b216d64b2416ee27"


def activate() -> None:
Expand Down
13 changes: 9 additions & 4 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,17 @@ def test_latex_build(tmp_path: Path) -> None:
def test_epub_build(tmp_path: Path) -> None:
"""An epub-format target builds a single .epub file."""
prj_path = tmp_path / "simple"
shutil.copytree(EXAMPLES_DIR / "projects" / "project_refactor" / "simple", prj_path)
shutil.copytree(EXAMPLES_DIR / "core" / "examples" / "epub", prj_path)
with utils.working_directory(prj_path):
project = pr.Project.parse()
target = project.new_target("ebook", "epub")
project = pr.Project(ptx_version="2", source=Path(""), publication=Path(""))
target = project.new_target(
"ebook",
"epub",
source=Path("epub-sampler.xml"),
publication=Path("publication.xml"),
)
target.build()
assert (prj_path / "output" / "ebook" / "main.epub").exists()
assert (prj_path / "output" / "ebook" / "epub-sampler.epub").exists()


@pytest.mark.skipif(
Expand Down