Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
31dce2d
feat(model): add dependency override in model
HernandoR Jun 14, 2025
db9204e
fix: change PIXI_BUILD_API_VERSION_NAME from const to static
HernandoR Jun 14, 2025
1b293f6
feat(pypi): add dependency overrides to PypiOptions and TOML deserial…
HernandoR Jun 14, 2025
2547567
test(snap): update snap relating to dependency override
HernandoR Jun 14, 2025
28afc35
feat(pypi): add support for dependency overrides in resolve_pypi func…
HernandoR Jun 15, 2025
8106c97
feat(schema): add dependency overrides for numpy in project.pypi-options
HernandoR Jun 15, 2025
e4f40af
Merge branch 'main' into lz/feat/pypi-overide
nichmor Jun 23, 2025
9e36530
更新 model.py
HernandoR Jun 24, 2025
8897783
更新 override.md
HernandoR Jun 24, 2025
c206e1c
feat(override): add samples, and updated marks
HernandoR Jun 28, 2025
950b691
remove commented code
HernandoR Jun 28, 2025
e220df0
draft: test(overide)
HernandoR Jun 28, 2025
e099dfb
test(depency_overrides): add genrated lock file.
HernandoR Jul 4, 2025
a830d3e
fix typo
HernandoR Jul 5, 2025
8b74fb3
Merge branch 'main' into lz/feat/pypi-overide
HernandoR Jul 5, 2025
c1b9808
fix
HernandoR Jul 5, 2025
17f2e48
test(snap): update snaps
HernandoR Jul 5, 2025
e7f7fcd
fix(lint)
HernandoR Jul 5, 2025
d386b9f
feat(nav): add Dependency Overrides section to Advanced documentation
HernandoR Jul 5, 2025
5aa356c
Merge branch 'main' into lz/feat/pypi-overide
HernandoR Jul 8, 2025
7bcc730
Merge branch 'main' into lz/feat/pypi-overide
HernandoR Jul 10, 2025
02e7c73
fix: improve error handling for dependency overrides in resolve_pypi
HernandoR Jul 10, 2025
f5aaa03
test: enhance pypi overrides test to verify lock file contents
HernandoR Jul 10, 2025
60ffd25
Merge branch 'main' into lz/feat/pypi-overide
HernandoR Jul 10, 2025
fe9983d
Merge branch 'main' into lz/feat/pypi-overide
tdejager Jul 11, 2025
06fdaa0
chore(doc): fix wrongfull comment
HernandoR Jul 11, 2025
523e783
doc(override): update how override interact with other
HernandoR Jul 11, 2025
802bd09
Merge branch 'main' into lz/feat/pypi-overide
nichmor Jul 14, 2025
524549b
test(pypi_options): update merge test to include dependency_overrides
HernandoR Jul 14, 2025
026053e
Merge branch 'main' into lz/feat/pypi-overide
nichmor Jul 14, 2025
42de699
remove the redundend todo, since it has been implement
HernandoR Jul 14, 2025
ba07228
Merge branch 'main' into lz/feat/pypi-overide
HernandoR Jul 15, 2025
336091c
Merge branch 'main' into lz/feat/pypi-overide
HernandoR Jul 17, 2025
f278422
Merge branch 'main' into lz/feat/pypi-overide
HernandoR Jul 17, 2025
4af4ba6
Merge branch 'main' into lz/feat/pypi-overide
tdejager Jul 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ find-links:
no-build-isolation: []
index-strategy: ~
no-build: ~
dependency-overrides: ~
no-binary: ~
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ find-links: ~
no-build-isolation: []
index-strategy: ~
no-build: ~
dependency-overrides: ~
no-binary: ~
48 changes: 48 additions & 0 deletions crates/pixi_manifest/src/pypi/pypi_options.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{hash::Hash, path::PathBuf};

use indexmap::IndexMap;
use indexmap::IndexSet;
use pep508_rs::PackageName;
use pixi_pypi_spec::{PixiPypiSpec, PypiPackageName};
use serde::{Serialize, Serializer, ser::SerializeSeq};
use thiserror::Error;
use url::Url;
Expand Down Expand Up @@ -133,6 +135,8 @@ pub struct PypiOptions {
pub index_strategy: Option<IndexStrategy>,
/// Don't build sdist for all or certain packages
pub no_build: Option<NoBuild>,
/// Dependency overrides
pub dependency_overrides: Option<IndexMap<PypiPackageName, PixiPypiSpec>>,
/// Don't use pre-built wheels all or certain packages
pub no_binary: Option<NoBinary>,
}
Expand All @@ -151,13 +155,15 @@ fn clone_and_deduplicate<'a, I: Iterator<Item = &'a T>, T: Clone + Eq + Hash + '
}

impl PypiOptions {
#[allow(clippy::too_many_arguments)]
pub fn new(
index: Option<Url>,
extra_indexes: Option<Vec<Url>>,
flat_indexes: Option<Vec<FindLinksUrlOrPath>>,
no_build_isolation: NoBuildIsolation,
index_strategy: Option<IndexStrategy>,
no_build: Option<NoBuild>,
dependency_overrides: Option<IndexMap<PypiPackageName, PixiPypiSpec>>,
no_binary: Option<NoBinary>,
) -> Self {
Self {
Expand All @@ -167,6 +173,7 @@ impl PypiOptions {
no_build_isolation,
index_strategy,
no_build,
dependency_overrides,
no_binary,
}
}
Expand Down Expand Up @@ -271,6 +278,21 @@ impl PypiOptions {
(None, Some(b)) => Some(b.clone()),
(None, None) => None,
};
// Set the dependency overrides
// notice that default feature comes last in the feature_ext
// so we want self overwriting the other
// i.e. if same key exists in both, we want the value from `self` to be used
// so we extend b with a (a overrides b)
let dependency_overrides = match (&self.dependency_overrides, &other.dependency_overrides) {
(Some(a), Some(b)) => {
let mut overrides = b.clone();
overrides.extend(a.into_iter().map(|(k, v)| (k.clone(), v.clone())));
Some(overrides)
}
(Some(a), None) => Some(a.clone()),
(None, Some(b)) => Some(b.clone()),
(None, None) => None,
};

// Set the no-binary option
let no_binary = match (self.no_binary.as_ref(), other.no_binary.as_ref()) {
Expand All @@ -287,6 +309,7 @@ impl PypiOptions {
no_build_isolation,
index_strategy,
no_build,
dependency_overrides,
no_binary,
})
}
Expand Down Expand Up @@ -441,6 +464,16 @@ mod tests {
]),
index_strategy: None,
no_build: None,
dependency_overrides:Some(IndexMap::from_iter([
(
"pkg1".parse().unwrap(),
PixiPypiSpec::RawVersion("==1.0.0".parse().unwrap()),
),
(
"pkg2".parse().unwrap(),
PixiPypiSpec::RawVersion("==2.0.0".parse().unwrap()),
),
])),
no_binary: Default::default(),
};

Expand All @@ -455,6 +488,17 @@ mod tests {
no_build_isolation: NoBuildIsolation::from_iter(["foo".parse().unwrap()]),
index_strategy: None,
no_build: Some(NoBuild::All),
dependency_overrides: Some(IndexMap::from_iter([
(
"pkg1".parse().unwrap(),
PixiPypiSpec::RawVersion("==1.2.0".parse().unwrap()),
),
(
"pkg3".parse().unwrap(),
PixiPypiSpec::RawVersion("==3.2.0".parse().unwrap()),
),
])),

no_binary: Default::default(),
};

Expand Down Expand Up @@ -550,6 +594,7 @@ mod tests {
no_build_isolation: NoBuildIsolation::default(),
index_strategy: None,
no_build: Default::default(),
dependency_overrides: None,
no_binary: Default::default(),
};

Expand All @@ -561,6 +606,7 @@ mod tests {
no_build_isolation: NoBuildIsolation::default(),
index_strategy: None,
no_build: Default::default(),
dependency_overrides: None,
no_binary: Default::default(),
};

Expand All @@ -580,6 +626,7 @@ mod tests {
no_build_isolation: NoBuildIsolation::default(),
index_strategy: Some(IndexStrategy::FirstIndex),
no_build: Default::default(),
dependency_overrides: None,
no_binary: Default::default(),
};

Expand All @@ -591,6 +638,7 @@ mod tests {
no_build_isolation: NoBuildIsolation::default(),
index_strategy: Some(IndexStrategy::UnsafeBestMatch),
no_build: Default::default(),
dependency_overrides: None,
no_binary: Default::default(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ no-build-isolation:
- bar
index-strategy: ~
no-build: all
dependency-overrides:
pkg1: "==1.0.0"
pkg3: "==3.2.0"
pkg2: "==2.0.0"
no-binary: ~
16 changes: 15 additions & 1 deletion crates/pixi_manifest/src/toml/pypi_options.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::PathBuf, str::FromStr};

use indexmap::IndexSet;
use pixi_toml::{TomlEnum, TomlFromStr, TomlWith};
use pixi_toml::{TomlEnum, TomlFromStr, TomlIndexMap, TomlWith};
use toml_span::{
DeserError, ErrorKind, Value,
de_helpers::{TableHelper, expected},
Expand Down Expand Up @@ -124,6 +124,9 @@ impl<'de> toml_span::Deserialize<'de> for PypiOptions {
.map(TomlEnum::into_inner);

let no_build = th.optional::<NoBuild>("no-build");
let dependency_overrides = th
.optional::<TomlIndexMap<_, _>>("dependency-overrides")
.map(TomlIndexMap::into_inner);

let no_binary = th.optional::<NoBinary>("no-binary");

Expand All @@ -136,6 +139,7 @@ impl<'de> toml_span::Deserialize<'de> for PypiOptions {
no_build_isolation,
index_strategy,
no_build,
dependency_overrides,
no_binary,
})
}
Expand Down Expand Up @@ -238,6 +242,7 @@ impl<'de> toml_span::Deserialize<'de> for NoBuildIsolation {
#[cfg(test)]
mod test {
use insta::{assert_debug_snapshot, assert_snapshot};
use pixi_pypi_spec::PypiPackageName;
use pixi_test_utils::format_parse_error;

use super::*;
Expand All @@ -262,6 +267,9 @@ mod test {

[[find-links]]
url = "https://flat.index"

[dependency-overrides]
numpy = ">=2.0.0"
"#;
let deserialized_options: PypiOptions = PypiOptions::from_toml_str(toml_str).unwrap();
assert_eq!(
Expand All @@ -279,6 +287,12 @@ mod test {
]),
index_strategy: None,
no_build: Default::default(),
dependency_overrides: Some(indexmap::IndexMap::from_iter([(
PypiPackageName::from_str("numpy").unwrap(),
pixi_pypi_spec::PixiPypiSpec::RawVersion(
pixi_pypi_spec::VersionOrStar::from_str(">=2.0.0").unwrap()
)
)]),),
no_binary: Default::default(),
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/pixi_manifest/src/toml/pypi_options.rs
assertion_line: 299
expression: options
---
PypiOptions {
Expand Down Expand Up @@ -88,6 +87,7 @@ PypiOptions {
no_build: Some(
All,
),
dependency_overrides: None,
no_binary: Some(
Packages(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/pixi_manifest/src/toml/pypi_options.rs
assertion_line: 317
expression: options
---
PypiOptions {
Expand All @@ -12,6 +11,7 @@ PypiOptions {
),
index_strategy: None,
no_build: None,
dependency_overrides: None,
no_binary: Some(
Packages(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ PypiOptions {
no_build_isolation: All,
index_strategy: None,
no_build: None,
dependency_overrides: None,
no_binary: None,
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ PypiOptions {
},
),
),
dependency_overrides: None,
no_binary: None,
}
10 changes: 10 additions & 0 deletions crates/pixi_pypi_spec/src/name.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use pep508_rs::{InvalidNameError, PackageName};
use serde::{Serialize, Serializer};
use std::{borrow::Borrow, str::FromStr};

/// A package name for Pypi that also stores the source version of the name.
Expand Down Expand Up @@ -39,6 +40,15 @@ impl FromStr for PypiPackageName {
}
}

impl Serialize for PypiPackageName {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.as_source().serialize(serializer)
}
}

impl PypiPackageName {
pub fn from_normalized(normalized: PackageName) -> Self {
Self {
Expand Down
66 changes: 66 additions & 0 deletions docs/overrides/override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Overview

Sometimes our direct dependency declares outdated intermediate dependency or is too tight to solve with other direct dependencies. In this case, we can override the intermediate dependency in our `pyproject.toml`or `pixi.toml` file.

> [!Note] This option is not recommended unless you know what you are doing, as uv will ignore all the version constraints of the dependency and use the version you specified.

## Example
### Override a dependency version
```toml
# pyproject.toml
[tool.pixi.pypi-options.dependency-overrides]
numpy = ">=2.0.0"
```
or in `pixi.toml`:

```toml
# pixi.toml
[pypi-options.dependency-overrides]
numpy = ">=2.0.0"
```
This will override the version of `numpy` used by all dependencies to be at least `2.0.0`, regardless of what the dependencies specify.
This is useful if you need a specific version of a library that is not compatible with the versions specified by your dependencies.

### Override a dependency version in a specific feature
it can also be specified in feature level,
```toml
[features.dev.pypi-options.dependency-overrides]
numpy = ">=2.0.0"
```
This will override the version of `numpy` used by all dependencies in the `dev` feature to be at least `2.0.0`, regardless of what the dependencies specify when the `dev` feature is enabled.
Comment thread
HernandoR marked this conversation as resolved.

### Interact with other overrides
For a specific environment, all the `dependency-overrides` defined in different features will be combined in the order they were when defining the environment.

If the same dependency is overridden multiple times, we'll use the override from the **prior** feature in that environment.

Also, the default feature will always come, and come last in the list of all overrides.

```toml
# pixi.toml
[pypi-options]
dependency-overrides = { numpy = ">=2.1.0" }

[pypi-dependencies]
numpy = ">=1.25.0"

[feature.dev.pypi-options.dependency-overrides]
numpy = "==2.0.0"

[feature.outdated.pypi-options.dependency-overrides]
numpy = "==1.21.0"

[environments]
dev = ["dev"]
outdated = ["outdated"]
conflict_a=["outdated", "dev"]
conflict_b=["dev","outdated"]
```
the following constrains are merged out:
default: `numpy >= 2.1.0`
dev: `numpy == 2.0.0`
outdated: `numpy == 1.21.0`
conflict_a: `numpy == 1.21.0` (from `outdated`)
conflict_b: `numpy == 2.0.0` (from `dev`)

This may contrast with the intuition that all overrides are applied and combined to a result, but it is done this way to avoid conflicts and confusion. Since users are granted fully control over the overrides, it is up to ourselves to choose the right overrides for the environment.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ nav:
- Advanced:
- Channel Logic: advanced/channel_logic.md
- Info Command: advanced/explain_info_command.md
- Dependency Overrides: overrides/override.md
- Shebang: advanced/shebang.md
- Shell: advanced/pixi_shell.md
- Reference:
Expand Down
3 changes: 3 additions & 0 deletions schema/examples/valid/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ version = "0.1.0"

[project.pypi-options]
no-build = false
[project.pypi-options.dependency-overrides]
numpy = { version = ">=1.21.0" }

[package]
# Inherit the name and version the workspace
Expand Down Expand Up @@ -125,6 +127,7 @@ test = "*"
test = "*"

[feature.yes-build.pypi-options]
dependency-overrides = { numpy = ">=2.0.0" }
no-build = true

[feature.prod]
Expand Down
7 changes: 7 additions & 0 deletions schema/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,13 @@ class PyPIOptions(StrictBaseModel):
description="Packages that should NOT be built",
examples=["true", "false"],
)
dependency_overrides: dict[PyPIPackageName, PyPIRequirement] | None = Field(
None,
description="A list of PyPI dependencies that override the resolved dependencies",
examples=[
{"numpy": ">=1.21.0"},
],
)
no_binary: bool | list[PyPIPackageName] | None = Field(
None,
description="Don't use pre-built wheels for these packages",
Expand Down
Loading
Loading