|
| 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