calkit-python 0.50.3__py3-none-any.whl → 0.50.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- calkit/agent_skills/connect-overleaf-project/SKILL.md +165 -0
- calkit/cli/check.py +7 -1
- calkit/cli/core.py +32 -0
- calkit/cli/export.py +139 -0
- calkit/cli/latex.py +49 -4
- calkit/cli/main/core.py +159 -6
- calkit/cli/scheduler.py +51 -5
- calkit/config.py +266 -57
- calkit/core.py +23 -4
- calkit/docker.py +2 -0
- calkit/export.py +169 -0
- calkit/latex.py +158 -36
- calkit/models/pipeline.py +220 -16
- calkit/overleaf.py +22 -0
- calkit/pipeline.py +54 -14
- calkit/provenance.py +278 -6
- calkit/reproducibility.py +63 -1
- calkit/tests/cli/main/test_core.py +184 -0
- calkit/tests/cli/test_core.py +33 -0
- calkit/tests/cli/test_export.py +152 -0
- calkit/tests/cli/test_latex.py +63 -0
- calkit/tests/cli/test_scheduler.py +73 -0
- calkit/tests/models/test_pipeline.py +76 -0
- calkit/tests/test_config.py +238 -48
- calkit/tests/test_core.py +24 -0
- calkit/tests/test_docker.py +6 -0
- calkit/tests/test_export.py +85 -0
- calkit/tests/test_latex.py +60 -0
- calkit/tests/test_overleaf.py +16 -0
- calkit/tests/test_pipeline.py +177 -4
- calkit/tests/test_provenance.py +186 -0
- calkit/tests/test_reproducibility.py +88 -4
- calkit/tests/test_upgrade.py +9 -1
- calkit/tests/test_windows.py +56 -0
- calkit/upgrade.py +7 -0
- calkit/windows.py +59 -0
- {calkit_python-0.50.3.dist-info → calkit_python-0.50.5.dist-info}/METADATA +56 -1
- {calkit_python-0.50.3.dist-info → calkit_python-0.50.5.dist-info}/RECORD +54 -47
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/etc/jupyter/jupyter_server_config.d/calkit.json +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/package.json +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/schemas/calkit/package.json.orig +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/schemas/calkit/plugin.json +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/506.c34b070098184e33.js +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/57d13a7399cec3c5.png +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/616.528427eb54a4a0c0.js +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/740.6bf87276e9e5788a.js +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/899.f9b9f9bf705a6493.js +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/935.46ecc6bf99aa593a.js +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/remoteEntry.109a3a8379365e59.js +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/style.js +0 -0
- {calkit_python-0.50.3.data → calkit_python-0.50.5.data}/data/share/jupyter/labextensions/calkit/static/third-party-licenses.json +0 -0
- {calkit_python-0.50.3.dist-info → calkit_python-0.50.5.dist-info}/WHEEL +0 -0
- {calkit_python-0.50.3.dist-info → calkit_python-0.50.5.dist-info}/entry_points.txt +0 -0
- {calkit_python-0.50.3.dist-info → calkit_python-0.50.5.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: connect-overleaf-project
|
|
3
|
+
description: Connect an Overleaf project, e.g., a paper, thesis, or poster,
|
|
4
|
+
to a Calkit project and the scripts and data behind it, so its figures and
|
|
5
|
+
numbers come from a pipeline. Use when the user invokes
|
|
6
|
+
`/calkit:connect-overleaf-project`, asks to connect an Overleaf project
|
|
7
|
+
(often one open in their browser) to Calkit, or asks to make an Overleaf
|
|
8
|
+
document reproducible. Not for only signing in to Overleaf.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Connect an Overleaf project to its analysis
|
|
12
|
+
|
|
13
|
+
The person writes in Overleaf, e.g., a paper, thesis, or poster, and their
|
|
14
|
+
scripts and data are somewhere on their machine or a shared drive. The job is
|
|
15
|
+
to connect the two: a Calkit project with the document in it, stages that make
|
|
16
|
+
what the document shows, and the document reading those outputs instead of
|
|
17
|
+
pasted copies. The writing stays theirs. Change only how the document includes
|
|
18
|
+
figures and numbers.
|
|
19
|
+
|
|
20
|
+
Work in two places:
|
|
21
|
+
|
|
22
|
+
- **The browser**, through the person's own Overleaf session, for what only
|
|
23
|
+
it can do: connecting the document, and checking the result in the editor.
|
|
24
|
+
This needs a browser tool, e.g., Claude in Chrome.
|
|
25
|
+
- **A local clone**, through the CLI, for everything else.
|
|
26
|
+
|
|
27
|
+
Never type passwords or tokens. If something asks the person to sign in,
|
|
28
|
+
stop and ask them to do it.
|
|
29
|
+
|
|
30
|
+
## 1. Connect the document
|
|
31
|
+
|
|
32
|
+
In the Overleaf tab, open the Calkit panel from the launcher at the bottom
|
|
33
|
+
right, which reads "Calkit: not linked" when the document isn't connected. It's
|
|
34
|
+
in a shadow root, so it may not show in the page's accessibility tree; take a
|
|
35
|
+
screenshot to find it.
|
|
36
|
+
|
|
37
|
+
Click "Make this paper reproducible", check the project name, privacy, and
|
|
38
|
+
folder, and create the project. Name the folder for what the document is,
|
|
39
|
+
e.g., `paper` only for a paper, and `thesis` for a thesis. A project with
|
|
40
|
+
several publications may keep them under `pubs`, e.g., `pubs/paper-1` and
|
|
41
|
+
`pubs/thesis`, and presentations under `presentations`. The panel then
|
|
42
|
+
shows the project and "in sync". If the document should go in a project the
|
|
43
|
+
person already has, use "Use a project I already have" instead.
|
|
44
|
+
|
|
45
|
+
Without the browser extension, `calkit overleaf import URL SUBFOLDER` adds the
|
|
46
|
+
document to an existing local project, using Overleaf's Git access.
|
|
47
|
+
|
|
48
|
+
## 2. Clone it
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
calkit clone OWNER/NAME ~/calkit/NAME
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`~/calkit/` is the usual place, unless the person keeps projects elsewhere,
|
|
55
|
+
e.g., `~/research` or `~/dev`.
|
|
56
|
+
|
|
57
|
+
## 3. Find what the document shows and where it came from
|
|
58
|
+
|
|
59
|
+
Read the document's `.tex` files and list:
|
|
60
|
+
|
|
61
|
+
- figures included from files in the document's folder, e.g., a pasted
|
|
62
|
+
`\includegraphics{drag.png}`
|
|
63
|
+
- numbers typed into the text that are results, e.g., a mean or a fit
|
|
64
|
+
parameter
|
|
65
|
+
- tables typed or pasted in
|
|
66
|
+
|
|
67
|
+
Then find the scripts and data that made them. Ask the person where they
|
|
68
|
+
keep their analysis before searching their files. Match a figure to its
|
|
69
|
+
script by its file name, `savefig` calls, axis labels, and data columns.
|
|
70
|
+
Don't move or delete anything in their folders; copy what the project needs.
|
|
71
|
+
|
|
72
|
+
## 4. Bring in the scripts and data
|
|
73
|
+
|
|
74
|
+
Copy scripts into `scripts/` and data into `data/`, then change paths in the
|
|
75
|
+
scripts to be relative to the project root. Where a number in the text comes
|
|
76
|
+
from a script, have the script write it to a results file, e.g.,
|
|
77
|
+
`results/drag.json`, rather than only printing it.
|
|
78
|
+
|
|
79
|
+
Add each script as a stage, previewing first:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
calkit xr scripts/plot_drag.py --dry-run
|
|
83
|
+
calkit xr scripts/plot_drag.py
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Check the detected inputs, outputs, and environment in `calkit.yaml`. Large
|
|
87
|
+
data belongs in DVC; see the conventions skill.
|
|
88
|
+
|
|
89
|
+
## 5. Have the document read the outputs
|
|
90
|
+
|
|
91
|
+
Load the package and swap each pasted figure and typed result for the
|
|
92
|
+
output that makes it:
|
|
93
|
+
|
|
94
|
+
```latex
|
|
95
|
+
\usepackage{calkit}
|
|
96
|
+
...
|
|
97
|
+
The mean drag coefficient was \ckvalue{results/drag.json}{mean_cd}.
|
|
98
|
+
\ckfigure[width=0.6\linewidth]{figures/drag.png}
|
|
99
|
+
\cktable{results/summary.tex}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Remove the pasted copies the document no longer includes, and drop them from
|
|
103
|
+
the LaTeX stage's `inputs`.
|
|
104
|
+
|
|
105
|
+
## 6. Say where everything starts
|
|
106
|
+
|
|
107
|
+
Data at the start of the chain needs an origin: `created_by` for data the
|
|
108
|
+
person measured or collected, or `imported_from` with a public URL or DOI
|
|
109
|
+
for data from elsewhere. A file on their laptop or a private drive isn't
|
|
110
|
+
somewhere it can be imported from. Ask the person which it is; don't guess.
|
|
111
|
+
|
|
112
|
+
```yaml
|
|
113
|
+
datasets:
|
|
114
|
+
- path: data/drag_data_FINAL.csv
|
|
115
|
+
title: Drag measurements
|
|
116
|
+
created_by:
|
|
117
|
+
- name: Their Name
|
|
118
|
+
email: them@example.edu
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
A PNG or PDF can't be created by a person, since an app or script exports
|
|
122
|
+
it. If no script makes it, ask the person what they made it in, copy that
|
|
123
|
+
file into the project, e.g., `figures/src/setup.svg`, and add a stage that
|
|
124
|
+
exports it. Inkscape SVGs and GIMP files are exported as the pipeline runs;
|
|
125
|
+
anything else is a manual step, which asks the person to export it again
|
|
126
|
+
when its file changes:
|
|
127
|
+
|
|
128
|
+
```yaml
|
|
129
|
+
pipeline:
|
|
130
|
+
stages:
|
|
131
|
+
export-setup:
|
|
132
|
+
kind: inkscape-export # or gimp-export
|
|
133
|
+
source_path: figures/src/setup.svg
|
|
134
|
+
outputs:
|
|
135
|
+
- paper/setup.png
|
|
136
|
+
export-diagram:
|
|
137
|
+
kind: manual-step
|
|
138
|
+
message: In PowerPoint, export paper/diagram.png from slide 2
|
|
139
|
+
open:
|
|
140
|
+
app: PowerPoint
|
|
141
|
+
path: figures/src/diagram.pptx
|
|
142
|
+
inputs:
|
|
143
|
+
- figures/src/diagram.pptx
|
|
144
|
+
outputs:
|
|
145
|
+
- paper/diagram.png
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 7. Run, save, and sync
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
calkit run --save --overleaf -m "Make the drag figure from its script"
|
|
152
|
+
calkit check repro
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Then, in the Overleaf tab:
|
|
156
|
+
|
|
157
|
+
1. Dismiss Overleaf's "Document Updated Externally" notice, if shown.
|
|
158
|
+
2. Reload the page, since the extension remembers what it last looked up.
|
|
159
|
+
3. Recompile, and check that no "Origin not defined" marks remain in the
|
|
160
|
+
editor or on the PDF.
|
|
161
|
+
4. Hover a `\ckvalue` or `\ckfigure` to confirm it traces back to its stage
|
|
162
|
+
and data.
|
|
163
|
+
|
|
164
|
+
Tell the person what you connected, what you asked them about, and anything
|
|
165
|
+
left without an origin.
|
calkit/cli/check.py
CHANGED
|
@@ -16,7 +16,7 @@ import dotenv
|
|
|
16
16
|
import typer
|
|
17
17
|
|
|
18
18
|
import calkit
|
|
19
|
-
from calkit.cli import AliasGroup, raise_error, warn
|
|
19
|
+
from calkit.cli import AliasGroup, raise_error, warn, warn_app_control
|
|
20
20
|
from calkit.core import get_md5
|
|
21
21
|
|
|
22
22
|
|
|
@@ -605,6 +605,7 @@ def check_environment(
|
|
|
605
605
|
try:
|
|
606
606
|
subprocess.check_call(cmd)
|
|
607
607
|
except subprocess.CalledProcessError:
|
|
608
|
+
warn_app_control(maybe=True)
|
|
608
609
|
raise_error("Failed to check pixi environment")
|
|
609
610
|
elif env["kind"] == "uv":
|
|
610
611
|
cmd = ["uv", "sync"]
|
|
@@ -616,6 +617,7 @@ def check_environment(
|
|
|
616
617
|
try:
|
|
617
618
|
subprocess.check_call(cmd)
|
|
618
619
|
except subprocess.CalledProcessError:
|
|
620
|
+
warn_app_control(maybe=True)
|
|
619
621
|
raise_error("Failed to check uv environment")
|
|
620
622
|
elif (kind := env["kind"]) in ["uv-venv", "venv"]:
|
|
621
623
|
if "path" not in env:
|
|
@@ -1835,6 +1837,7 @@ def check_conda_env(
|
|
|
1835
1837
|
verbose=not quiet,
|
|
1836
1838
|
)
|
|
1837
1839
|
except Exception as e:
|
|
1840
|
+
warn_app_control(output=str(e), maybe=True)
|
|
1838
1841
|
raise_error(f"Failed to check conda environment: {e}")
|
|
1839
1842
|
|
|
1840
1843
|
|
|
@@ -1917,6 +1920,7 @@ def check_venv(
|
|
|
1917
1920
|
try:
|
|
1918
1921
|
subprocess.check_call(create_cmd + [prefix], cwd=wdir)
|
|
1919
1922
|
except subprocess.CalledProcessError:
|
|
1923
|
+
warn_app_control(maybe=True)
|
|
1920
1924
|
raise_error(f"Failed to create {kind} at {prefix}")
|
|
1921
1925
|
# Put a gitignore file in the env dir if one doesn't exist
|
|
1922
1926
|
gitignore_fpath = os.path.join(prefix_full_path, ".gitignore")
|
|
@@ -2117,6 +2121,7 @@ def check_venv(
|
|
|
2117
2121
|
pip_install_and_freeze(dep_file_txt)
|
|
2118
2122
|
except (subprocess.CalledProcessError, OSError):
|
|
2119
2123
|
if lock_is_current:
|
|
2124
|
+
warn_app_control(maybe=True)
|
|
2120
2125
|
raise_error(
|
|
2121
2126
|
f"Failed to create {kind} at {prefix} from its lock file "
|
|
2122
2127
|
f"({lock_fpath}), which matches the spec ({path}). "
|
|
@@ -2132,6 +2137,7 @@ def check_venv(
|
|
|
2132
2137
|
try:
|
|
2133
2138
|
pip_install_and_freeze(f"-r {path}")
|
|
2134
2139
|
except subprocess.CalledProcessError:
|
|
2140
|
+
warn_app_control(maybe=True)
|
|
2135
2141
|
raise_error(f"Failed to check {kind} from input file {path}")
|
|
2136
2142
|
|
|
2137
2143
|
|
calkit/cli/core.py
CHANGED
|
@@ -184,3 +184,35 @@ def warn(txt: str, prefix: str = "Warning: ", err: bool = False):
|
|
|
184
184
|
text = typer.style(prefix + encode_safe(str(txt), err=err), fg="yellow")
|
|
185
185
|
if not _echo_above_spinner(text, err=err):
|
|
186
186
|
typer.echo(text, err=err)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def warn_app_control(
|
|
190
|
+
output: str = "", returncode: int | None = None, maybe: bool = False
|
|
191
|
+
) -> None:
|
|
192
|
+
"""Explain a failure Windows App Control may have caused.
|
|
193
|
+
|
|
194
|
+
Smart App Control blocks unsigned executables and DLLs it doesn't trust,
|
|
195
|
+
which environments are full of, and the failure reads as unrelated.
|
|
196
|
+
Pass ``maybe`` for a failure whose output went straight to the terminal,
|
|
197
|
+
to warn whenever Smart App Control is on.
|
|
198
|
+
"""
|
|
199
|
+
from calkit.windows import (
|
|
200
|
+
SMART_APP_CONTROL_DOCS_URL,
|
|
201
|
+
app_control_blocked,
|
|
202
|
+
smart_app_control_on,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if app_control_blocked(output=output, returncode=returncode):
|
|
206
|
+
warn(
|
|
207
|
+
"Windows blocked a file from running, which Smart App Control "
|
|
208
|
+
"does to unsigned files it doesn't trust; see "
|
|
209
|
+
f"{SMART_APP_CONTROL_DOCS_URL}",
|
|
210
|
+
err=True,
|
|
211
|
+
)
|
|
212
|
+
elif maybe and smart_app_control_on():
|
|
213
|
+
warn(
|
|
214
|
+
"Smart App Control is on, which can block files in environments "
|
|
215
|
+
"from running; if the output above says a file was blocked, see "
|
|
216
|
+
f"{SMART_APP_CONTROL_DOCS_URL}",
|
|
217
|
+
err=True,
|
|
218
|
+
)
|
calkit/cli/export.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""CLI for exporting data and artifacts from various apps, e.g., a PNG
|
|
2
|
+
from an Inkscape SVG.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
from typing_extensions import Annotated
|
|
12
|
+
|
|
13
|
+
from calkit.cli import raise_error
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from calkit.export import Exporter
|
|
17
|
+
|
|
18
|
+
export_app = typer.Typer(no_args_is_help=True)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _prepare(exporter: Exporter, source: str, output: str) -> str:
|
|
22
|
+
"""Get ready to export, returning the executable to run."""
|
|
23
|
+
exporter.check(source, output)
|
|
24
|
+
if not os.path.isfile(source):
|
|
25
|
+
raise ValueError(f"'{source}' doesn't exist")
|
|
26
|
+
os.makedirs(os.path.dirname(output) or ".", exist_ok=True)
|
|
27
|
+
# What was there is from before, so it can't pass for a new export
|
|
28
|
+
if os.path.exists(output):
|
|
29
|
+
os.remove(output)
|
|
30
|
+
exe = exporter.find_executable()
|
|
31
|
+
if exe is None:
|
|
32
|
+
raise ValueError(
|
|
33
|
+
f"Exporting '{source}' needs {exporter.app} installed"
|
|
34
|
+
)
|
|
35
|
+
return exe
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def inkscape(source: str, output: str, dpi: int | None = None) -> None:
|
|
39
|
+
"""Export a drawing to the format ``output``'s extension names,
|
|
40
|
+
raising ``ValueError`` if it can't be.
|
|
41
|
+
"""
|
|
42
|
+
import subprocess
|
|
43
|
+
|
|
44
|
+
from calkit.export import INKSCAPE
|
|
45
|
+
|
|
46
|
+
exe = _prepare(INKSCAPE, source, output)
|
|
47
|
+
cmd = [exe, source, f"--export-filename={output}"]
|
|
48
|
+
if dpi is not None:
|
|
49
|
+
cmd.append(f"--export-dpi={dpi}")
|
|
50
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
51
|
+
if not os.path.isfile(output):
|
|
52
|
+
detail = (result.stderr or result.stdout or "").strip()
|
|
53
|
+
raise ValueError(
|
|
54
|
+
f"Inkscape didn't export '{output}' from '{source}'"
|
|
55
|
+
+ (f": {detail.splitlines()[-1]}" if detail else "")
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def gimp(source: str, output: str) -> None:
|
|
60
|
+
"""Flatten a GIMP document into the format ``output``'s extension
|
|
61
|
+
names, raising ``ValueError`` if it can't be.
|
|
62
|
+
|
|
63
|
+
Runs GIMP 3's batch dialect, then GIMP 2's, which differ in their file
|
|
64
|
+
procedures. Neither reports a failed script in its exit code, so the
|
|
65
|
+
written file is what says it worked.
|
|
66
|
+
"""
|
|
67
|
+
import subprocess
|
|
68
|
+
|
|
69
|
+
from calkit.export import GIMP
|
|
70
|
+
|
|
71
|
+
exe = _prepare(GIMP, source, output)
|
|
72
|
+
src = os.path.abspath(source).replace("\\", "\\\\").replace('"', '\\"')
|
|
73
|
+
dst = os.path.abspath(output).replace("\\", "\\\\").replace('"', '\\"')
|
|
74
|
+
v3 = (
|
|
75
|
+
f'(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "{src}"))))'
|
|
76
|
+
" (gimp-image-flatten image)"
|
|
77
|
+
f' (gimp-file-save RUN-NONINTERACTIVE image "{dst}" "{dst}")'
|
|
78
|
+
" (gimp-image-delete image)"
|
|
79
|
+
" (gimp-quit 0))"
|
|
80
|
+
)
|
|
81
|
+
v2 = (
|
|
82
|
+
"(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "
|
|
83
|
+
f'"{src}" "{src}")))'
|
|
84
|
+
" (drawable (car (gimp-image-flatten image))))"
|
|
85
|
+
f' (gimp-file-save RUN-NONINTERACTIVE image drawable "{dst}" '
|
|
86
|
+
f'"{dst}")'
|
|
87
|
+
" (gimp-image-delete image)"
|
|
88
|
+
" (gimp-quit 0))"
|
|
89
|
+
)
|
|
90
|
+
detail = ""
|
|
91
|
+
for cmd in [
|
|
92
|
+
[exe, "-i", "--batch-interpreter=plug-in-script-fu-eval", "-b", v3],
|
|
93
|
+
[exe, "-i", "-b", v2],
|
|
94
|
+
]:
|
|
95
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
96
|
+
if os.path.isfile(output):
|
|
97
|
+
return
|
|
98
|
+
detail = (result.stderr or result.stdout or "").strip()
|
|
99
|
+
raise ValueError(
|
|
100
|
+
f"GIMP didn't export '{output}' from '{source}'"
|
|
101
|
+
+ (f": {detail.splitlines()[-1]}" if detail else "")
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@export_app.command(name="inkscape", help="Export a figure from an SVG.")
|
|
106
|
+
def export_inkscape(
|
|
107
|
+
source: Annotated[str, typer.Argument(help="SVG to export from.")],
|
|
108
|
+
output: Annotated[
|
|
109
|
+
str,
|
|
110
|
+
typer.Option(
|
|
111
|
+
"--output", "-o", help="File to export to, e.g., a PNG or PDF."
|
|
112
|
+
),
|
|
113
|
+
],
|
|
114
|
+
dpi: Annotated[
|
|
115
|
+
int | None, typer.Option("--dpi", help="Resolution of a PNG.")
|
|
116
|
+
] = None,
|
|
117
|
+
) -> None:
|
|
118
|
+
try:
|
|
119
|
+
inkscape(source, output, dpi=dpi)
|
|
120
|
+
except ValueError as e:
|
|
121
|
+
raise_error(str(e))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@export_app.command(
|
|
125
|
+
name="gimp", help="Export a flattened figure from an XCF file."
|
|
126
|
+
)
|
|
127
|
+
def export_gimp(
|
|
128
|
+
source: Annotated[str, typer.Argument(help="XCF file to export from.")],
|
|
129
|
+
output: Annotated[
|
|
130
|
+
str,
|
|
131
|
+
typer.Option(
|
|
132
|
+
"--output", "-o", help="File to export to, e.g., a PNG or TIFF."
|
|
133
|
+
),
|
|
134
|
+
],
|
|
135
|
+
) -> None:
|
|
136
|
+
try:
|
|
137
|
+
gimp(source, output)
|
|
138
|
+
except ValueError as e:
|
|
139
|
+
raise_error(str(e))
|
calkit/cli/latex.py
CHANGED
|
@@ -660,6 +660,26 @@ def build(
|
|
|
660
660
|
"""
|
|
661
661
|
import time
|
|
662
662
|
|
|
663
|
+
def rel_to_tex_dir(path: str) -> str:
|
|
664
|
+
"""Express a current-directory-relative path from the .tex file's
|
|
665
|
+
directory.
|
|
666
|
+
|
|
667
|
+
Pure path arithmetic, since ``os.path.relpath`` resolves names like
|
|
668
|
+
``aux`` to devices on Windows.
|
|
669
|
+
"""
|
|
670
|
+
cwd = os.getcwd()
|
|
671
|
+
target = Path(os.path.normpath(os.path.join(cwd, path)))
|
|
672
|
+
start = Path(os.path.normpath(os.path.join(cwd, tex_dir)))
|
|
673
|
+
# On another drive, there's no relative path
|
|
674
|
+
if os.path.normcase(target.anchor) != os.path.normcase(start.anchor):
|
|
675
|
+
return target.as_posix()
|
|
676
|
+
t = [os.path.normcase(p) for p in target.parts]
|
|
677
|
+
s = [os.path.normcase(p) for p in start.parts]
|
|
678
|
+
n = 0
|
|
679
|
+
while n < min(len(t), len(s)) and t[n] == s[n]:
|
|
680
|
+
n += 1
|
|
681
|
+
return "/".join([".."] * (len(s) - n) + list(target.parts[n:])) or "."
|
|
682
|
+
|
|
663
683
|
# latexmk records a failed run in its file database and then refuses
|
|
664
684
|
# to try again, reporting "Nothing to do" and exiting non-zero with no
|
|
665
685
|
# PDF. Running it again is the first thing anyone does after a
|
|
@@ -672,6 +692,33 @@ def build(
|
|
|
672
692
|
# \ckfigure, have to be beside it before TeX can read them
|
|
673
693
|
for problem in calkit.latex.map_ck_components(tex_file):
|
|
674
694
|
warn(f"{problem}; it will print as ??")
|
|
695
|
+
# Plain \includegraphics counts as much as \ckfigure, and is fine
|
|
696
|
+
# wherever the pipeline made the file. Paths are the enclosing
|
|
697
|
+
# project's, wherever the build runs from, e.g., a stage's wdir
|
|
698
|
+
root = os.path.abspath(tex_dir)
|
|
699
|
+
while not os.path.isfile(os.path.join(root, "calkit.yaml")):
|
|
700
|
+
parent = os.path.dirname(root)
|
|
701
|
+
if parent == root:
|
|
702
|
+
root = os.path.abspath(".")
|
|
703
|
+
break
|
|
704
|
+
root = parent
|
|
705
|
+
shown = calkit.latex.find_shown(
|
|
706
|
+
os.path.relpath(os.path.abspath(tex_file), root), wdir=root
|
|
707
|
+
)
|
|
708
|
+
if shown:
|
|
709
|
+
from calkit.provenance import (
|
|
710
|
+
find_project_provenance_gaps,
|
|
711
|
+
how_to_define_origin,
|
|
712
|
+
)
|
|
713
|
+
|
|
714
|
+
for gap in find_project_provenance_gaps(shown, wdir=root):
|
|
715
|
+
msg = str(gap)
|
|
716
|
+
how = (
|
|
717
|
+
"give its URL, DOI, or Git repo in imported_from"
|
|
718
|
+
if gap.unchecked
|
|
719
|
+
else how_to_define_origin(gap.path)
|
|
720
|
+
)
|
|
721
|
+
warn(f"{msg[0].upper()}{msg[1:]}; {how}")
|
|
675
722
|
if not os.path.isfile(os.path.join(pdf_dir, stem + ".pdf")):
|
|
676
723
|
fdb_dir = aux_dir if aux_dir is not None else tex_dir
|
|
677
724
|
fdb_fpath = os.path.join(fdb_dir, stem + ".fdb_latexmk")
|
|
@@ -693,11 +740,9 @@ def build(
|
|
|
693
740
|
# file's directory; convert the (current-directory-relative) Calkit paths
|
|
694
741
|
# into that frame.
|
|
695
742
|
if output_dir is not None:
|
|
696
|
-
|
|
697
|
-
latexmk_cmd.append(f"-outdir={rel}")
|
|
743
|
+
latexmk_cmd.append(f"-outdir={rel_to_tex_dir(output_dir)}")
|
|
698
744
|
if aux_dir is not None:
|
|
699
|
-
|
|
700
|
-
latexmk_cmd.append(f"-auxdir={rel}")
|
|
745
|
+
latexmk_cmd.append(f"-auxdir={rel_to_tex_dir(aux_dir)}")
|
|
701
746
|
latexmk_cmd.append("-interaction=nonstopmode")
|
|
702
747
|
latexmk_cmd.append(f"-usepretex={calkit.latex.PDF_PRETEX}")
|
|
703
748
|
# User pass-through args come last so they can override Calkit's defaults.
|