Skip to content

chore: refactor PixiSpec to distinguish binary vs source packages at type level - #6184

Closed
wolfv wants to merge 2 commits into
mainfrom
claude/bold-mccarthy-aYhrj
Closed

wolfv wants to merge 2 commits into
mainfrom
claude/bold-mccarthy-aYhrj

Conversation

@wolfv

@wolfv wolfv commented May 22, 2026

Copy link
Copy Markdown
Member

Description

This PR refactors the PixiSpec enum to encode the binary-vs-source distinction at the type level rather than via runtime URL/path inspection. Previously, PixiSpec had variants like Url and Path that could represent either binary or source packages depending on the file extension. Now it has six distinct variants:

  • Detailed — bare version string or detailed channel-based binary spec (replaces Version and DetailedVersion)
  • UrlBinary — URL pointing at a binary conda archive (.conda / .tar.bz2)
  • PathBinary — local path pointing at a binary conda archive
  • UrlSource — URL pointing at a source archive with optional matchspec selectors
  • PathSource — local directory or source path with optional matchspec selectors
  • Git — git repository with optional matchspec selectors

Key changes:

  1. New MatchspecFields type: Extracted matchspec selector fields (version, build, build_number, extras, flags, subdir, license, license_family, condition, track_features) into a dedicated struct that decorates source-side specs. Binary variants do not carry these fields since a .conda archive is already fully-specified.

  2. Binary-specific fields remain on DetailedSpec/UrlBinarySpec/PathBinarySpec: Fields like file-name, channel, md5, sha256 stay on binary specs where they make sense.

  3. Improved validation: The TOML parser now detects whether a URL/path points to a binary archive by file extension and enforces that matchspec fields are only used with source locations.

  4. Serialization optimization: Detailed specs carrying only a version field collapse back to bare version strings during serialization to preserve the on-disk format (foo = ">=1" instead of foo = { version = ">=1" }).

  5. Updated GitSpec and related types: GitSpec now carries MatchspecFields and has a constructor method GitSpec::new().

This change improves type safety by making it impossible to accidentally apply matchspec selectors to binary packages, and clarifies the semantics of each spec variant.

How Has This Been Tested?

  • Existing snapshot tests updated to reflect new variant names and serialization behavior
  • TOML round-trip tests verify that specs serialize and deserialize correctly
  • Validation tests confirm that matchspec fields are rejected for binary archives
  • All existing tests pass with the refactored types

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (crate-level docs updated)
  • Snapshot tests updated to reflect new behavior

https://claude.ai/code/session_01677F3pUX6QVNCtikszPRUn

@wolfv wolfv changed the title Refactor PixiSpec to distinguish binary vs source packages at type level chore: refactor PixiSpec to distinguish binary vs source packages at type level May 22, 2026
@Hofer-Julian Hofer-Julian self-assigned this May 26, 2026
license_family,
extras,
flags,
track_features,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not add track_features and license_family as those are deprecated.

Comment on lines +404 to +423
// A bare version with no other fields collapses to "upgrade to
// anything"; preserve the old `PixiSpec::Version(_)` shortcut so
// we don't carry over a single `version` constraint as if it
// were a detailed selector.
let is_bare_version_only = detailed.build.is_none()
&& detailed.build_number.is_none()
&& detailed.file_name.is_none()
&& detailed.extras.is_none()
&& detailed.flags.is_none()
&& detailed.channel.is_none()
&& detailed.subdir.is_none()
&& detailed.md5.is_none()
&& detailed.sha256.is_none()
&& detailed.license.is_none()
&& detailed.license_family.is_none()
&& detailed.condition.is_none()
&& detailed.track_features.is_none();
if is_bare_version_only {
return Some((name.clone(), (MatchSpec::from(name), spec_type)));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make this a function on detailed

/// version spec.
Version(VersionSpec),
/// A bare version string or a detailed channel-based binary spec.
Detailed(Box<DetailedSpec>),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to bring back Version, because { version = "*" } might not be the same as "*".

/// constraints that apply to the built output transitively.
#[derive(Debug, Clone, Hash, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum SourceLocationSpec {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should improve this part, the SourceLocationSpec now also includes the matchspec fields, so "Location" is a bit of a misnomer here. I think we should either call this just SourceSpec or we make SourceSpec a struct with MatchSpecFields and a location.

@Hofer-Julian
Hofer-Julian force-pushed the claude/bold-mccarthy-aYhrj branch 2 times, most recently from 912426c to 827a388 Compare May 28, 2026 12:45
@Hofer-Julian
Hofer-Julian force-pushed the claude/bold-mccarthy-aYhrj branch from d97eb21 to 4983637 Compare May 28, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants