Skip to content

Commit

Permalink
Default manifest (#855)
Browse files Browse the repository at this point in the history
* install default manifest in ~/.ptx if missing

* create default project with global manifest.  Also fix issue with Paths not allowed in contexts

* use context to pass project object to subcommands

* implement file override

* create default pdf target for standalone builds

* improve help

* turn off test if no xelatex

* downgrade prefig version to 0.2.8
  • Loading branch information
oscarlevin authored Dec 5, 2024
1 parent 5666697 commit 3835f41
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
- name: update changelog
run: |
newline="\\n## [${{ env.VERSION }}] - $(date +'%Y-%m-%d')"
sed '/## \[UNRELEASED\]/a\'"$newline" CHANGELOG.md > CHANGELOG.md.tmp
sed '/## \[Current Release\]/a\'"$newline" CHANGELOG.md > CHANGELOG.md.tmp
mv CHANGELOG.md.tmp CHANGELOG.md
- name: commit version bump via pr
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jobs:

- name: Install apt packages (Linux with python 3.12 only)
if: runner.os == 'Linux' && matrix.python-version == '3.12'

run: |
sudo apt update
sudo apt install -y --no-install-recommends texlive texlive-science texlive-xetex ghostscript pdf2svg texlive-fonts-extra sagemath
- name: Install poetry ${{ matrix.poetry-version }}
run: |
python -m ensurepip
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ All notable changes to the PreTeXt-CLI will be documented in this file (admitted
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Instructions: Add a subsection under `[UNRELEASED]` for additions, fixes, changes, and removals of features accompanying each PR. When a release is made, the github action will automatically add the next version number above the unreleased changes with the date of release.
Instructions: Add a subsection under `[Current Release]` for additions, fixes, changes, and removals of features accompanying each PR. When a release is made, the github action will automatically add the next version number above the unreleased changes with the date of release.

## [UNRELEASED]
## [Current Release]

### Added

- Support for building stand-alone documents without adding the source to the manifest.
- Support for upcoming html themes, including `pretext build --theme` to refresh theme without rebuilding entire project.

## [2.9.2] - 2024-11-22

Expand Down
74 changes: 52 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pretext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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

CORE_COMMIT = "e84b24bdb7acc46d3814618bd9b16ff5bd081ae2"
CORE_COMMIT = "dafa002301ab1be5c1e092e7ba60837464253347"


def activate() -> None:
Expand Down
76 changes: 68 additions & 8 deletions pretext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def main(ctx: click.Context, targets: bool) -> None:
print(target)
return
# create file handler which logs even debug messages
# TODO: this will likely be moved out of this if to allow manifest-free builds
logdir = pp / "logs"
logdir.mkdir(exist_ok=True)
logfile = logdir / f"{datetime.datetime.now().strftime('%Y%m%d-%H%M%S')}.log"
Expand Down Expand Up @@ -180,7 +181,14 @@ def main(ctx: click.Context, targets: bool) -> None:
)
else:
log.info(f"PreTeXt-CLI version: {VERSION}\n")
log.info("No existing PreTeXt project found.")
utils.ensure_default_project_manifest()
default_project_path = resources.resource_base_path().parent / "project.ptx"
project = Project.parse(default_project_path, global_manifest=True)
log.warning(
"No project.ptx manifest found in current workspace. Using global configuration specified in '~/.ptx/project.ptx'."
)
# Add project to context so it can be used in subcommands
ctx.obj = {"project": project}
if ctx.invoked_subcommand is None:
log.info("Run `pretext --help` for help.")

Expand Down Expand Up @@ -420,19 +428,29 @@ def init(refresh: bool, files: List[str]) -> None:
is_flag=True,
help="Build all targets configured to be deployed.",
)
@click.option(
"-i",
"--input",
"source_file",
type=click.Path(),
help="Override the source file from the manifest by providing a path to the input.",
)
@click.pass_context
@nice_errors
def build(
target_name: str,
ctx: click.Context,
target_name: Optional[str],
clean: bool,
generate: bool,
no_generate: bool,
theme: bool,
xmlid: Optional[str],
no_knowls: bool,
deploys: bool,
source_file: Optional[str],
) -> None:
"""
Build [TARGET] according to settings specified by project.ptx.
Build [TARGET], which can be the name of a target specified by project.ptx or the name of a pretext file.
If using elements that require separate generation of assets (e.g., webwork, latex-image, etc.) then these will be generated automatically if their source has changed since the last build. You can suppress this with the `--no-generate` flag, or force a regeneration with the `--generate` flag.
Expand All @@ -445,17 +463,48 @@ def build(
# Set up project and target based on command line arguments and project.ptx

# Supply help if not in project subfolder
if utils.cannot_find_project(task="build"):
return
# NOTE: we no longer need the following since we have added support for building without a manifest.
# if utils.cannot_find_project(task="build"):
# return
# Create a new project, apply overlay, and get target. Note, the CLI always finds changes to the root folder of the project, so we don't need to specify a path to the project.ptx file.
project = Project.parse()
# Use the project discovered in the main command.
project = ctx.obj["project"]

# Check to see whether target_name is a path to a file:
if target_name and Path(target_name).is_file():
log.debug(
f"target is a source file {Path(target_name).resolve()}. Using this to override input."
)
log.warning(
"Building standalone documents is an experimental feature and the interface may change."
)
# set the source_file to that target_name and reset target_name to None
source_file = target_name
target_name = None

# Now create the target if the target_name is not missing.
try:
# deploys flag asks to build multiple targets: all that have deploy set.
if deploys and len(project.deploy_targets()) > 0:
targets = project.deploy_targets()
elif target_name is None and source_file is not None:
# We are in the case where we are building a standalone document, so we build a default target if there are no standalone targets or find the first target with standalone="yes".
if len(project.standalone_targets()) > 0:
targets = [project.standalone_targets()[0]]
else:
target = project.new_target(
name="standalone",
format="pdf",
standalone="yes",
output_dir=Path(source_file).resolve().parent,
)
targets = [target]
log.debug(f"Building standalone document with target {target.name}")
log.debug(target)
else:
targets = [project.get_target(name=target_name)]
except AssertionError as e:
log.warning("Assertion error in getting target.")
utils.show_target_hints(target_name, project, task="build")
log.critical("Exiting without completing build.")
log.debug(e, exc_info=True)
Expand All @@ -473,6 +522,13 @@ def build(
# Theme flag means to only build the theme, so we...
return

# If input/source_file is given, override the source file for the target
if source_file is not None:
for t in targets:
t.source = Path(source_file).resolve()
log.warning(f"Overriding source file for target with: {t.source}")
log.debug(t)

# Call generate if flag is set
if generate and not no_generate:
try:
Expand Down Expand Up @@ -557,8 +613,10 @@ def build(
default=False,
help="Used to revert to non-pymupdf (legacy) method for generating svg and png.",
)
@click.pass_context
@nice_errors
def generate(
ctx: click.Context,
assets: List[str],
target_name: Optional[str],
all_formats: bool,
Expand All @@ -584,7 +642,7 @@ def generate(
if utils.cannot_find_project(task="generate assets for"):
return

project = Project.parse()
project = ctx.obj["project"]
# Now create the target if the target_name is not missing.
try:
target = project.get_target(name=target_name)
Expand Down Expand Up @@ -700,8 +758,10 @@ def generate(
default=False,
help="Use the standard python server, even if in a codespace (for debugging)",
)
@click.pass_context
@nice_errors
def view(
ctx: click.Context,
target_name: str,
access: Literal["public", "private"],
port: int,
Expand Down Expand Up @@ -869,7 +929,7 @@ def deploy(
"""
if utils.cannot_find_project(task="deploy"):
return
project = Project.parse()
project = ctx.obj["project"]
project.stage_deployment()
if stage_only:
return
Expand Down
Loading

0 comments on commit 3835f41

Please sign in to comment.