|
| 1 | +# Move a Project to Another Machine |
| 2 | + |
| 3 | +This guide teaches you how to move a pytask project to another machine or environment |
| 4 | +and reuse existing outputs where possible. |
| 5 | + |
| 6 | +## Update the lockfile on the source machine |
| 7 | + |
| 8 | +Run a normal build with [`pytask build`](../reference_guides/commands.md#pytask-build) |
| 9 | +before moving the project with its `pytask.lock` and files and outputs are up-to-date: |
| 10 | + |
| 11 | +```console |
| 12 | +$ pytask build |
| 13 | +``` |
| 14 | + |
| 15 | +## Move the project files and reusable outputs |
| 16 | + |
| 17 | +If you have not done it yet, commit `pytask.lock` to your repository and move it with |
| 18 | +the project. In practice, move: |
| 19 | + |
| 20 | +- the project files tracked in version control, including source files, configuration, |
| 21 | + data inputs, and `pytask.lock` |
| 22 | +- the build artifacts you want to reuse, often in `bld/` if you follow the tutorial |
| 23 | + layout |
| 24 | +- the `.pytask` folder if you use the data catalog and it manages some of your files |
| 25 | + |
| 26 | +## Keep external files in the same relative layout |
| 27 | + |
| 28 | +If tasks use files outside the project root, keep the same relative layout on the target |
| 29 | +machine. The project root is the folder with the `pyproject.toml` file. |
| 30 | + |
| 31 | +For example, if a task reads `../shared/input.csv` from the source machine, the moved |
| 32 | +project also needs a readable `../shared/input.csv` next to the project root on the |
| 33 | +target machine. |
| 34 | + |
| 35 | +## Run pytask on the target machine |
| 36 | + |
| 37 | +After you moved the project to the target machine, run pytask to build the project: |
| 38 | + |
| 39 | +```console |
| 40 | +$ pytask build |
| 41 | +``` |
| 42 | + |
| 43 | +Assuming that the project was fully built before the move, pytask will not rebuild the |
| 44 | +project and skip all tasks. |
| 45 | + |
| 46 | +## Clean stale lockfile entries |
| 47 | + |
| 48 | +If you removed, renamed, or moved tasks before transferring the project, clean up stale |
| 49 | +lockfile entries on the source machine before you move the project: |
| 50 | + |
| 51 | +```console |
| 52 | +$ pytask build --clean-lockfile |
| 53 | +``` |
| 54 | + |
| 55 | +This rewrites the lockfile after a successful build with only the currently collected |
| 56 | +tasks and their current state values. |
| 57 | + |
| 58 | +## If your project uses custom nodes |
| 59 | + |
| 60 | +Make sure custom node IDs and state values stay stable across machines: |
| 61 | + |
| 62 | +- Use project-relative IDs instead of absolute paths. |
| 63 | +- Prefer file content hashes over timestamps. |
| 64 | +- Avoid machine-specific paths or timestamps in custom |
| 65 | + [`state()`](../api/nodes_and_tasks.md#pytask.PNode.state) implementations. |
| 66 | +- Provide a custom hash function for |
| 67 | + [`PythonNode`](../api/nodes_and_tasks.md#pytask.PythonNode) values that are not |
| 68 | + natively stable. |
| 69 | + |
| 70 | +Most projects that only use built-in nodes do not need extra work here. |
| 71 | + |
| 72 | +!!! seealso |
| 73 | + |
| 74 | + The lockfile format and behavior are documented in the |
| 75 | + [reference guide](../reference_guides/lockfile.md). For custom nodes, see |
| 76 | + [Writing custom nodes](writing_custom_nodes.md). For hashing guidance, see |
| 77 | + [Hashing inputs of tasks](hashing_inputs_of_tasks.md). |
0 commit comments