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

refactor!: lock-file API #942

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6dcd1f7
Merge remote-tracking branch 'upstream/main' into feat/pixi-build
baszalmstra Nov 14, 2024
573d6ff
feat: source dependencies are seperated
baszalmstra Nov 14, 2024
4cafa0c
wip python bindings
baszalmstra Nov 14, 2024
60069f8
refactor: python API for lock files
baszalmstra Nov 15, 2024
db4e3c6
fix: docs issue
baszalmstra Nov 15, 2024
b94c922
fix: formatting issue
baszalmstra Nov 15, 2024
4e22eda
fix: formatting
baszalmstra Nov 15, 2024
d80e9ff
Merge remote-tracking branch 'upstream/feat/pixi-build' into refactor…
baszalmstra Nov 15, 2024
c6327ad
fix: remove unused snapshot
baszalmstra Nov 15, 2024
7556a97
Merge remote-tracking branch 'upstream/feat/pixi-build' into refactor…
baszalmstra Nov 18, 2024
e38ff40
fix: expose source and binary type
baszalmstra Nov 18, 2024
07d9d49
fix: expose source and binary type
baszalmstra Nov 18, 2024
bdf3bfc
fix: add into methods for conda package
baszalmstra Nov 18, 2024
0cd43f9
feat: add struct docs and return lock file from environment
baszalmstra Nov 18, 2024
1eb3ee4
Merge remote-tracking branch 'upstream/feat/pixi-build' into refactor…
baszalmstra Nov 18, 2024
ba9df05
fix: add same accessors
baszalmstra Nov 18, 2024
7534d3e
fix: allow serializing package data directly
baszalmstra Nov 18, 2024
1114c01
fix: derive build number for number only build string
baszalmstra Nov 18, 2024
8f81669
fix: clippy issues
baszalmstra Nov 18, 2024
712cff4
fix: update snapshots
baszalmstra Nov 18, 2024
7e79a81
fix: bring back satisfies for conda package
baszalmstra Nov 18, 2024
8cab691
fix: add satisfies to python bindings
baszalmstra Nov 18, 2024
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
6 changes: 3 additions & 3 deletions crates/rattler-bin/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ pub async fn create(opt: Opt) -> anyhow::Result<()> {
/// Prints the operations of the transaction to the console.
fn print_transaction(transaction: &Transaction<PrefixRecord, RepoDataRecord>) {
let format_record = |r: &RepoDataRecord| {
let direct_url_print = if r.clone().channel.is_empty() {
r.url.as_str()
let direct_url_print = if let Some(channel) = &r.channel {
channel.clone()
} else {
""
String::new()
};

format!(
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ pub(crate) fn get_repodata_record(package_path: impl AsRef<std::path::Path>) ->
.unwrap()
.to_string(),
url: url::Url::from_file_path(package_path).unwrap(),
channel: "test".to_string(),
channel: Some(String::from("test")),
}
}
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/src/match_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ mod tests {
),
file_name: String::from("mamba-1.0-py37_0"),
url: url::Url::parse("https://mamba.io/mamba-1.0-py37_0.conda").unwrap(),
channel: String::from("mamba"),
channel: Some(String::from("mamba")),
};
let package_record = repodata_record.clone().package_record;

Expand Down
3 changes: 1 addition & 2 deletions crates/rattler_conda_types/src/repo_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ impl RepoData {
/// given the source of the data.
pub fn into_repo_data_records(self, channel: &Channel) -> Vec<RepoDataRecord> {
let mut records = Vec::with_capacity(self.packages.len() + self.conda_packages.len());
let channel_name = channel.canonical_name();
let base_url = self.base_url().map(ToOwned::to_owned);

// Determine the base_url of the channel
Expand All @@ -241,7 +240,7 @@ impl RepoData {
base_url.as_deref(),
&filename,
),
channel: channel_name.clone(),
channel: Some(channel.base_url.as_str().to_string()),
package_record,
file_name: filename,
});
Expand Down
3 changes: 2 additions & 1 deletion crates/rattler_conda_types/src/repo_data_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub struct RepoDataRecord {
/// String representation of the channel where the package comes from. This could be a URL but
/// it could also be a channel name. Personally I would always add the complete URL here to be
/// explicit about where the package came from.
pub channel: String,
/// TODO: Refactor this into `Source` which can be a "name", "channelurl", or "direct url".
pub channel: Option<String>,
}

impl AsRef<PackageRecord> for RepoDataRecord {
Expand Down
116 changes: 103 additions & 13 deletions crates/rattler_lock/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,106 @@ use pep508_rs::ExtraName;
use rattler_conda_types::Platform;

use crate::{
file_format_version::FileFormatVersion, Channel, CondaPackageData, EnvironmentData,
EnvironmentPackageData, LockFile, LockFileInner, Package, PypiIndexes, PypiPackageData,
PypiPackageEnvironmentData,
file_format_version::FileFormatVersion, Channel, CondaBinaryData, CondaPackageData,
CondaSourceData, EnvironmentData, EnvironmentPackageData, LockFile, LockFileInner,
LockedPackageRef, PypiIndexes, PypiPackageData, PypiPackageEnvironmentData, UrlOrPath,
};

/// Information about a single locked package in an environment.
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum LockedPackage {
/// A conda package
Conda(CondaPackageData),

/// A pypi package in an environment
Pypi(PypiPackageData, PypiPackageEnvironmentData),
}

impl From<LockedPackageRef<'_>> for LockedPackage {
fn from(value: LockedPackageRef<'_>) -> Self {
match value {
LockedPackageRef::Conda(data) => LockedPackage::Conda(data.clone()),
LockedPackageRef::Pypi(data, env) => LockedPackage::Pypi(data.clone(), env.clone()),
}
}
}

impl From<CondaPackageData> for LockedPackage {
fn from(value: CondaPackageData) -> Self {
LockedPackage::Conda(value)
}
}

impl From<(PypiPackageData, PypiPackageEnvironmentData)> for LockedPackage {
fn from((data, env): (PypiPackageData, PypiPackageEnvironmentData)) -> Self {
LockedPackage::Pypi(data, env)
}
}

impl LockedPackage {
/// Returns the name of the package as it occurs in the lock file. This
/// might not be the normalized name.
pub fn name(&self) -> &str {
match self {
LockedPackage::Conda(data) => data.record().name.as_source(),
LockedPackage::Pypi(data, _) => data.name.as_ref(),
}
}

/// Returns the location of the package.
pub fn location(&self) -> &UrlOrPath {
match self {
LockedPackage::Conda(data) => data.location(),
LockedPackage::Pypi(data, _) => &data.location,
}
}

/// Returns the conda package data if this is a conda package.
pub fn as_conda(&self) -> Option<&CondaPackageData> {
match self {
LockedPackage::Conda(data) => Some(data),
LockedPackage::Pypi(..) => None,
}
}

/// Returns the pypi package data if this is a pypi package.
pub fn as_pypi(&self) -> Option<(&PypiPackageData, &PypiPackageEnvironmentData)> {
match self {
LockedPackage::Conda(..) => None,
LockedPackage::Pypi(data, env) => Some((data, env)),
}
}

/// Returns the package as a binary conda package if this is a binary conda
/// package.
pub fn as_binary_conda(&self) -> Option<&CondaBinaryData> {
self.as_conda().and_then(CondaPackageData::as_binary)
}

/// Returns the package as a source conda package if this is a source conda
/// package.
pub fn as_source_conda(&self) -> Option<&CondaSourceData> {
self.as_conda().and_then(CondaPackageData::as_source)
}

/// Returns the conda package data if this is a conda package.
pub fn into_conda(self) -> Option<CondaPackageData> {
match self {
LockedPackage::Conda(data) => Some(data),
LockedPackage::Pypi(..) => None,
}
}

/// Returns the pypi package data if this is a pypi package.
pub fn into_pypi(self) -> Option<(PypiPackageData, PypiPackageEnvironmentData)> {
match self {
LockedPackage::Conda(..) => None,
LockedPackage::Pypi(data, env) => Some((data, env)),
}
}
}

/// A struct to incrementally build a lock-file.
#[derive(Default)]
pub struct LockFileBuilder {
Expand Down Expand Up @@ -162,7 +257,7 @@ impl LockFileBuilder {
mut self,
environment: impl Into<String>,
platform: Platform,
locked_package: Package,
locked_package: LockedPackage,
) -> Self {
self.add_package(environment, platform, locked_package);
self
Expand All @@ -174,18 +269,13 @@ impl LockFileBuilder {
&mut self,
environment: impl Into<String>,
platform: Platform,
locked_package: Package,
locked_package: LockedPackage,
) -> &mut Self {
match locked_package {
Package::Conda(p) => {
self.add_conda_package(environment, platform, p.package_data().clone())
LockedPackage::Conda(p) => self.add_conda_package(environment, platform, p),
LockedPackage::Pypi(data, env_data) => {
self.add_pypi_package(environment, platform, data, env_data)
}
Package::Pypi(p) => self.add_pypi_package(
environment,
platform,
p.package_data().clone(),
p.environment_data().clone(),
),
}
}

Expand Down
Loading