pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Add Environment Markers to pypi-dependencies specification

Open tdejager opened this issue 1 year ago • 6 comments

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.

tdejager avatar Apr 23 '24 09:04 tdejager

I found myself needing this again today, while trying to add proper support for testing against various python version in Rerun.

abey79 avatar Jul 03 '24 14:07 abey79

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 = "*"

deltamarnix avatar Nov 04 '24 11:11 deltamarnix

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 :)

tdejager avatar Nov 04 '24 14:11 tdejager

Would really love to see environment marker support in Pixi. Just out of curiosity is that mentioned uv upgrade complete?

cpcloud avatar Oct 08 '25 19:10 cpcloud

It has been completed indeed!

tdejager avatar Oct 08 '25 19:10 tdejager

Just added this to start on into our cycle in two weeks :)

tdejager avatar Oct 09 '25 10:10 tdejager