-
Notifications
You must be signed in to change notification settings - Fork 3
Use Typst's JSON dep file (with outputs) #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tovrstra
wants to merge
5
commits into
reproducible-reporting:main
Choose a base branch
from
tovrstra:json-deps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
82d0b53
Use Typst's JSON dep file (with outputs)
tovrstra f1c0498
Add example, few cleanups
tovrstra 2fdf4dc
Fix for current development version of Typst (post 0.14)
tovrstra 073c1be
Merge branch 'main' into json-deps
tovrstra 9559604
Merge branch 'main' into json-deps
tovrstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,13 +22,14 @@ | |
| This wrapper extracts relevant information from a typst build | ||
| to inform StepUp of input files used or needed. | ||
|
|
||
| This is tested with Typst 0.12. | ||
| A current limitation of typst is that it will fail after the first missing file it requires, | ||
| This is tested with Typst 0.14. | ||
| A limitation of typst is that it will fail after the first missing file it requires, | ||
| making it inefficient to plan ahead and build all missing required inputs early. | ||
| """ | ||
|
|
||
| import argparse | ||
| import contextlib | ||
| import json | ||
| import shlex | ||
| import sys | ||
|
|
||
|
|
@@ -49,8 +50,8 @@ def main(argv: list[str] | None = None, work_thread: WorkThread | None = None): | |
|
|
||
| if not args.path_typ.endswith(".typ"): | ||
| raise ValueError("The Typst source must have extension .typ") | ||
| if not (args.path_out is None or args.path_out.suffix in (".pdf", ".png", ".svg")): | ||
| raise ValueError("The Typst output must be a PDF, PNG, or SVG file.") | ||
| if not (args.path_out is None or args.path_out.suffix in (".pdf", ".png", ".svg", ".html")): | ||
sourcery-ai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| raise ValueError("The Typst output must be a PDF, PNG, SVG, or HTML file.") | ||
|
|
||
| # Get Typst executable and prepare some arguments that | ||
| if args.typst is None: | ||
|
|
@@ -67,6 +68,8 @@ def main(argv: list[str] | None = None, work_thread: WorkThread | None = None): | |
| if resolution is None: | ||
| resolution = int(getenv("REPREP_TYPST_RESOLUTION", "144")) | ||
| typargs.append(f"--ppi={resolution}") | ||
| elif args.path_out.suffix == ".html": | ||
| typargs.append("--features=html") | ||
| for keyval in args.sysinp: | ||
| typargs.append("--input") | ||
| typargs.append(keyval) | ||
|
|
@@ -77,36 +80,29 @@ def main(argv: list[str] | None = None, work_thread: WorkThread | None = None): | |
| with contextlib.ExitStack() as stack: | ||
| if args.keep_deps: | ||
| # Remove any existing make-deps output from a previous run. | ||
| path_dep = Path(args.path_typ[:-4] + ".dep") | ||
| path_dep = Path(args.path_typ[:-4] + ".dep.json") | ||
| path_dep.remove_p() | ||
| else: | ||
| # Use a temporary file for the make-deps output. | ||
| path_dep = stack.enter_context(TempDir()) / "typst.dep" | ||
| typargs.extend(["--make-deps", path_dep]) | ||
| path_dep = stack.enter_context(TempDir()) / "typst.dep.json" | ||
| typargs.extend(["--deps", path_dep, "--deps-format", "json"]) | ||
|
|
||
| # Run typst compile | ||
| returncode, stdout, stderr = work_thread.runsh(shlex.join(typargs)) | ||
| print(stdout) | ||
| # Get existing input files from the dependency file and amend. | ||
| # Note that the deps file does not escape colons in paths, | ||
| # so the code below assumes one never uses colons in paths. | ||
| inp_paths = [] | ||
| # Assume there is a single output file, which is the one specified. | ||
| # This is not correct when there are multiple outputs, e.g. as with SVG and PNG outputs. | ||
| # Get required input files from the dependency file. | ||
| if path_dep.is_file(): | ||
| out_paths = [] | ||
| with open(path_dep) as fh: | ||
| dep_out, dep_inp = fh.read().split(":", 1) | ||
| out_paths.extend(shlex.split(dep_out)) | ||
| inp_paths.extend(shlex.split(dep_inp)) | ||
| depinfo = json.load(fh) | ||
| inp_paths = depinfo["inputs"] | ||
| out_paths = depinfo["outputs"] | ||
|
||
| else: | ||
| print(f"Dependency file not created: {path_dep}.", file=sys.stderr) | ||
| out_paths = [args.path_out] | ||
| out_paths = [] | ||
| inp_paths = [] | ||
|
|
||
| # Look for missing input files in the standard error stream and amend them. | ||
| if returncode != 0: | ||
| lead = "error: file not found (searched at " | ||
| inp_paths.extend( | ||
| line[len(lead) : -1] for line in stderr.splitlines() if line.startswith(lead) | ||
| ) | ||
| sys.stderr.write(stderr) | ||
| inp_paths = filter_dependencies(inp_paths) | ||
| amend(inp=inp_paths) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| .stepup | ||
| current* | ||
| document.pdf | ||
| document.dep | ||
| document.dep.json | ||
| image.jpg | ||
| document1.pdf | ||
| reproducibility_inventory.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| .stepup | ||
| current* | ||
| document.pdf | ||
| document.dep.json | ||
| data.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .stepup | ||
| current* | ||
| lorem.html | ||
| lorem.dep.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| A simple example of compiling a typst document to HTML. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.