Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pixi add with more than just package name and version #1704

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion crates/pixi_manifest/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl Target {
) {
// TODO: add proper error handling for this
let mut pypi_requirement = PyPiRequirement::try_from(requirement.clone())
.expect("could not convert pep508 requirm");
.expect("could not convert pep508 requirement");
if let Some(editable) = editable {
pypi_requirement.set_editable(editable);
}
Expand Down
8 changes: 4 additions & 4 deletions src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ fn update_pypi_specs_from_lock_file(
let pinning_strategy = project.config().pinning_strategy.unwrap_or_default();

// Determine the versions of the packages in the lock-file
for (name, _) in pypi_specs_to_add_constraints_for {
for (name, req) in pypi_specs_to_add_constraints_for {
let version_constraint = pinning_strategy.determine_version_constraint(
pypi_records
.iter()
Expand All @@ -419,10 +419,10 @@ fn update_pypi_specs_from_lock_file(
project.manifest.add_pypi_dependency(
&Requirement {
name: name.as_normalized().clone(),
extras: vec![],
extras: req.extras,
version_or_url: Some(VersionSpecifier(version_spec)),
marker: None,
origin: None,
marker: req.marker,
origin: req.origin,
},
platforms,
feature_name,
Expand Down
47 changes: 36 additions & 11 deletions tests/add_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use crate::common::builders::HasDependencyConfig;
use crate::common::package_database::{Package, PackageDatabase};
use crate::common::LockFileExt;
use crate::common::PixiControl;
use pixi::{DependencyType, HasFeatures};
use pixi::{DependencyType, HasFeatures, Project};
use pixi_consts::consts;
use pixi_manifest::pypi::PyPiPackageName;
use pixi_manifest::SpecType;
use rattler_conda_types::{PackageName, Platform};
use serial_test::serial;
use std::str::FromStr;
use tempfile::TempDir;
use uv_normalize::ExtraName;

/// Test add functionality for different types of packages.
/// Run, dev, build
Expand Down Expand Up @@ -232,14 +234,27 @@ async fn add_pypi_functionality() {
.await
.unwrap();

// Add a pypi package to a target
pixi.add("pytest[all]")
// Add a pypi package to a target with extras
pixi.add("pytest[dev]==8.3.2")
.set_type(DependencyType::PypiDependency)
.set_platforms(&[Platform::Linux64])
.with_install(true)
.await
.unwrap();

// Read project from file and check if the dev 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("pytest").unwrap() {
assert_eq!(spec.extras(), &[ExtraName::from_str("dev").unwrap()]);
}
});

// Test all the added packages are in the lock file
let lock = pixi.lock_file().await.unwrap();
assert!(lock.contains_pypi_package(
consts::DEFAULT_ENVIRONMENT_NAME,
Expand All @@ -254,16 +269,22 @@ async fn add_pypi_functionality() {
assert!(lock.contains_pep508_requirement(
consts::DEFAULT_ENVIRONMENT_NAME,
Platform::Linux64,
pep508_rs::Requirement::from_str("pytest[all]").unwrap(),
pep508_rs::Requirement::from_str("pytest").unwrap(),
));
// Test that the dev extras are added, mock is a test dependency of `pytest==8.3.2`
assert!(lock.contains_pep508_requirement(
consts::DEFAULT_ENVIRONMENT_NAME,
Platform::Linux64,
pep508_rs::Requirement::from_str("mock").unwrap(),
));

// Add a pypi package with a git url
// pixi.add("requests @ git+https://github.com/psf/requests.git")
// .set_type(DependencyType::PypiDependency)
// .set_platforms(&[Platform::Linux64])
// .with_install(true)
// .await
// .unwrap();
pixi.add("requests @ git+https://github.com/psf/requests.git")
.set_type(DependencyType::PypiDependency)
.set_platforms(&[Platform::Linux64])
.with_install(true)
.await
.unwrap();

pixi.add("isort @ git+https://github.com/PyCQA/isort@c655831799765e9593989ee12faba13b6ca391a5")
.set_type(DependencyType::PypiDependency)
Expand All @@ -280,7 +301,11 @@ async fn add_pypi_functionality() {
.unwrap();

let lock = pixi.lock_file().await.unwrap();
// assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, "requests"));
assert!(lock.contains_pypi_package(
consts::DEFAULT_ENVIRONMENT_NAME,
Platform::Linux64,
"requests"
));
assert!(lock.contains_pypi_package(
consts::DEFAULT_ENVIRONMENT_NAME,
Platform::Linux64,
Expand Down
Loading