Skip to content

pixi.lock input: check the PyPI packages of a pixi environment - #251

Merged
patrickballard merged 5 commits into
mainfrom
fix-229-pixi-lock
Nov 12, 2026
Merged

patrickballard merged 5 commits into
mainfrom
fix-229-pixi-lock

Conversation

@patrickballard

@patrickballard patrickballard commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #229

Made with Claude Code.

wheelgap now reads pixi.lock and checks the PyPI packages of one pixi environment.

Supported lock versions: 6 and 7

rattler_lock's FileFormatVersion (crates/rattler_lock/src/file_format_version.rs in conda/rattler) defines versions 1 to 7, with 7 as the latest. pixi has written version 7 since 0.68.0 (2026-05-07). I looked at eight public pixi.lock files: matplotlib/ipympl, stanford-oval/WikiChat, pinellolab/CRISPResso2 and pyjanitor-devs/pandas_flavor are on v6; prefix-dev/pixi, conda/grayskull, ericmjl/nxviz and Quansight-Labs/uarray are on v7. wheelgap reads 6 and 7. Any other version is a SourceError naming the file. Versions 4 and 5 used a different package layout (kind: pypi), and any pixi lock with a current pixi rewrites them.

How pixi records PyPI packages, and what that means here

  • environments.<name>.packages.<platform> lists selectors (- pypi: <location>, - conda: <url>, and in v7 - conda_source: name[hash] @ path). Each selector points at a top-level packages: entry with the same location.
  • A PyPI entry has pypi: (a URL or path), name, version (in v7, missing for source/path packages), sha256/md5, requires_dist and requires_python. v6 can also have editable: true; v7 can have index: (written only when the index isn't PyPI) and build_packages/host_packages.
  • Each entry is one file: the distribution pixi picked for one platform, for the environment's conda Python and pixi's own glibc/macOS floors. A uv.lock lists every file of a release; a pixi.lock doesn't.

So the recorded filenames become the package's files, as the issue asks, but on their own they would give false gaps on any target the lock doesn't match exactly. Examples: a different Python, musl, or wheelgap's default glibc 2.36 against pixi's 2.28. So these packages are marked partial_files:

  • fill_all always looks them up on PyPI for the pinned version, which the 24-hour cache covers. A failed lookup is unknown, not the recorded sdist.
  • --offline refuses the file, naming why.
  • A package from another index can't be looked up safely, so it's skipped as private index, as for a Pipfile.lock. The exception is when WHEELGAP_INDEX_URL points at that same index (may_look_up).

Which index a package came from:

  • v7 index: is used when present.
  • Otherwise a file on files.pythonhosted.org is PyPI's.
  • Otherwise, if the environment's indexes are all PyPI, it's a direct URL (url), since PyPI serves files only from that host.
  • Otherwise it's private index, because a v6 lock doesn't record which index a package came from.

Other packages:

  • Git, path and editable PyPI packages are skipped (git, path, editable).
  • Conda packages (binary and source) are skipped as conda, so they show under "skipped".

Platform-specific packages. pixi resolves each platform separately. Locked platforms are grouped by the markers pip sees there: sys_platform, platform_machine and the environment's Python version, read from the conda python-X.Y.Z-… package. So linux-64 and a linux-64-cuda with subdir linux-64 are one group. A package missing from every platform of a group, say pywin32 locked on win-64 only, gets a marker that is false exactly on that group's markers. That way it shows n/a there instead of a false gap. Targets on platforms the lock doesn't cover, and other Pythons, still count it. That follows wheelgap's existing rule that only a definite False hides a package. 32-bit x86/Arm subdirs get no marker (their platform_machine isn't certain).

The reader

There's no YAML library. _BlockYaml in sources.py reads the block subset serde_yaml writes:

  • mappings and sequences, including indentless ones under a key;
  • one-line plain, single-quoted and double-quoted scalars (with a fixed set of escapes);
  • [] and {}.

Everything else is refused with pixi.lock: can't read it for sure: line N: …: anchors, aliases, tags, block scalars, flow collections with content, multi-line scalars, comments, tabs, document markers, duplicate keys and non-string keys.

On top of that it also refuses:

  • unknown top-level keys;
  • unknown environment keys (allowed: channels, indexes, find-links, options, packages);
  • unknown PyPI entry keys for that version;
  • PyPI selectors with extra keys;
  • a selector whose package isn't in packages;
  • a v7 platform missing from platforms;
  • PyPI packages in an environment with no indexes;
  • an index package with no version;
  • unknown location schemes.

Conda entries must be valid in the subset, but their contents aren't interpreted beyond the name and version.

All 38 environments in the eight real lockfiles above parse.

Environment selection: --environment NAME, not --group

--environment (default default) matches pixi's own -e/--environment and its term. In wheelgap, --group adds a dependency group to what's installed (uv, Poetry, PDM), and --no-dev and --only-group build on that. A pixi environment is a whole, separately solved package set: you pick exactly one, and it can't be combined with others. Reusing --group would give it a second, conflicting meaning. An unknown environment is an error listing the lock's environments, and --environment with no pixi.lock input is an error. --group on a pixi.lock keeps the existing "requires uv.lock inputs" error.

Targets from the lock's platforms: not done (note for later)

The subdirs map cleanly to platforms (linux-64 to linux-x86_64, osx-arm64 to macos-arm64, win-64 to win-amd64). The rest of a target doesn't:

  • the glibc and macOS floors come from pixi's system-requirements, which the lock doesn't record (v7 platforms may carry virtual_packages);
  • the Python is per-platform conda data.

Defaulting from the lock would mean guessing or silently differing from pixi, so the targets stay wheelgap's defaults. A later step could read [system-requirements] from pixi.toml or the lock's virtual packages.

Other changes

  • pixi.lock is detected in a project directory, last in LOCKFILES, so a directory that already has another lockfile is read as before.
  • .pre-commit-hooks.yaml files pattern, the README input list, a usage example, a "How it works" bullet, AGENTS.md's sources.py row, and the CHANGELOG.
  • Fixture tests/fixtures/pixiproj/pixi.lock (v7; linux-64, osx-arm64, win-64; environments default and test).

Verification

  • ruff format, ruff check, mypy, pytest all pass (1637 passed).
  • New tests:
    • test_pixi_lock, test_pixi_lock_environment, test_pixi_lock_version_6 (both index cases);
    • test_pixi_lock_refuses_what_it_cannot_read_for_sure: 27 malformed variants, from versions 5 and 8 to anchors, block scalars, flow lists, comments, tabs, unknown keys, dangling selectors and unknown schemes. Each must be a SourceError starting pixi.lock: with the expected reason;
    • quoted scalars;
    • CLI tests for the JSON output and lookups, a lock whose pick misses a wheel PyPI has, a failed lookup giving unknown, --environment errors, and the --offline refusal.
  • I reverted each source change and checked the tests fail without it:
    • fill_all's partial_files lookup: 3 tests;
    • the require_offline change: 1;
    • the per-platform markers: 2;
    • auto-detection: 1.
  • By hand against PyPI (public packages from public locks): grayskull (-p 3.13 -t all) and ipympl (--environment docs) gave sensible results. The lookups went to the pinned versions, and the conda packages were listed as skipped.

For the maintainer

  • Deliberate departure from "as for uv.lock": pixi.lock files are recorded but always re-checked on PyPI, and --offline refuses a pixi.lock with PyPI packages, because pixi's single pick per platform can't answer other targets. If you'd rather keep --offline working with a "may show false gaps" note, as for the uv.lock requires-python case, that's a small change. I chose an error because here nearly every off-lock target would be affected.
  • Not in this PR:
    • an environment key in [tool.wheelgap];
    • an environment argument for the MCP tools (they use default; check_lockfile() now takes environment=);
    • --github-annotations line numbers for pixi.lock (it names the file without a line);
    • llms.txt and the agent integrations (released behaviour only).

Review fixes (d8da984)

  • Platform grouping as above: no wrong n/a when platforms share a subdir, or when two versions are locked on two variants of one subdir.
  • A partial_files package is never judged on its locked file. It isn't kept under --online (a v7 index: package with WHEELGAP_INDEX_URL pointing at that index is looked up), and a failed lookup drops its files (unknown, no files in check_lockfile() results).
  • The reader refuses:
    • tabs and control characters anywhere, including C1 and \x7f;
    • line breaks other than \n/\r;
    • a byte order mark after the start (a leading one is stripped, as serde_yaml does);
    • a space before a colon, k: -, and ---/... lines with content;
    • escapes that aren't Unicode characters (lone surrogates, \U above 0x10FFFF).
  • --environment "" is an error. With --environment, a project directory reads pixi.lock even next to a uv.lock; without it, a stderr note names the pixi.lock that was passed over.
  • Conda packages are skipped once per name, and past five the text and Markdown output count them (105 conda packages (not on PyPI)); --json lists each one.
  • check_lockfile(..., environment=).
  • README: direct URLs on files.pythonhosted.org are checked as PyPI packages; MCP and [tool.wheelgap] read default only.
  • Tests for each, and for the reviews' mutation survivors: the reader checks, registry mismatch, the exact host, all vs any over indexes, version consistency, duplicate locations, merge keys, machine and subdir mapping, the Python package match, a platform without Python, and the LOCKFILES order. 1710 passed. I reverted the grouping, the never-kept and dropped-files changes, and the conda-by-name key one at a time and confirmed tests fail without each.

🤖 Generated with Claude Code

patrickballard and others added 5 commits November 12, 2026 18:36
A strict reader for the block-YAML subset pixi writes (lock versions 6 and 7,
no YAML library); any other version or construct is a SourceError naming the
file. --environment picks the environment (default: `default`). Conda packages
are skipped as `conda`. pixi records only the file it picked per platform, so
PyPI packages are always looked up on the index (partial_files), --offline
refuses them, and a package left out on one of the lock's platforms is hidden
only for that platform's markers and Python.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ricter reader

- Hide a package only when it's missing from every locked platform with the
  same sys_platform, platform_machine and Python (linux-64 and linux-64-cuda
  are one group), so no wrong n/a on rich platforms or per-variant versions.
- A partial_files package is looked up or skipped, never judged on its locked
  file: not kept under --online, and its files are dropped if the lookup fails.
- The YAML reader refuses tabs and control characters anywhere, other line
  breaks, a BOM after the start (a leading one is stripped), a space before a
  colon, `k: -`, document markers with content, and escapes that aren't
  Unicode characters.
- --environment "" is an error; with --environment a project directory reads
  pixi.lock, otherwise a note names the pixi.lock passed over.
- Conda packages are skipped once per name and counted past five in text and
  Markdown output; check_lockfile() takes environment=.
- Tests for each, and for the reviews' mutation survivors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A package installed on a platform whose Python isn't known (built from
  source, say) is never hidden on that platform's sys_platform and machine,
  since that Python may be the one a group of the same markers has.
- The reader refuses U+FFFE and U+FFFF, as libyaml does.
- A pixi.lock that isn't valid UTF-8 is a `pixi.lock: ...` SourceError.
- Tests for these and for the remaining mutants: platforms sharing a subdir
  with different Pythons, U+2029, \U0010FFFF accepted, exactly six conda
  packages, and conda counted next to a named git package.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@patrickballard
patrickballard merged commit ab22ad2 into main Nov 12, 2026
9 checks passed
patrickballard added a commit that referenced this pull request Nov 12, 2026
…rdening

pixi.lock's PyPI package names now go through package_name like the other
lockfiles' (conda names are left alone: they aren't PEP 508 names). Its
quoted-scalars test used the name pure'wheel, which is now an input
error; it uses purewheel, and test_block_yaml_reads still covers ''.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@patrickballard
patrickballard deleted the fix-229-pixi-lock branch November 13, 2026 08:34
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.

pixi.lock input: check the PyPI packages in a pixi project

1 participant