Skip to content

Commit

Permalink
fix: Noarch python packages not installable (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw authored Dec 2, 2024
1 parent f32c95a commit 505203b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use rattler::install::{link_package, InstallDriver, InstallOptions};
use rattler::install::{link_package, InstallDriver, InstallOptions, PythonInfo};
use rattler_conda_types::{prefix_record::PathsEntry, PackageRecord, PrefixRecord, RepoDataRecord};
use rattler_package_streaming::fs::extract;
use std::{
Expand Down Expand Up @@ -123,7 +123,24 @@ pub async fn pixi_inject(target_prefix: PathBuf, packages: Vec<PathBuf>) -> Resu
);

let driver = InstallDriver::default();
let options = InstallOptions::default();
let python_info = if installed_package_names.contains("python") {
Some(PythonInfo::from_python_record(
&installed_packages
.iter()
.find(|&p| p.repodata_record.package_record.name.as_normalized() == "python")
.context("Could not find python package in installed packages")?
.repodata_record
.package_record
.clone(),
Platform::current(),
)?)
} else {
None
};
let options = InstallOptions {
python_info,
..Default::default()
};

for (path, package_record) in injected_packages.iter() {
let repodata_record = RepoDataRecord {
Expand Down
25 changes: 25 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ fn required_fs_objects() -> Vec<&'static str> {
]
}

#[rstest]
#[tokio::test]
async fn test_noarch_python(options: Options) {
pixi_inject::pixi_inject(
options.prefix.clone(),
vec!["tests/resources/packages/setuptools-75.6.0-pyhff2d567_1.conda".into()],
)
.await
.unwrap();

#[cfg(not(unix))]
let required_fs_objects = vec![
"Lib\\site-packages\\setuptools\\__init__.py",
"Lib\\site-packages\\pkg_resources\\__init__.py",
];
#[cfg(unix)]
let required_fs_objects = vec![
"lib/python3.13/site-packages/setuptools/__init__.py",
"lib/python3.13/site-packages/pkg_resources/__init__.py",
];
for fs_object in required_fs_objects {
assert!(options.prefix.join(fs_object).exists());
}
}

#[rstest]
#[tokio::test]
async fn test_simple_example(options: Options, required_fs_objects: Vec<&'static str>) {
Expand Down
Binary file not shown.

0 comments on commit 505203b

Please sign in to comment.