Skip to content

Commit

Permalink
fix: add package when extra is added (prefix-dev#1856)
Browse files Browse the repository at this point in the history
Fixes prefix-dev#1850

Reallows for:
```
pixi add black --pypi

pixi add black[cli] --pypi
```
  • Loading branch information
ruben-arts authored Aug 22, 2024
1 parent c53dd22 commit 6fd6efe
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
7 changes: 6 additions & 1 deletion crates/pixi_manifest/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ impl Target {
*r == PyPiRequirement::try_from(requirement.clone())
.expect("could not convert pep508 requirement")
}
(Some(_), false) => true,
(Some(r), false) => {
if r.extras() != requirement.extras {
return false;
}
true
}
(None, _) => false,
}
}
Expand Down
89 changes: 88 additions & 1 deletion tests/add_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::common::{
};
use pixi::{DependencyType, Project};
use pixi_consts::consts;
use pixi_manifest::{pypi::PyPiPackageName, FeaturesExt, SpecType};
use pixi_manifest::pypi::VersionOrStar;
use pixi_manifest::{pypi::PyPiPackageName, FeaturesExt, PyPiRequirement, SpecType};
use rattler_conda_types::{PackageName, Platform};
use serial_test::serial;
use tempfile::TempDir;
Expand Down Expand Up @@ -359,6 +360,92 @@ async fn add_pypi_functionality() {
));
}

/// Test the `pixi add --pypi` functionality with extras
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
#[cfg_attr(not(feature = "slow_integration_tests"), ignore)]
#[serial]
async fn add_pypi_extra_functionality() {
let pixi = PixiControl::new().unwrap();

pixi.init().await.unwrap();

// Add python
pixi.add("python")
.set_type(DependencyType::CondaDependency(SpecType::Run))
.with_install(false)
.await
.unwrap();

pixi.add("black")
.set_type(DependencyType::PypiDependency)
.with_install(true)
.await
.unwrap();

// Add dep with extra
pixi.add("black[cli]")
.set_type(DependencyType::PypiDependency)
.with_install(true)
.await
.unwrap();

// Check if the extras are added
let project = Project::from_path(pixi.manifest_path().as_path()).unwrap();
project
.default_environment()
.pypi_dependencies(None)
.into_specs()
.for_each(|(name, spec)| {
if name == PyPiPackageName::from_str("black").unwrap() {
assert_eq!(spec.extras(), &[ExtraName::from_str("cli").unwrap()]);
}
});

// Remove extras
pixi.add("black")
.set_type(DependencyType::PypiDependency)
.with_install(true)
.await
.unwrap();

// Check if the extras are removed
let project = Project::from_path(pixi.manifest_path().as_path()).unwrap();
project
.default_environment()
.pypi_dependencies(None)
.into_specs()
.for_each(|(name, spec)| {
if name == PyPiPackageName::from_str("black").unwrap() {
assert_eq!(spec.extras(), &[]);
}
});

// Add dep with extra and version
pixi.add("black[cli]==24.8.0")
.set_type(DependencyType::PypiDependency)
.with_install(true)
.await
.unwrap();

// Check if the extras added and the version is set
let project = Project::from_path(pixi.manifest_path().as_path()).unwrap();
project
.default_environment()
.pypi_dependencies(None)
.into_specs()
.for_each(|(name, spec)| {
if name == PyPiPackageName::from_str("black").unwrap() {
assert_eq!(
spec,
PyPiRequirement::Version {
version: VersionOrStar::from_str("==24.8.0").unwrap(),
extras: vec![ExtraName::from_str("cli").unwrap()],
}
);
}
});
}

/// Test the sdist support for pypi packages
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
#[cfg_attr(not(feature = "slow_integration_tests"), ignore)]
Expand Down

0 comments on commit 6fd6efe

Please sign in to comment.