|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
| 3 | +""" |
| 4 | +Generate a `pixi.toml` file. |
| 5 | +
|
| 6 | +Overview: |
| 7 | +
|
| 8 | +To a very good approximation, this script just runs RAW_COMMAND, |
| 9 | +and writes the output to `pixi.toml`. |
| 10 | +
|
| 11 | +This script is necessary in order to do some minor pre- and post-processing. |
| 12 | +
|
| 13 | +Context: |
| 14 | +
|
| 15 | +Pixi is a modern project-centric manager of Conda environments. |
| 16 | +It runs completely independently of more traditional tools like `conda` |
| 17 | +or `mamba`, or non-Conda-enabled Python environment managers like |
| 18 | +`pip` or `uv`. As such, we need to define the dependencies and Conda |
| 19 | +environments that pixi should automatically manage. This is specified |
| 20 | +in a `pixi.toml` file. |
| 21 | +
|
| 22 | +The sources of truth for the dependencies in this project are: |
| 23 | +- `environment.yml` |
| 24 | +- `pyproject.toml` |
| 25 | +
|
| 26 | +The goal of this script is to maintain the original sources of truth and |
| 27 | +in a completely automatic way generate a valid `pixi.toml` from them. |
| 28 | +
|
| 29 | +Currently, pixi has no mechanism for importing `environment.yml` files, |
| 30 | +and when loading `pyproject.toml` files it does not attempt to convert |
| 31 | +the PyPI dependencies into conda-forge dependencies. On the other hand, |
| 32 | +`conda-lock` does both of these things, and recently added support for |
| 33 | +generating `pixi.toml` files from `environment.yml` and `pyproject.toml` |
| 34 | +files. |
| 35 | +
|
| 36 | +PyTensor has some rather complicated dependencies, and so we do some |
| 37 | +pre- and post-processing in this script in order to work around some |
| 38 | +idiosyncrasies. |
| 39 | +
|
| 40 | +Technical details: |
| 41 | +
|
| 42 | +This script creates a temporary working directory `pixi-working/` in |
| 43 | +the project root, copies pre-processed versions of `environment.yml`, |
| 44 | +`pyproject.toml`, and `scripts/environment-blas.yml` into it, and then |
| 45 | +runs `conda-lock` via `pixi exec` in order to generate the contents of |
| 46 | +a `pixi.toml` file. |
| 47 | +
|
| 48 | +The generated `pixi.toml` contents are then post-processed and written |
| 49 | +to the project root. |
| 50 | +
|
| 51 | +The pre-processing steps are: |
| 52 | +
|
| 53 | +- Remove the `complete` and `development` optional dependencies from |
| 54 | + `pyproject.toml`. |
| 55 | +- Remove the BLAS dependencies from `environment.yml`. (They are redefined |
| 56 | + in `scripts/environment-blas.yml` on a platform-by-platform basis to |
| 57 | + work around limitations in `conda-lock`'s selector parsing.) |
| 58 | +
|
| 59 | +The post-processing steps are: |
| 60 | +
|
| 61 | +- Add an explanatory header comment to the `pixi.toml` file. |
| 62 | +- Remove the `win-64` platform from the jax feature (jaxlib is not |
| 63 | + available for Windows from conda-forge). |
| 64 | +- Add the default solve group to each environment entry. |
| 65 | +- Comment out the non-default environments. |
| 66 | +""" |
| 67 | + |
3 | 68 | import argparse
|
4 | 69 | import shlex
|
5 | 70 | import shutil
|
|
0 commit comments