Pass environment variables to pypi dependencies
Problem description
Some pip dependencies, when they are built from source, require environnement variables to be passed on the command line.
Example: Detectron2 on macOS https://detectron2.readthedocs.io/en/latest/tutorials/install.html#build-detectron2-from-source https://github.com/facebookresearch/detectron2/discussions/4336
Detectron2 build isolation problems were solved on linux thanks to https://github.com/prefix-dev/pixi/pull/1909 But on macOS, I still need to resort to a manual task to build it properly:
[target.osx-arm64.dependencies]
uv = ">=0.2.37,<0.3"
setuptools = ">=72.2.0,<73"
[target.osx-arm64.tasks]
detectron = { cmd = "CC=clang CXX=clang++ ARCHFLAGS=\"-arch arm64\" pixi run uv pip install --no-build-isolation git+https://github.com/facebookresearch/detectron2@ebe8b45437f86395352ab13402ba45b75b4d1ddb" }
Proposal
Is there a possibility to add a new field to pypi dependencies ? Something like env ?
What I imagine for a multiplatform detectron2 install:
[pypi-options]
no-build-isolation = ["detectron2"]
[target.linux-64.pypi-dependencies]
detectron2 = { git = "https://github.com/facebookresearch/detectron2.git", rev = "ebe8b45437f86395352ab13402ba45b75b4d1ddb" }
[target.osx-arm64.pypi-dependencies]
detectron2 = { git = "https://github.com/facebookresearch/detectron2.git", rev = "ebe8b45437f86395352ab13402ba45b75b4d1ddb", env = "CC=clang CXX=clang++ ARCHFLAGS=\"-arch arm64\""}
I believe this should be possible with activation scripts. I'll make an example for you later 😀
hello @jeremyben !
Unfortunatly on my macOS Ventura 13.4 M2 Max this task doesn't work, so I can't really verify my solution. Could you please share it fully?
You can achieve this using activation scripts:
this would be the setup.sh
export CC=clang
export CXX=clang++
export ARCHFLAGS=\"-arch arm64\"
and you can use this target table to tell pixi to execute it prior running tasks, or just [activation] if you want it to be always included.
[target.osx-arm64.activation]
scripts = ["setup.sh"]
Let me know if it helps you
Thank you I thought activation scripts were meant for tasks or when entering pixi shell, not package installation/build. I will give it a try and let you know.
This was indeed the design. So this should work. There is a second option you can use with setting the env variables directly in the toml:
[target.osx-arm64.activation.env]
CC= "clang"
CXX= "clang++"
ARCHFLAGS= "-arch arm64"
Closing for now, reopen if there is something not working with these approaches