|
| 1 | +# Update the Lockfile to Match Project State |
| 2 | + |
| 3 | +Use [`pytask lock`](../reference_guides/commands.md#pytask-lock) when the current files |
| 4 | +and outputs in the project are already correct, but the recorded state in `pytask.lock` |
| 5 | +needs to catch up. This can happen after refactoring task files, moving or renaming |
| 6 | +tasks, producing outputs outside of pytask, or deleting tasks. |
| 7 | + |
| 8 | +## Accept current files and outputs |
| 9 | + |
| 10 | +Use [`pytask lock accept`](../reference_guides/commands.md#pytask-lock-accept) when the |
| 11 | +current dependencies, products, and task definition are already correct and should |
| 12 | +become the new recorded state. |
| 13 | + |
| 14 | +Preview the changes without writing them with `--dry-run`: |
| 15 | + |
| 16 | +--8<-- "docs/source/_static/md/lock-accept-dry-run.md" |
| 17 | + |
| 18 | +Then accept the planned changes interactively: |
| 19 | + |
| 20 | +--8<-- "docs/source/_static/md/lock-accept-interactive.md" |
| 21 | + |
| 22 | +Add `--yes` to apply all planned changes without prompting: |
| 23 | + |
| 24 | +```console |
| 25 | +$ pytask lock accept -k train --yes |
| 26 | +``` |
| 27 | + |
| 28 | +If no selectors are provided, `pytask lock accept` applies to all collected tasks in the |
| 29 | +provided paths. |
| 30 | + |
| 31 | +If selectors are provided with `-k` or `-m`, `accept` automatically includes the |
| 32 | +ancestors of the selected tasks. This is useful when you target a downstream task and |
| 33 | +want the accepted state to stay consistent with its upstream dependencies. |
| 34 | + |
| 35 | +```console |
| 36 | +$ pytask lock accept -k evaluate |
| 37 | +``` |
| 38 | + |
| 39 | +In this example, `pytask` accepts `evaluate` and its ancestors. It does not |
| 40 | +automatically include descendants. If you want to accept a wider part of the DAG, widen |
| 41 | +the task selection yourself. |
| 42 | + |
| 43 | +```console |
| 44 | +$ pytask lock accept -k "train or evaluate" |
| 45 | +``` |
| 46 | + |
| 47 | +If a selected task is missing a required dependency or product, the command fails |
| 48 | +instead of accepting incomplete state. |
| 49 | + |
| 50 | +Run a build afterwards to check that unchanged tasks are skipped according to the |
| 51 | +updated lockfile. |
| 52 | + |
| 53 | +```console |
| 54 | +$ pytask build |
| 55 | +``` |
| 56 | + |
| 57 | +## Reset state for selected tasks |
| 58 | + |
| 59 | +Use [`pytask lock reset`](../reference_guides/commands.md#pytask-lock-reset) to remove |
| 60 | +recorded state for selected tasks when state was accepted too broadly or when specific |
| 61 | +tasks should be reconsidered from scratch. |
| 62 | + |
| 63 | +```console |
| 64 | +$ pytask lock reset -k train |
| 65 | +``` |
| 66 | + |
| 67 | +Unlike `accept`, `reset` with a selector works on the exact selected tasks. It does not |
| 68 | +automatically include ancestors. |
| 69 | + |
| 70 | +Preview the reset with `--dry-run` if you want to check the affected tasks first: |
| 71 | + |
| 72 | +```console |
| 73 | +$ pytask lock reset -k train --dry-run |
| 74 | +``` |
| 75 | + |
| 76 | +Add `--yes` to remove all planned entries without prompting: |
| 77 | + |
| 78 | +```console |
| 79 | +$ pytask lock reset -k train --yes |
| 80 | +``` |
| 81 | + |
| 82 | +If no selectors are provided, `pytask lock reset` removes the recorded state for all |
| 83 | +collected tasks in the provided paths. |
| 84 | + |
| 85 | +Run a build afterwards so `pytask` determines again whether the selected tasks require |
| 86 | +execution. |
| 87 | + |
| 88 | +```console |
| 89 | +$ pytask build |
| 90 | +``` |
| 91 | + |
| 92 | +## Remove stale entries for deleted or moved tasks |
| 93 | + |
| 94 | +Use [`pytask lock clean`](../reference_guides/commands.md#pytask-lock-clean) to remove |
| 95 | +entries from the lockfile which no longer correspond to collected tasks in the current |
| 96 | +project. This is useful after deleting, renaming, or moving tasks when old entries |
| 97 | +should no longer remain in the lockfile. |
| 98 | + |
| 99 | +Preview stale entries without writing them with `--dry-run`: |
| 100 | + |
| 101 | +```console |
| 102 | +$ pytask lock clean --dry-run |
| 103 | +``` |
| 104 | + |
| 105 | +Then remove stale entries interactively: |
| 106 | + |
| 107 | +--8<-- "docs/source/_static/md/lock-clean.md" |
| 108 | + |
| 109 | +Add `--yes` to remove all stale entries without prompting: |
| 110 | + |
| 111 | +```console |
| 112 | +$ pytask lock clean --yes |
| 113 | +``` |
| 114 | + |
| 115 | +`clean` only removes entries for tasks which are no longer collected. It does not accept |
| 116 | +or update the current state of collected tasks. |
| 117 | + |
| 118 | +## Related |
| 119 | + |
| 120 | +- [`pytask lock`](../reference_guides/commands.md#pytask-lock) |
| 121 | +- [`pytask build`](../reference_guides/commands.md#pytask-build) |
| 122 | +- [Portability](portability.md) |
| 123 | +- [The lockfile](../reference_guides/lockfile.md) |
0 commit comments