Add Environment Markers to pypi-dependencies specification
Problem description
In pypi packaging you have the concept of environment markers, which can help you to optionally install a dependency. We've had requests of people wanting to use this to exclude certain dependencies according to the python version e.g:
pkg = { path ="./my-pkg", env-markers = ["python_version < '3.11'"] }
Because we re-create the PEP508 requirements, it would be easy to add and this is already taken into account in the satisfyiability. The main upside would be less features when compared to splitting all this up. Also, it would not be very hard to integrate.
Would love to hear everyone's thoughts.
Previous discussions
We have also talked about explicitly excluding certain dependencies from environments. However, @baszalmstra and myself feel this would open a can of worms. Seeing as how long it's taking to even agree on how to exclude the default-feature: https://github.com/prefix-dev/pixi/pull/1092 this approach mentioned above would be easier and already supported by the pypi ecosystem.
This kind of leaves the same question for conda dependencies, but I think we might need to tackle this differently, although a similar feature would probably be desirable.
I found myself needing this again today, while trying to add proper support for testing against various python version in Rerun.
I have a pyproject.toml that contains a number of optional dependencies, based on the python version and system you are using:
optional = [
"affine",
"descartes",
"fiona",
"geojson",
"geopandas",
"imageio",
"netcdf4",
"pymetis ; platform_system != 'Windows'",
"pyproj",
"pyshp",
"pyvista ; python_version <'3.13'",
"rasterio",
"rasterstats",
"scipy",
"shapely >=2.0",
"vtk ; python_version <'3.13'",
"xmipy",
]
My workaround is now to cap the python version and overwrite pymetis with a conda dependency, because there is a windows version on conda. But it's not the same functionality in some way or another.
[project]
requires-python = ">=3.9,<3.13"
[pixi.tool.feature.optional.dependencies]
pymetis = "*"
Yeah we are in the process of doing a uv upgrade and are making a distinction between the open-source pep_* crates and the uv_pep crates, now we should be able to integrate environment markers more easily :)
Would really love to see environment marker support in Pixi. Just out of curiosity is that mentioned uv upgrade complete?
It has been completed indeed!
Just added this to start on into our cycle in two weeks :)