pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Pixi does not consider target specific dependencies when comparing lock files

Open GuillaumeQuenneville opened this issue 10 months ago • 9 comments

Checks

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of pixi, using pixi --version.

Reproducible example

Commands I ran and their output:

pixi shell -v

I made a repo that reproduces the bug. https://github.com/GuillaumeQuenneville/pixitargetbug

Issue description

When pixi does a diff with a lock file, it does not consider target specific run-dependencies. In my reproduction, every time you run pixi shell -v. you'll see that the lock file is out of date on win-64 which is the target that has the conditional dependency. I compiled pixi from main and added a print statement to verify that this is in-fact happening. I compared the PackageData printing data in crates/pixi_core/src/lock_file/satisfiability/mod.rs line: 1330

You can change the target and then make a make a new env to see that it is not OS specific. You can also remove the target dependency and see the the environment reads the lockfile just fine. The bug also doesnt happen if you only have the single target in the supported platforms.

Packages with target specific dependencies will happen often for the MKL which doesnt not support arm64 but provides significant speed boosts on intel x86_64 arches.

Expected behavior

Pixi considers target specific dependencies when diffing lock files.

GuillaumeQuenneville avatar Jan 15 '26 15:01 GuillaumeQuenneville

Thanks, I very much appreciate the issue and the reproducer!

baszalmstra avatar Jan 15 '26 16:01 baszalmstra

I investigated this a little. The cause is that the package is a noarch package which should have the same dependencies on all platforms. We currently don't deal with that properly.

baszalmstra avatar Jan 16 '26 09:01 baszalmstra

Noarch packages cannot have platform-specific dependencies because they are not platform-specific. In this case I think our backend should error, telling the user to make the package arch specific.

When conditional dependencies are further developed, we can make those changes.

The solution for the time being is to add:

[package.build.config]
noarch = false

baszalmstra avatar Jan 16 '26 09:01 baszalmstra

To add, with conditional dependencies (https://github.com/conda/ceps/pull/111/changes#diff-82241b2f88ce71caab4f64ac25bff5f1e4544117b076952753b2b09677dec95a) you will be able to specify dependencies like:

- pywin32 [when = "__win"]
- numpy [when="python >=3.8"]

Or in TOML syntax:

pywin32 = { version = "*", when = "__win" }
numpy = { version = "*", when = "python >=3.8" }

wolfv avatar Jan 16 '26 09:01 wolfv

what should be the next steps here @baszalmstra?

nichtmacho avatar Jan 16 '26 10:01 nichtmacho

We should handle this properly in the pixi-build-python backend. Ill cook up an issue for it.

baszalmstra avatar Jan 16 '26 10:01 baszalmstra

Is the noarch not having target deps part of the spec? Suppose you had three packages that provided executables. And your noarch python calls them by command line. Then your lib would be noarch but have platform specific deps. E.g. a python package that uses only ctypes dlopen to interact with a lib that is dynamically found (e.g.mkl vs openblas)

My specific case was that I had to blacklist a version of a dependency that was not working specifically on windows.

On the python side, PEP 508 allows env specific dependencies in the pyproject dependencies. https://peps.python.org/pep-0508/#environment-markers

There are plenty of wrappers over os specific packages that are no-arch e.g. https://anaconda.org/channels/conda-forge/packages/python-gmsh/overview

Edit: just reread the other suggestion, I should have used conditional dependencies for my case. The error should suggest noarch or "maybe you wanted conditional dependencies?"

GuillaumeQuenneville avatar Jan 16 '26 14:01 GuillaumeQuenneville

You cannot yet use conditional deps, unfortunately.

However, you can add an option to not make your package noarch: https://prefix-dev.github.io/pixi-build-backends/backends/pixi-build-python/#noarch

We'll guard against this in the build backend in the future (or automatically not make your package noarch) if we detect target specific dependencies.

wolfv avatar Jan 16 '26 14:01 wolfv

Thank you! I'm assuming @baszalmstra wants to make an issue in the pixi-build-backends repo? Feel free to re-open if you want but my specific issue is addressed.

GuillaumeQuenneville avatar Jan 16 '26 15:01 GuillaumeQuenneville