pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Pass environment variables to pypi dependencies

Open jeremyben opened this issue 2 years ago • 4 comments

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\""}

jeremyben avatar Sep 10 '24 12:09 jeremyben

I believe this should be possible with activation scripts. I'll make an example for you later 😀

tdejager avatar Sep 11 '24 05:09 tdejager

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

nichtmacho avatar Sep 11 '24 08:09 nichtmacho

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.

jeremyben avatar Sep 12 '24 21:09 jeremyben

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

ruben-arts avatar Sep 17 '24 11:09 ruben-arts