|
| 1 | +.. _requirements: |
| 2 | + |
| 3 | +Reproduce a workflow environment |
| 4 | +================================ |
| 5 | + |
| 6 | +A :term:`workflow` stores the python environment it was created in as the ``requirements`` |
| 7 | +field of its ``graph`` field. ``ewoks install`` recreates that environment and |
| 8 | +``ewoks execute --env`` runs the :term:`workflow` in it. See |
| 9 | +:ref:`this tutorial <install_tutorial>` for a step-by-step example. |
| 10 | + |
| 11 | +What is stored |
| 12 | +-------------- |
| 13 | + |
| 14 | +``ewoks convert`` and ``ewoks execute -o convert_destination=...`` store |
| 15 | + |
| 16 | +* ``python`` and ``system``: the python interpreter and the operating system. |
| 17 | +* ``distributions``: every installed python package with its version and, when it was not |
| 18 | + installed from the python package index, the git commit or the archive it came from. Any |
| 19 | + :term:`package manager` can recreate the environment from this list. |
| 20 | +* ``manager``: the :term:`package manager` that generated the requirements, with the content |
| 21 | + of the files it needs to recreate the environment: ``requirements.txt`` for pip-venv, |
| 22 | + ``pyproject.toml`` and ``uv.lock`` for uv, ``pyproject.toml`` and ``poetry.lock`` for |
| 23 | + poetry, ``environment.yml`` for conda, ``pixi.toml`` and ``pixi.lock`` for pixi. |
| 24 | + |
| 25 | +Use ``--exclude-requirements`` to store nothing. |
| 26 | + |
| 27 | +.. note:: |
| 28 | + |
| 29 | + A :term:`workflow` that stores a list of requirements instead of the structure above is |
| 30 | + still supported: the list is parsed as a ``requirements.txt`` file. |
| 31 | + |
| 32 | +Select a package manager |
| 33 | +------------------------ |
| 34 | + |
| 35 | +``ewoks convert`` uses the :term:`package manager` of the current python environment. It is |
| 36 | +detected from the environment variables and files that package managers leave behind, and |
| 37 | +from the tool that installed most of the packages. Use ``--package-manager-name`` to select |
| 38 | +one explicitly |
| 39 | + |
| 40 | +.. code-block:: bash |
| 41 | +
|
| 42 | + ewoks convert demo demo.json --test --package-manager-name uv |
| 43 | +
|
| 44 | +``ewoks install`` uses the :term:`package manager` that generated the requirements, unless it |
| 45 | +is not installed on the machine. It installs the stored files of that :term:`package manager`. |
| 46 | +When the requirements do not contain them, or installing them fails, it generates its own |
| 47 | +files from the ``distributions`` list and installs those instead. Both installations are |
| 48 | +confirmed separately unless ``--yes`` is provided |
| 49 | + |
| 50 | +.. code-block:: bash |
| 51 | +
|
| 52 | + # requirements generated by conda, environment created by uv |
| 53 | + ewoks install demo.json --yes --package-manager-name uv |
| 54 | +
|
| 55 | +``--package-manager-command`` provides the command that invokes the tool, for example when it |
| 56 | +is not on the ``PATH`` or when a faster implementation should be used |
| 57 | + |
| 58 | +.. code-block:: bash |
| 59 | +
|
| 60 | + ewoks install demo.json --yes --package-manager-name conda \ |
| 61 | + --package-manager-command micromamba |
| 62 | +
|
| 63 | +Choose the environment |
| 64 | +---------------------- |
| 65 | + |
| 66 | +.. code-block:: bash |
| 67 | +
|
| 68 | + # a root directory of your choice instead of the one of the package manager |
| 69 | + ewoks install demo.json --yes --env-root /tmp/envs |
| 70 | +
|
| 71 | + # a name of your choice instead of the workflow identifier |
| 72 | + ewoks install demo.json --yes --env-name demo-env |
| 73 | +
|
| 74 | + # remove the environment when it already exists |
| 75 | + ewoks install demo.json --yes --clean |
| 76 | +
|
| 77 | + # another python version than the one stored in the requirements |
| 78 | + ewoks install demo.json --yes --python-version 3.12 |
| 79 | +
|
| 80 | + # add ewoks itself when the requirements do not contain it |
| 81 | + ewoks install demo.json --yes --with-ewoks |
| 82 | +
|
| 83 | + # install in the current python environment instead of creating one |
| 84 | + ewoks install demo.json --yes --in-place |
| 85 | +
|
| 86 | +The default name is the identifier of the :term:`workflow`, which is the ``id`` field of its |
| 87 | +``graph`` field. A :term:`workflow` without an identifier gets a name derived from its |
| 88 | +content. |
| 89 | + |
| 90 | +Without ``--env-root`` the :term:`package manager` decides where the environment goes: conda |
| 91 | +creates it in its own environment directory (``conda config --show envs_dirs``), so |
| 92 | +``conda activate <name>`` finds it, and poetry in the directory it creates project |
| 93 | +environments in (``poetry config virtualenvs.path``). venv, uv and pixi create an environment |
| 94 | +wherever they are told to, so for those ewoks uses ``~/.ewoks/envs``. |
| 95 | + |
| 96 | +An environment that already exists is installed in, which adds the requirements to what is |
| 97 | +already there. Use ``--clean`` to remove it first. Only a directory that contains a python |
| 98 | +environment is removed. |
| 99 | + |
| 100 | +The environment of a :term:`workflow` is a directory. For pip-venv and conda it is a python |
| 101 | +environment, for uv and poetry it is a project with the environment in ``.venv`` and for pixi |
| 102 | +it is a workspace with the environment in ``.pixi/envs/default``. ``ewoks execute --env`` takes |
| 103 | +that directory, not the python interpreter inside it. |
| 104 | + |
| 105 | +Limitations |
| 106 | +----------- |
| 107 | + |
| 108 | +* ``--in-place`` is only supported by pip-venv and uv. The other package managers only install |
| 109 | + in an environment they created themselves. |
| 110 | +* ``--python-version`` is a request: uv, conda and pixi can provide any python version, while |
| 111 | + pip-venv and poetry can only use the version of the python interpreter that creates the |
| 112 | + environment. A warning is emitted when the version cannot be provided. |
| 113 | +* uv, poetry and pixi resolve the ``distributions`` into a lock file, which requires access to |
| 114 | + the package index. When that fails, a warning is emitted and the requirements are stored |
| 115 | + without files: the environment is then recreated from the ``distributions`` list. |
| 116 | +* A lock file is only read by a :term:`package manager` that understands its format version, so |
| 117 | + reproducing an environment can require a version of the tool that is at least as recent as |
| 118 | + the one that generated the requirements. |
| 119 | +* poetry 1.8 or later is required. Older versions are reported as not available. |
| 120 | +* A package installed from a local directory cannot be recreated elsewhere. This is reported as |
| 121 | + a warning when the requirements are generated. |
0 commit comments