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

feat: use python_site_packages_path field when available for installing noarch: python packages, CEP-17 #909

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions crates/rattler/src/install/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
InvalidVersion(String),
}

impl PythonInfo {

Check warning on line 31 in crates/rattler/src/install/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/python.rs
/// 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<Self, PythonInfoError> {
pub fn from_version(version: &Version, sp_path: &Option<String>, platform: Platform) -> Result<Self, PythonInfoError> {
// Determine the major, and minor versions of the version
let (major, minor) = version
.as_major_minor()
Expand All @@ -44,11 +44,14 @@
PathBuf::from(format!("bin/python{major}.{minor}"))
};

// Find the location of the site packages

Check warning on line 47 in crates/rattler/src/install/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/python.rs
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
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler/src/install/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@
records: impl IntoIterator<Item = impl AsRef<PackageRecord>>,
platform: Platform,
) -> Result<Option<PythonInfo>, PythonInfoError> {
records

Check warning on line 199 in crates/rattler/src/install/transaction.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler/src/install/transaction.rs
.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))
}

Expand Down
3 changes: 3 additions & 0 deletions crates/rattler_conda_types/src/package/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub struct IndexJson {
/// Optionally, the OS the package is build for.
pub platform: Option<String>,

/// Optionally a path within the environment of the site-packages directory
pub python_site_packages_path: Option<String>,

/// The subdirectory that contains this package
pub subdir: Option<String>,

Expand Down
5 changes: 5 additions & 0 deletions crates/rattler_conda_types/src/repo_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ pub struct PackageRecord {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub purls: Option<BTreeSet<PackageUrl>>,

/// Optionally a path within the environment of the site-packages directory
pub python_site_packages_path: Option<String>,

/// Run exports that are specified in the package.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub run_exports: Option<RunExportsJson>,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
Loading