Skip to content
Merged
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
8 changes: 4 additions & 4 deletions crates/pixi_build_type_conversions/src/project_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ fn to_pixi_spec_v1(
// Convert into correct type for pixi
let pbt_spec = match source_or_binary {
itertools::Either::Left(source) => {
let source = match source {
pixi_spec::SourceSpec::Url(url_source_spec) => {
let source = match source.location {
pixi_spec::SourceLocationSpec::Url(url_source_spec) => {
let pixi_spec::UrlSourceSpec { url, md5, sha256 } = url_source_spec;
pbt::SourcePackageSpecV1::Url(pbt::UrlSpecV1 { url, md5, sha256 })
}
pixi_spec::SourceSpec::Git(git_spec) => {
pixi_spec::SourceLocationSpec::Git(git_spec) => {
let pixi_spec::GitSpec {
git,
rev,
Expand All @@ -50,7 +50,7 @@ fn to_pixi_spec_v1(
subdirectory,
})
}
pixi_spec::SourceSpec::Path(path_source_spec) => {
pixi_spec::SourceLocationSpec::Path(path_source_spec) => {
pbt::SourcePackageSpecV1::Path(pbt::PathSpecV1 {
path: path_source_spec.path.to_string(),
})
Expand Down
58 changes: 32 additions & 26 deletions crates/pixi_command_dispatcher/src/build/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,44 @@ use pixi_build_types::{
BinaryPackageSpecV1, CondaPackageMetadata, PackageSpecV1, SourcePackageSpecV1,
};
use pixi_record::{InputHash, PinnedSourceSpec, SourceRecord};
use pixi_spec::{BinarySpec, DetailedSpec, UrlBinarySpec};
use pixi_spec::{BinarySpec, DetailedSpec, SourceLocationSpec, UrlBinarySpec};
use rattler_conda_types::{NamedChannelOrUrl, PackageName, PackageRecord};

/// Converts a [`SourcePackageSpecV1`] to a [`pixi_spec::SourceSpec`].
pub fn from_source_spec_v1(source: SourcePackageSpecV1) -> pixi_spec::SourceSpec {
match source {
SourcePackageSpecV1::Url(url) => pixi_spec::SourceSpec::Url(pixi_spec::UrlSourceSpec {
url: url.url,
md5: url.md5,
sha256: url.sha256,
}),
SourcePackageSpecV1::Git(git) => pixi_spec::SourceSpec::Git(pixi_spec::GitSpec {
git: git.git,
rev: git.rev.map(|r| match r {
pixi_build_frontend::types::GitReferenceV1::Branch(b) => {
pixi_spec::GitReference::Branch(b)
}
pixi_build_frontend::types::GitReferenceV1::Tag(t) => {
pixi_spec::GitReference::Tag(t)
}
pixi_build_frontend::types::GitReferenceV1::Rev(rev) => {
pixi_spec::GitReference::Rev(rev)
}
pixi_build_frontend::types::GitReferenceV1::DefaultBranch => {
pixi_spec::GitReference::DefaultBranch
}
SourcePackageSpecV1::Url(url) => pixi_spec::SourceSpec {
location: SourceLocationSpec::Url(pixi_spec::UrlSourceSpec {
url: url.url,
md5: url.md5,
sha256: url.sha256,
}),
subdirectory: git.subdirectory,
}),
SourcePackageSpecV1::Path(path) => pixi_spec::SourceSpec::Path(pixi_spec::PathSourceSpec {
path: path.path.into(),
}),
},
SourcePackageSpecV1::Git(git) => pixi_spec::SourceSpec {
location: SourceLocationSpec::Git(pixi_spec::GitSpec {
git: git.git,
rev: git.rev.map(|r| match r {
pixi_build_frontend::types::GitReferenceV1::Branch(b) => {
pixi_spec::GitReference::Branch(b)
}
pixi_build_frontend::types::GitReferenceV1::Tag(t) => {
pixi_spec::GitReference::Tag(t)
}
pixi_build_frontend::types::GitReferenceV1::Rev(rev) => {
pixi_spec::GitReference::Rev(rev)
}
pixi_build_frontend::types::GitReferenceV1::DefaultBranch => {
pixi_spec::GitReference::DefaultBranch
}
}),
subdirectory: git.subdirectory,
}),
},
SourcePackageSpecV1::Path(path) => pixi_spec::SourceSpec {
location: SourceLocationSpec::Path(pixi_spec::PathSourceSpec {
path: path.path.into(),
}),
},
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/pixi_command_dispatcher/src/command_dispatcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use pixi_build_frontend::BackendOverride;
use pixi_git::resolver::GitResolver;
use pixi_glob::GlobHashCache;
use pixi_record::{PinnedPathSpec, PinnedSourceSpec, PixiRecord};
use pixi_spec::SourceSpec;
use pixi_spec::{SourceLocationSpec, SourceSpec};
use rattler::package_cache::PackageCache;
use rattler_conda_types::{GenericVirtualPackage, Platform};
use rattler_repodata_gateway::Gateway;
Expand Down Expand Up @@ -545,11 +545,11 @@ impl CommandDispatcher {
&self,
source_spec: SourceSpec,
) -> Result<SourceCheckout, CommandDispatcherError<SourceCheckoutError>> {
match source_spec {
SourceSpec::Url(url) => {
match source_spec.location {
SourceLocationSpec::Url(url) => {
unimplemented!("fetching URL sources ({}) is not yet implemented", url.url)
}
SourceSpec::Path(path) => {
SourceLocationSpec::Path(path) => {
let source_path = self
.data
.resolve_typed_path(path.path.to_path())
Expand All @@ -560,7 +560,7 @@ impl CommandDispatcher {
pinned: PinnedSourceSpec::Path(PinnedPathSpec { path: path.path }),
})
}
SourceSpec::Git(git_spec) => self.pin_and_checkout_git(git_spec).await,
SourceLocationSpec::Git(git_spec) => self.pin_and_checkout_git(git_spec).await,
}
}

Expand Down
30 changes: 22 additions & 8 deletions crates/pixi_record/src/pinned_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use pixi_git::{
sha::GitSha,
url::{RepositoryUrl, redact_credentials},
};
use pixi_spec::{GitReference, GitSpec, PathSourceSpec, SourceSpec, UrlSourceSpec};
use pixi_spec::{
GitReference, GitSpec, PathSourceSpec, SourceLocationSpec, SourceSpec, UrlSourceSpec,
};
use rattler_digest::{Md5Hash, Sha256Hash};
use rattler_lock::UrlOrPath;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -694,10 +696,16 @@ impl PinnedSourceSpec {
#[allow(clippy::result_large_err)]
/// Verifies if the locked source satisfies the requested source.
pub fn satisfies(&self, spec: &SourceSpec) -> Result<(), SourceMismatchError> {
match (self, spec) {
(PinnedSourceSpec::Path(locked), SourceSpec::Path(spec)) => locked.satisfies(spec),
(PinnedSourceSpec::Url(locked), SourceSpec::Url(spec)) => locked.satisfies(spec),
(PinnedSourceSpec::Git(locked), SourceSpec::Git(spec)) => locked.satisfies(spec),
match (self, &spec.location) {
(PinnedSourceSpec::Path(locked), SourceLocationSpec::Path(spec)) => {
locked.satisfies(spec)
}
(PinnedSourceSpec::Url(locked), SourceLocationSpec::Url(spec)) => {
locked.satisfies(spec)
}
(PinnedSourceSpec::Git(locked), SourceLocationSpec::Git(spec)) => {
locked.satisfies(spec)
}
(_, _) => Err(SourceMismatchError::SourceTypeMismatch),
}
}
Expand Down Expand Up @@ -734,9 +742,15 @@ impl Display for PinnedGitSpec {
impl From<PinnedSourceSpec> for SourceSpec {
fn from(value: PinnedSourceSpec) -> Self {
match value {
PinnedSourceSpec::Url(url) => SourceSpec::Url(url.into()),
PinnedSourceSpec::Git(git) => SourceSpec::Git(git.into()),
PinnedSourceSpec::Path(path) => SourceSpec::Path(path.into()),
PinnedSourceSpec::Url(url) => SourceSpec {
location: SourceLocationSpec::Url(url.into()),
},
PinnedSourceSpec::Git(git) => SourceSpec {
location: SourceLocationSpec::Git(git.into()),
},
PinnedSourceSpec::Path(path) => SourceSpec {
location: SourceLocationSpec::Path(path.into()),
},
}
}
}
Expand Down
73 changes: 49 additions & 24 deletions crates/pixi_spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,18 @@ impl PixiSpec {
}
PixiSpec::Url(url) => url
.into_source_or_binary()
.map_left(SourceSpec::Url)
.map_left(|url| SourceSpec {
location: SourceLocationSpec::Url(url),
})
.map_right(BinarySpec::Url),
PixiSpec::Git(git) => Either::Left(SourceSpec::Git(git)),
PixiSpec::Git(git) => Either::Left(SourceSpec {
location: SourceLocationSpec::Git(git),
}),
PixiSpec::Path(path) => path
.into_source_or_binary()
.map_left(SourceSpec::Path)
.map_left(|path| SourceSpec {
location: SourceLocationSpec::Path(path),
})
.map_right(BinarySpec::Path),
}
}
Expand All @@ -302,7 +308,9 @@ impl PixiSpec {
.try_into_source_url()
.map(SourceSpec::from)
.map_err(PixiSpec::from),
PixiSpec::Git(git) => Ok(SourceSpec::Git(git)),
PixiSpec::Git(git) => Ok(SourceSpec {
location: SourceLocationSpec::Git(git),
}),
PixiSpec::Path(path) => path
.try_into_source_path()
.map(SourceSpec::from)
Expand Down Expand Up @@ -339,8 +347,15 @@ impl PixiSpec {
/// This type only represents source packages. Use [`PixiSpec`] to represent
/// both binary and source packages.
#[derive(Debug, Clone, Hash, PartialEq, Eq, serde::Serialize)]
pub struct SourceSpec {
/// The location of the source.
pub location: SourceLocationSpec,
}

/// A specification for a source location.
#[derive(Debug, Clone, Hash, PartialEq, Eq, serde::Serialize)]
#[serde(untagged)]
pub enum SourceSpec {
pub enum SourceLocationSpec {
/// The spec is represented as an archive that can be downloaded from the
/// specified URL.
Url(UrlSourceSpec),
Expand All @@ -354,18 +369,18 @@ pub enum SourceSpec {

impl Display for SourceSpec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SourceSpec::Url(url) => write!(f, "{}", url),
SourceSpec::Git(git) => write!(f, "{}", git),
SourceSpec::Path(path) => write!(f, "{}", path),
match &self.location {
SourceLocationSpec::Url(url) => write!(f, "{}", url),
SourceLocationSpec::Git(git) => write!(f, "{}", git),
SourceLocationSpec::Path(path) => write!(f, "{}", path),
}
}
}

impl SourceSpec {
/// Returns true if this spec represents a git repository.
pub fn is_git(&self) -> bool {
matches!(self, Self::Git(_))
matches!(self.location, SourceLocationSpec::Git(_))
}

/// Convert this instance into a nameless match spec.
Expand All @@ -375,17 +390,17 @@ impl SourceSpec {

/// Converts this instance into a [`toml_edit::Value`].
pub fn to_toml_value(&self) -> toml_edit::Value {
::serde::Serialize::serialize(self, toml_edit::ser::ValueSerializer::new())
::serde::Serialize::serialize(&self.location, toml_edit::ser::ValueSerializer::new())
.expect("conversion to toml cannot fail")
}
}

impl From<SourceSpec> for PixiSpec {
fn from(value: SourceSpec) -> Self {
match value {
SourceSpec::Url(url) => Self::Url(url.into()),
SourceSpec::Git(git) => Self::Git(git),
SourceSpec::Path(path) => Self::Path(path.into()),
match value.location {
SourceLocationSpec::Url(url) => Self::Url(url.into()),
SourceLocationSpec::Git(git) => Self::Git(git),
SourceLocationSpec::Path(path) => Self::Path(path.into()),
}
}
}
Expand All @@ -404,7 +419,9 @@ impl From<UrlSpec> for PixiSpec {

impl From<UrlSourceSpec> for SourceSpec {
fn from(value: UrlSourceSpec) -> Self {
SourceSpec::Url(value)
Self {
location: SourceLocationSpec::Url(value),
}
}
}

Expand All @@ -422,7 +439,9 @@ impl From<PathSpec> for PixiSpec {

impl From<PathSourceSpec> for SourceSpec {
fn from(value: PathSourceSpec) -> Self {
Self::Path(value)
Self {
location: SourceLocationSpec::Path(value),
}
}
}

Expand Down Expand Up @@ -507,20 +526,26 @@ impl From<VersionSpec> for BinarySpec {
impl From<rattler_lock::source::SourceLocation> for SourceSpec {
fn from(value: rattler_lock::source::SourceLocation) -> Self {
match value {
rattler_lock::source::SourceLocation::Url(url) => Self::Url(url.into()),
rattler_lock::source::SourceLocation::Git(git) => Self::Git(git.into()),
rattler_lock::source::SourceLocation::Path(path) => Self::Path(path.into()),
rattler_lock::source::SourceLocation::Url(url) => Self {
location: SourceLocationSpec::Url(url.into()),
},
rattler_lock::source::SourceLocation::Git(git) => Self {
location: SourceLocationSpec::Git(git.into()),
},
rattler_lock::source::SourceLocation::Path(path) => Self {
location: SourceLocationSpec::Path(path.into()),
},
}
}
}

#[cfg(feature = "rattler_lock")]
impl From<SourceSpec> for rattler_lock::source::SourceLocation {
fn from(value: SourceSpec) -> Self {
match value {
SourceSpec::Url(url) => Self::Url(url.into()),
SourceSpec::Git(git) => Self::Git(git.into()),
SourceSpec::Path(path) => Self::Path(path.into()),
match value.location {
SourceLocationSpec::Url(url) => Self::Url(url.into()),
SourceLocationSpec::Git(git) => Self::Git(git.into()),
SourceLocationSpec::Path(path) => Self::Path(path.into()),
}
}
}
Expand Down
Loading
Loading