Skip to content

Commit f369ce4

Browse files
authored
Add pytask lock command (#860)
1 parent d644e5e commit f369ce4

22 files changed

Lines changed: 1844 additions & 69 deletions

‎.pre-commit-config.yaml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ repos:
2525
- id: python-no-log-warn
2626
- id: text-unicode-replacement-char
2727
- repo: https://github.com/astral-sh/ruff-pre-commit
28-
rev: v0.15.11
28+
rev: v0.15.12
2929
hooks:
3030
- id: ruff-format
3131
- id: ruff-check
3232
- repo: https://github.com/astral-sh/uv-pre-commit
3333
rev: 0.11.7
3434
hooks:
3535
- id: uv-lock
36+
- repo: local
37+
hooks:
38+
- id: check-termynal-line-lengths
39+
name: Check Termynal line lengths
40+
entry: python scripts/check_termynal_line_lengths.py
41+
language: python
42+
files: ^docs/source/_static/md/.*\.md$
3643
- repo: https://github.com/executablebooks/mdformat
3744
rev: 1.0.0
3845
hooks:
@@ -60,7 +67,7 @@ repos:
6067
- id: nbstripout
6168
exclude: (docs)
6269
- repo: https://github.com/crate-ci/typos
63-
rev: v1
70+
rev: v1.45.1
6471
hooks:
6572
- id: typos
6673
exclude: (\.ipynb)

‎.readthedocs.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ build:
1919
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uv sync --frozen --group docs
2020
build:
2121
html:
22-
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uv run --group docs zensical build
22+
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uvx --from rust-just just docs
2323
post_build:
2424
- mkdir -p "${READTHEDOCS_OUTPUT}/html"
2525
- cp -a docs/build/. "${READTHEDOCS_OUTPUT}/html/"

‎docs/source/_static/md/commands/build-options.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
| ---------------------------------------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
33
| <code>-c, --config FILE</code> | - | Path to configuration file. |
44
| <code>--capture [fd\|no\|sys\|tee-sys]</code> | <code>fd</code> | Per task capturing method. |
5-
| <code>--clean-lockfile</code> | <code>false</code> | Rewrite the lockfile with only currently collected tasks. |
65
| <code>--database-url TEXT</code> | - | Url to the database. |
76
| <code>--debug-pytask</code> | <code>false</code> | Trace all function calls in the plugin framework. |
87
| <code>--disable-warnings</code> | <code>false</code> | Disables the summary for warnings. |

‎docs/source/_static/md/commands/command-list.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
| [`clean`](clean.md) | Clean the provided paths by removing files unknown to pytask. |
55
| [`collect`](collect.md) | Collect tasks and report information about them. |
66
| [`dag`](dag.md) | Create a visualization of the directed acyclic graph. |
7+
| [`lock`](lock.md) | Inspect and update recorded task state in the lockfile. |
78
| [`markers`](markers.md) | Show all registered markers. |
89
| [`profile`](profile.md) | Show information about resource consumption. |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="termy">
2+
3+
```console
4+
$ pytask lock accept -k train --dry-run
5+
6+
<span class="termynal-dim">──────────────────────────</span> Start pytask session <span class="termynal-dim">──────────────────────────</span>
7+
Platform: win32 -- Python 3.12.0, pytask 0.5.3
8+
Root: C:\Users\pytask-dev\git\my_project
9+
Collected 2 tasks.
10+
<span class="termynal-success">Would accept recorded state for task_train.py::task_train.</span>
11+
<span class="termynal-success">Would accept recorded state for task_evaluate.py::task_evaluate.</span>
12+
13+
<span class="termynal-dim">─────────────────────────────────────────────────────────────────────────</span>
14+
```
15+
16+
</div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="termy">
2+
3+
```console
4+
$ pytask lock accept -k train
5+
<span class="termynal-dim">──────────────────────────</span> Start pytask session <span class="termynal-dim">──────────────────────────</span>
6+
Platform: win32 -- Python 3.12.0, pytask 0.5.3
7+
Root: C:\Users\pytask-dev\git\my_project
8+
Collected 2 tasks.
9+
# Accept recorded state for task_train.py::task_train? [y/N]: $ y
10+
# Accept recorded state for task_evaluate.py::task_evaluate? [y/N]: $ n
11+
<span class="termynal-success">Accept recorded state for task_train.py::task_train.</span>
12+
13+
<span class="termynal-dim">─────────────────────────────────────────────────────────────────────────</span>
14+
```
15+
16+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="termy">
2+
3+
```console
4+
$ pytask lock clean
5+
<span class="termynal-dim">──────────────────────────</span> Start pytask session <span class="termynal-dim">──────────────────────────</span>
6+
Platform: win32 -- Python 3.12.0, pytask 0.5.3
7+
Root: C:\Users\pytask-dev\git\my_project
8+
Collected 2 tasks.
9+
# Remove recorded state for task_old.py::task_train? [y/N]: $ y
10+
# Remove recorded state for task_old.py::task_evaluate? [y/N]: $ y
11+
<span class="termynal-success">Remove recorded state for task_old.py::task_train.</span>
12+
<span class="termynal-success">Remove recorded state for task_old.py::task_evaluate.</span>
13+
14+
<span class="termynal-dim">─────────────────────────────────────────────────────────────────────────</span>
15+
```
16+
17+
</div>

‎docs/source/how_to_guides/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ specific tasks with pytask.
1010
- [Migrating From Scripts To Pytask](migrating_from_scripts_to_pytask.md)
1111
- [Interfaces For Dependencies Products](interfaces_for_dependencies_products.md)
1212
- [Portability](portability.md)
13+
- [Reconciling Lockfile State](reconciling_lockfile_state.md)
1314
- [Remote Files](remote_files.md)
1415
- [Functional Interface](functional_interface.md)
1516
- [Capture Warnings](capture_warnings.md)

‎docs/source/how_to_guides/portability.md‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ Use this checklist when you move a project to another machine or environment.
1717
Run a normal build with [`pytask build`](../reference_guides/commands.md#pytask-build)
1818
so `pytask.lock` is up to date:
1919

20-
````
2120
```console
2221
$ pytask build
2322
```
2423

2524
If you already have a recent lockfile and up-to-date outputs, you can skip this step.
26-
````
2725

2826
1. **Ship the right files.**
2927

@@ -85,11 +83,10 @@ tasks run. If tasks are removed or renamed, their old entries remain as stale da
8583
are ignored.
8684

8785
To clean up stale entries without deleting the file, run
88-
[`pytask build --clean-lockfile`](../reference_guides/commands.md#pytask-build--clean-lockfile):
86+
[`pytask lock clean`](../reference_guides/commands.md#pytask-lock-clean):
8987

9088
```console
91-
$ pytask build --clean-lockfile
89+
$ pytask lock clean
9290
```
9391

94-
This rewrites the lockfile after a successful build with only the currently collected
95-
tasks and their current state values.
92+
This removes lockfile entries for tasks which are no longer collected.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Reconciling Lockfile State
2+
3+
Use [`pytask lock`](../reference_guides/commands.md#pytask-lock) when the current files
4+
in the project are already correct and only the recorded state in `pytask.lock` needs to
5+
catch up.
6+
7+
## When is this useful?
8+
9+
Typical situations are:
10+
11+
- You reformatted or reorganized a task file and do not want to rerun an expensive task.
12+
- You renamed or moved a task and want to accept the current outputs for the new task.
13+
- You produced outputs outside of pytask and now want to register the task along the
14+
outputs in the lockfile.
15+
- You deleted or renamed tasks and want to remove their stale lockfile entries.
16+
17+
## Preview changes first
18+
19+
By default, `pytask lock` runs interactively. It shows the planned changes and then asks
20+
for confirmation one by one. Only entries which would actually change appear in the
21+
prompt sequence.
22+
23+
To preview changes without writing them, use `--dry-run`:
24+
25+
--8<-- "docs/source/_static/md/lock-accept-dry-run.md"
26+
27+
To apply all planned changes without prompting, use `--yes`:
28+
29+
```console
30+
$ pytask lock accept -k train --yes
31+
```
32+
33+
## Accept the current state
34+
35+
Use [`pytask lock accept`](../reference_guides/commands.md#pytask-lock-accept) when the
36+
current dependencies, products, and task definition are already correct and should
37+
become the new recorded state.
38+
39+
--8<-- "docs/source/_static/md/lock-accept-interactive.md"
40+
41+
If no selectors are provided, `pytask lock accept` applies to all collected tasks in the
42+
provided paths.
43+
44+
If selectors are provided with `-k` or `-m`, `accept` automatically includes the
45+
ancestors of the selected tasks. This is useful when you target a downstream task and
46+
want the accepted state to stay consistent with its upstream dependencies.
47+
48+
```console
49+
$ pytask lock accept -k evaluate
50+
```
51+
52+
In this example, `pytask` accepts `evaluate` and its ancestors. It does not
53+
automatically include descendants. If you want to accept a wider part of the DAG, widen
54+
the task selection yourself.
55+
56+
```console
57+
$ pytask lock accept -k "train or evaluate"
58+
```
59+
60+
If a selected task is missing a required dependency or product, the command fails
61+
instead of accepting incomplete state.
62+
63+
## Reset recorded state
64+
65+
Use [`pytask lock reset`](../reference_guides/commands.md#pytask-lock-reset) to remove
66+
recorded state for selected tasks. The following command removes the recorded state for
67+
all tasks.
68+
69+
```console
70+
$ pytask lock reset
71+
```
72+
73+
Unlike `accept`, `reset` with a selector works on the exact selected tasks. It does not
74+
automatically include ancestors.
75+
76+
```console
77+
$ pytask lock reset -k train
78+
```
79+
80+
On the next build, `pytask` determines again whether these tasks require execution. This
81+
is useful when state was accepted too broadly or when you want a specific task to be
82+
reconsidered from scratch.
83+
84+
## Remove stale lockfile entries
85+
86+
Use [`pytask lock clean`](../reference_guides/commands.md#pytask-lock-clean) to remove
87+
entries from the lockfile which no longer correspond to collected tasks in the current
88+
project.
89+
90+
--8<-- "docs/source/_static/md/lock-clean.md"
91+
92+
This is useful after deleting, renaming, or moving tasks when old entries should no
93+
longer remain in the lockfile.
94+
95+
## Example workflow
96+
97+
One common workflow looks like this:
98+
99+
1. Run a normal build once.
100+
1. Change a task file in a way that should not force a rerun.
101+
1. Accept the current state.
102+
1. Verify that a later build skips the task.
103+
1. Reset the task if you want `pytask` to reconsider it again.
104+
105+
```console
106+
$ pytask build
107+
$ pytask lock accept -k train --yes
108+
$ pytask build
109+
$ pytask lock reset -k train --yes
110+
$ pytask build
111+
```
112+
113+
After `accept`, the next build skips unchanged tasks according to the updated lockfile.
114+
After `reset`, the selected tasks are reconsidered on the next build.
115+
116+
## Related
117+
118+
- [`pytask lock`](../reference_guides/commands.md#pytask-lock)
119+
- [`pytask build`](../reference_guides/commands.md#pytask-build)
120+
- [Portability](portability.md)
121+
- [The lockfile](../reference_guides/lockfile.md)

0 commit comments

Comments
 (0)