|
1 | | -use std::io::Write; |
| 1 | +use std::{fs::File, io::Write, str::FromStr}; |
2 | 2 |
|
| 3 | +use pep508_rs::Requirement; |
3 | 4 | use rattler_conda_types::Platform; |
4 | 5 | use tempfile::tempdir; |
5 | 6 | use typed_path::Utf8TypedPath; |
6 | 7 |
|
7 | 8 | use crate::common::pypi_index::{Database as PyPIDatabase, PyPIPackage}; |
8 | | -use crate::common::{LockFileExt, PixiControl}; |
| 9 | +use crate::common::{ |
| 10 | + LockFileExt, PixiControl, |
| 11 | + package_database::{Package, PackageDatabase}, |
| 12 | +}; |
9 | 13 | use crate::setup_tracing; |
10 | | -use std::fs::File; |
| 14 | + |
| 15 | +/// This tests if we can resolve pyproject optional dependencies recursively |
| 16 | +/// before when running `pixi list -e all`, this would have not included numpy |
| 17 | +/// we are now explicitly testing that this works |
| 18 | +#[tokio::test] |
| 19 | +async fn pyproject_optional_dependencies_resolve_recursively() { |
| 20 | + setup_tracing(); |
| 21 | + |
| 22 | + let simple = PyPIDatabase::new() |
| 23 | + .with(PyPIPackage::new("numpy", "1.0.0")) |
| 24 | + .with(PyPIPackage::new("sphinx", "1.0.0")) |
| 25 | + .with(PyPIPackage::new("pytest", "1.0.0")) |
| 26 | + .into_simple_index() |
| 27 | + .unwrap(); |
| 28 | + |
| 29 | + let platform = Platform::current(); |
| 30 | + let platform_str = platform.to_string(); |
| 31 | + |
| 32 | + let mut package_db = PackageDatabase::default(); |
| 33 | + package_db.add_package( |
| 34 | + Package::build("python", "3.11.0") |
| 35 | + .with_subdir(platform) |
| 36 | + .finish(), |
| 37 | + ); |
| 38 | + let channel = package_db.into_channel().await.unwrap(); |
| 39 | + let channel_url = channel.url(); |
| 40 | + let index_url = simple.index_url(); |
| 41 | + |
| 42 | + let pyproject = format!( |
| 43 | + r#" |
| 44 | +[build-system] |
| 45 | +requires = ["setuptools"] |
| 46 | +build-backend = "setuptools.build_meta" |
| 47 | +
|
| 48 | +[project] |
| 49 | +name = "recursive-optional-groups" |
| 50 | +
|
| 51 | +[project.optional-dependencies] |
| 52 | +np = ["numpy"] |
| 53 | +all = ["recursive-optional-groups[np]"] |
| 54 | +
|
| 55 | +[dependency-groups] |
| 56 | +docs = ["sphinx"] |
| 57 | +test = ["recursive-optional-groups[np]", "pytest", {{include-group = "docs"}}] |
| 58 | +
|
| 59 | +[tool.pixi.project] |
| 60 | +channels = ["{channel_url}"] |
| 61 | +platforms = ["{platform}"] |
| 62 | +
|
| 63 | +[tool.pixi.dependencies] |
| 64 | +python = "==3.11.0" |
| 65 | +
|
| 66 | +[tool.pixi.pypi-options] |
| 67 | +index-url = "{index_url}" |
| 68 | +
|
| 69 | +[tool.pixi.environments] |
| 70 | +np = {{features = ["np"]}} |
| 71 | +all = {{features = ["all"]}} |
| 72 | +test = {{features = ["test"]}} |
| 73 | +"#, |
| 74 | + platform = platform_str, |
| 75 | + channel_url = channel_url, |
| 76 | + index_url = index_url, |
| 77 | + ); |
| 78 | + |
| 79 | + let pixi = PixiControl::from_pyproject_manifest(&pyproject).unwrap(); |
| 80 | + |
| 81 | + let lock = pixi.update_lock_file().await.unwrap(); |
| 82 | + |
| 83 | + let numpy_req = Requirement::from_str("numpy").unwrap(); |
| 84 | + let sphinx_req = Requirement::from_str("sphinx").unwrap(); |
| 85 | + assert!( |
| 86 | + lock.contains_pep508_requirement("np", platform, numpy_req.clone()), |
| 87 | + "np environment should include numpy from optional dependencies" |
| 88 | + ); |
| 89 | + assert!( |
| 90 | + lock.contains_pep508_requirement("all", platform, numpy_req.clone()), |
| 91 | + "all environment should include numpy inherited from recursive optional dependency" |
| 92 | + ); |
| 93 | + assert!( |
| 94 | + lock.contains_pep508_requirement("test", platform, numpy_req), |
| 95 | + "test environment should include numpy inherited from recursive optional dependency" |
| 96 | + ); |
| 97 | + assert!( |
| 98 | + lock.contains_pep508_requirement("test", platform, sphinx_req), |
| 99 | + "test environment should include sphinx inherited from recursive dependency group" |
| 100 | + ); |
| 101 | +} |
11 | 102 |
|
12 | 103 | #[tokio::test] |
13 | 104 | #[cfg_attr(not(feature = "slow_integration_tests"), ignore)] |
|
0 commit comments