From ee43bfb1ce2d27a0bdb3df8fc689bbbbbdc36bae Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Mon, 21 Oct 2024 12:50:14 -0500 Subject: [PATCH 1/2] include optional python_site_packages_path entry The IndexJson and PackageRecord struct include an optional python_site_packages_path field as specified in CEP-17. --- crates/rattler_conda_types/src/package/index.rs | 3 +++ crates/rattler_conda_types/src/repo_data/mod.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/crates/rattler_conda_types/src/package/index.rs b/crates/rattler_conda_types/src/package/index.rs index 585cac162..97d193fa5 100644 --- a/crates/rattler_conda_types/src/package/index.rs +++ b/crates/rattler_conda_types/src/package/index.rs @@ -55,6 +55,9 @@ pub struct IndexJson { /// Optionally, the OS the package is build for. pub platform: Option, + /// Optionally a path within the environment of the site-packages directory + pub python_site_packages_path: Option, + /// The subdirectory that contains this package pub subdir: Option, diff --git a/crates/rattler_conda_types/src/repo_data/mod.rs b/crates/rattler_conda_types/src/repo_data/mod.rs index bc3f00a82..9708a87cd 100644 --- a/crates/rattler_conda_types/src/repo_data/mod.rs +++ b/crates/rattler_conda_types/src/repo_data/mod.rs @@ -151,6 +151,9 @@ pub struct PackageRecord { #[serde(default, skip_serializing_if = "Option::is_none")] pub purls: Option>, + /// Optionally a path within the environment of the site-packages directory + pub python_site_packages_path: Option, + /// Run exports that are specified in the package. #[serde(default, skip_serializing_if = "Option::is_none")] pub run_exports: Option, @@ -294,6 +297,7 @@ impl PackageRecord { name, noarch: NoArchType::default(), platform: None, + python_site_packages_path: None, sha256: None, size: None, subdir: Platform::current().to_string(), @@ -412,6 +416,7 @@ impl PackageRecord { name: index.name, noarch: index.noarch, platform: index.platform, + python_site_packages_path: index.python_site_packages_path, sha256, size, subdir, From 46eaf2a994d8f93f0b57eafcd824563f0fc57d60 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Mon, 21 Oct 2024 12:52:03 -0500 Subject: [PATCH 2/2] Use python_site_packages_path form repodata When specified in the packages repodata entry, use the "python_site_packages_path" field for the location of the site_packages_path. --- crates/rattler/src/install/python.rs | 13 ++++++++----- crates/rattler/src/install/transaction.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/rattler/src/install/python.rs b/crates/rattler/src/install/python.rs index 116c57251..52560e448 100644 --- a/crates/rattler/src/install/python.rs +++ b/crates/rattler/src/install/python.rs @@ -31,7 +31,7 @@ pub enum PythonInfoError { impl PythonInfo { /// Build an instance based on the version of the python package and the platform it is /// installed for. - pub fn from_version(version: &Version, platform: Platform) -> Result { + pub fn from_version(version: &Version, sp_path: &Option, platform: Platform) -> Result { // Determine the major, and minor versions of the version let (major, minor) = version .as_major_minor() @@ -45,10 +45,13 @@ impl PythonInfo { }; // Find the location of the site packages - let site_packages_path = if platform.is_windows() { - PathBuf::from("Lib/site-packages") - } else { - PathBuf::from(format!("lib/python{major}.{minor}/site-packages")) + let site_packages_path = match sp_path { + Some(sp_path) => PathBuf::from(sp_path), + None => if platform.is_windows() { + PathBuf::from("Lib/site-packages") + } else { + PathBuf::from(format!("lib/python{major}.{minor}/site-packages")) + }, }; // Binary directory diff --git a/crates/rattler/src/install/transaction.rs b/crates/rattler/src/install/transaction.rs index df8f85a66..bb4194dea 100644 --- a/crates/rattler/src/install/transaction.rs +++ b/crates/rattler/src/install/transaction.rs @@ -199,7 +199,7 @@ fn find_python_info( records .into_iter() .find(|r| is_python_record(r.as_ref())) - .map(|record| PythonInfo::from_version(&record.as_ref().version, platform)) + .map(|record| PythonInfo::from_version(&record.as_ref().version, &record.as_ref().python_site_packages_path, platform)) .map_or(Ok(None), |info| info.map(Some)) }