Repository navigation
Patch pixi projects: find .pixi/envs without activation - #2166
Conversation
pixi installs a project into conda prefixes of its own under `.pixi/envs/<name>`. The Python crawler did not know them, so in a pixi project `scan`, `apply`, `vex`, `rollback` and `remove` only saw the installed packages when run through `pixi run` in a project that also had a `pyproject.toml` (the crawler's project-marker fallback then asked the Python on PATH, which `pixi run` points at the environment). Run plainly after `pixi install`, as a CI step is, `scan` reported "No packages found", `apply` exited 1 with every patch "not found on disk", and `vex` had nothing to attest. A project with only `pixi.toml` was not patchable at all, and on a machine with a system Python the fallback crawled that interpreter instead of the project's environment. - Every conda prefix under `.pixi/envs/` is now one of the project's environments, added to whichever venv another tool keeps beside it. The link pixi leaves there for `detached-environments` is followed, and an environment `pixi run` activated for this workspace is found where there is no link (Windows). - A project with a `pixi.toml` or `pixi.lock` and no environment installed has nothing installed: the interpreter on PATH is never crawled for it, as for a uv, Poetry or Pipenv project. - `scan --global` reads the tool environments `pixi global install` creates under `$PIXI_HOME/envs` (default `~/.pixi/envs`), like uv tools and pipx apps. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With the environments found, the text around a pixi project's patches still spoke of pip and requirements files: - Hosted mode (the default) cannot rewrite a pixi project: pixi installs from its own lock, mostly from conda channels, and it keeps a conda package over a PyPI source for the same name. The run now warns `redirect_pypi_pixi_project`, which names the agent-mode steps, in place of `redirect_pypi_no_lockfile`, whose remedy (pin the package in a requirements.txt, or commit another tool's lock) changes nothing pixi installs. `pixi.toml` and `pixi.lock` are presence-only inputs of the hosted planner; nothing is written, as before. - The agent-mode next steps name `pixi install` when the project has a `pixi.lock`. - The advisory after an in-place Python patch names what reverts it in a conda prefix (`pixi reinstall`, or `conda install --force-reinstall`) instead of `pip check` and `pip install --force-reinstall`, which a pixi environment has no pip for. - A copy in a conda prefix whose files are not the PyPI release's (a recipe that changes the source, a compiled extension built for conda) was already left untouched; the failure now says that, instead of only "no matching variant found". Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`scripts/backtest-pixi.py` downloads pinned pixi releases (SHA-256 pinned per release and host) and runs the CLI from the project root with no `pixi run` around it, against the public urllib3 patch: agent mode must leave the patched bytes in every environment and the upstream bytes in pixi's package cache, survive `pixi install` and `pixi run`, be restored by `apply` after the environments are rebuilt, and be undone byte for byte by `rollback`; hosted mode must change nothing and name agent mode; vendored mode must refuse; a checkout with no environment must read nothing from the Python on PATH. Shapes: the package from conda-forge, from PyPI, a `pyproject.toml` manifest, two environments, and detached environments. `pixi-compatibility.yml` runs it for pixi 0.20.1, 0.39.5, 0.63.2 and 0.84.2 on Linux (path-filtered pull requests and pushes to main) and for the ends of that range on macOS on pushes to main. The ecosystems guide gains a pixi row and section, the CLI contract the discovery rule and the new warning code, and docs/testing a pixi guide. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A project pip installs too keeps the interpreter fallback. With a `requirements.txt`, `setup.py` or `setup.cfg` beside pixi's files, the packages may be in the Python on PATH (a container image that runs `pip install -r requirements.txt`, then `socket-patch apply`), which 5.1.0 found and the first version of this change no longer did. Only a project nothing but pixi installs skips that fallback. A pixi project whose own files name another lock tool (a Pipfile, a pyproject naming uv, Poetry or PDM) keeps that tool's hosted lock remedy. - `pixi run` from a workspace member directory finds the workspace's environment: pixi exports the root it found by walking up, and the activated prefix now counts from any directory below it, unless that directory has environments of its own. - The "no matching variant" reason for a copy in a conda prefix is given for Python packages only, names the copy, and offers the conda build as a cause instead of asserting it (pip and uv install wheels there too). The advisory for a plain conda environment names the pip reinstall beside conda's. - A copy in a pixi environment that a hosted run finds stale gets a remedy that can clear it (agent mode), not "reinstall from the rewritten lock". - Agent-mode next steps name `pixi install` for either pixi file, beside another tool's install when the project has both. - The harness's fresh-checkout cell plants a decoy interpreter with one package first on PATH, runs on a shape with a `pyproject.toml`, uses dry runs only, and checks both halves of the rule. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview A new Hosted/vendored behavior is documented and gated: pixi manifest/lock are presence-only in the format registry; hosted runs emit CI and docs: new Reviewed by Cursor Bugbot for commit d8387cd. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d8387cd. Configure here.
Finding pixi's environments means PyPI patches now reach packages conda built. A patch records the hash each file it replaces has in the PyPI release, and a conda build is not always that release. Compared file by file with the PyPI wheels, the 51 pure-Python conda-forge packages of one project held 45 identical builds and 6 that differ somewhere (a generated version file in three, one module the recipe patches in setuptools); every compiled package differed, in its extension modules and, for pillow, in a Python source too. The apply engine now refuses a PyPI patch for a copy conda built (its INSTALLER says conda, or it has none; a copy whose metadata cannot be read counts as one) unless: - the patch is for a pure-Python wheel (`...-none-any`) and the copy does not say it holds compiled code (`Root-Is-Purelib: false`). A compiled conda package is built separately from the PyPI wheel and links conda's own libraries, so it is never that release, even when the Python file a patch touches is byte-identical; - every file the patch replaces has the release's bytes, and the patch replaces at least one file. The check is in the engine, so `--force` and `--allow-patch-conflicts` do not get past it: they consent to losing local changes to the distribution a patch was made for, not to writing one distribution's files into another. Content an earlier Socket patch wrote still gives way to its update. A wheel pip or uv installed into a conda prefix is the PyPI release and takes the usual rules. `scan --mode agent` and `get` leave a patch out, with the warning `conda_build_not_pypi_release` and nothing recorded, when every installed copy of its package is such a build, instead of recording a patch every later `apply` would refuse. Not covered: files a patch does not replace are not compared, since a patch record holds no hashes for them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The conda rule: - A record made from a source distribution, or keyed by the bare purl, was refused by its name with text about a compiled package, so a manifest holding it beside the wheel's record failed `apply` on a pure-Python conda build. Only a platform wheel is refused by name now; for the others the copy shows what it holds: its WHEEL metadata, or, for an install without one (`.egg-info`), whether an extension module is among its files. - `--strict` was replaced by the default policy on a conda build, which let content an earlier Socket patch wrote be overwritten. Only `--force` and `--allow-patch-conflicts` are tightened now. - A compiled conda copy an earlier release patched made every `apply` fail while its files stayed patched. A copy that already holds the patch has nothing written to it and is reported as already patched. A refusal names the `socket-patch remove` that drops the record. - The engine reads a copy's metadata once instead of three times. Discovery: - A pixi project with a `pyproject.toml` that declares a `[build-system]` (a library that keeps pixi for development and is `pip install`ed elsewhere) keeps the interpreter fallback, like one with a `requirements.txt`. A `pyproject.toml` of metadata and tool settings does not. - `.pixi/envs` is read only beside a `pixi.toml` or `pixi.lock`: in the home directory that path holds the tools of `pixi global install`. - Below an activated workspace root, only a member (pixi files of its own, no environments of its own) is given the workspace's environment, not another tool's project that sits in the same tree. - A `--system-site-packages` venv built on a pixi environment's Python no longer hides that environment's packages: `pixi run` imports them. Hosted mode: a build backend (`poetry-core`, `pdm-backend`, `uv_build`) no longer keeps a pixi project from the pixi warning; only a tool's own table or a Pipfile does. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Resolves the CLI_CONTRACT.md conflict: keeps main's rewrite of the hosted mode paragraph and adds this branch's redirect_pypi_pixi_project code to its warning list. Assisted-by: Claude Code:claude-opus-5-5
Two Bugbot findings: - The environment pixi activated (CONDA_PREFIX under PIXI_PROJECT_ROOT or PIXI_WORKSPACE_ROOT) was taken for the workspace's without checking that pixi installed it. A `conda activate` inside `pixi shell` leaves pixi's variables set over a plain conda prefix, which was then crawled and patched as the project's. It now needs pixi's conda-meta record. - Agent-mode next steps named only `pixi install` for a pixi project that also has a requirements.txt, setup.py or setup.cfg, although the crawl then also reads the interpreter on PATH that `pip install` fills. They now name `pip install` too. Assisted-by: Claude Code:claude-opus-5-5
|
[agent] PR shepherd: final review on 72a5e5e found one blocker that needs a decision, so this PR is not labelled A clean apply can exit 1, depending on manifest order. The setup is a pure-Python conda build (
Question: should a conda build's static refusal of a record count as "this record is not the installed distribution"? Under that reading the loop skips the record quietly, like a first-file mismatch, whenever another record of the same base applies or is already patched, and fails only when no record of the base can take the copy. Or do you want it handled some other way, for example by ordering pure records first? Either way, this needs a test that runs both orders. Smaller points, not blockers:
Everything else checked out: the discovery rules, the Generated by Claude Code |
A release with a platform wheel beside its pure-Python one has a record for each, and their Python files are the same. On a pure-Python conda build the pure wheel's record patches the copy, and the platform wheel's, which a conda build never takes, is refused. `apply` tried the records in the order the manifest's map yielded them, so the same project exited 1 (platform record first: refused, then the pure record patched the file) or 0 (pure record first: the platform record found the file patched). On each copy the records a conda build never takes are now tried after the others, in purl order, and such a record is an error only when it is the first one tried on the copy. After another record of the release it reads as already patched when its files hold the patch, as it does in a venv, and is otherwise not reported: the copy's outcome is the earlier record's. So a copy that fails is reported once, with its own cause, instead of a second refusal naming the wrong one. `scan --mode agent` and `get` leave such a record out without the `conda_build_not_pypi_release` warning when they keep another record of the same release: the package is patched, so there is nothing to report. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The blocker from the final review is fixed in bddbcff, with the reading the review proposed: a record a conda build never takes is not that copy's distribution once another record of the release has been tried on it.
The two smaller points are left as they are, since both only withhold a patch: the PR description says why under "Code review". |

Problem
pixi installs a project into conda prefixes of its own under
.pixi/envs/<name>, and the Python crawler did not know them. Measured with the released 5.1.0 on a public pixi project (381 conda packages and one PyPI wheel,linux-64, 84 Python distributions in the environment), afterpixi install:scan/scan --mode agentNo packages found. Run your package manager's install first.apply(patches recorded)vexpackage_not_found, nothing to attestpixi runpyproject.tomlpixi.toml, underpixi runNo packages foundThe
pixi runcase worked by accident: with apyproject.tomland no venv the crawler asks the Python onPATH, whichpixi runpoints at the environment. Outsidepixi run, on a machine that has a system Python (a CI runner), that same fallback crawled the system interpreter instead of the project's environment.What changes
Discovery (
crawlers/pixi_env.rs,python_crawler.rs).pixi/envs/is one of the project's environments, with no activation, added to whichever venv another tool keeps beside it. It is read only where apixi.tomlorpixi.lockis (in the home directory that path holdspixi globaltools). The link pixi leaves there fordetached-environmentsis followed; where pixi leaves no link (Windows), the environmentpixi runactivated for this workspace is used.PATHis never crawled for it, the rule uv, Poetry and Pipenv projects already have. A file pip installs from beside pixi's files (requirements.txt,setup.py,setup.cfg, or apyproject.tomlwith a[build-system]) keeps the fallback as it was in 5.1.0.pixi.toml, no environments of its own), the environmentpixi run/pixi shellactivated for the workspace is used. Another tool's project in the same tree is not given it.--system-site-packagesvenv built on a pixi environment's Python does not hide that environment's packages from the crawl.scan --globalreadspixi global installtool environments ($PIXI_HOME/envs, default~/.pixi/envs).Messages
redirect_pypi_pixi_project, which names the agent-mode steps, instead ofredirect_pypi_no_lockfile, whose remedy (pin the package in arequirements.txt) changes nothing pixi installs.pixi install.pixi reinstall,conda install --force-reinstall) instead ofpip check; a pixi environment ships no pip.no matching variant found.A conda build is patched only as the PyPI release it repackages (
patch/conda_copy.rs)Finding pixi's environments means PyPI patches now reach packages conda built, so the rule for those is explicit and enforced in the apply engine, where no caller or flag gets past it. A copy conda built (its
INSTALLERsaysconda, or it has none) takes a patch only when:Root-Is-Purelib: truein itsWHEEL, or, for an.egg-infoinstall, no extension module among its files). A compiled conda package is built separately from the PyPI wheel and links conda's own libraries, so it is never that release, even when the Python file a patch touches is byte-identical;--forceand--allow-patch-conflictsdo not overwrite a file that differs;--strictis unchanged.A copy that already holds the patch (one an earlier release patched) has nothing written to it and is reported as already patched.
scan --mode agentleaves a patch out (warningconda_build_not_pypi_release, exit 0, nothing recorded) when no installed copy can take it, instead of recording a patch every laterapplywould refuse. A wheel pip or uv installed into the environment is the PyPI release itself and is patched as before.Measured on the project's lock, comparing each conda package with its PyPI wheel file by file:
setuptools, one source snapshot, one metapackagepillowalso a Python sourceAll 48 pure-Python builds with a
.dist-inforecordINSTALLER: condaandRoot-Is-Purelib: true; all 10 compiled ones recordRoot-Is-Purelib: false; the two.egg-infoinstalls record neither, and are judged by the wheel the patch names.Not covered: files a patch does not replace are not compared, because a patch record holds no hashes for them. A recipe that changes another module of an otherwise identical build (
setuptoolsabove) is not seen. Closing that needs the release's file hashes from the patch service.Tests and docs
scantests for all three modes; hermeticapplytests for a pixi layout.applytests (a compiled build whose file matches is refused with and without--force; no flag overwrites a differing file; a wheel pip or uv installed is patched; an earlier Socket patch still gives way) and ascantest (nothing recorded, exit 0). Checked by hand against a real compiled condapillow: refused, file unchanged, with and without--force.scripts/backtest-pixi.pyandpixi-compatibility.ymlrun real pixi releases (SHA-256 pinned): pixi 0.20.1, 0.39.5, 0.63.2 and 0.84.2 on Linux, the ends of the range on macOS on pushes to main.docs/ecosystems.mdgains a pixi row and section,CLI_CONTRACT.mdthe discovery rule and the new warning code,docs/testing/pixi-compatibility.mdthe test guide.Why agent mode only
Measured on pixi 0.84.2:
[pypi-dependencies]URL pointing at a hosted wheel is ignored when a conda package provides the same name at that version: pixi keeps the conda build and records no PyPI entry. At another version the solve fails ("pinned by the conda solve"). A hosted pin can therefore never replace a conda-provided package, and writing one would look wired while the unpatched conda build is what gets installed.pixi.lockalone installs the hosted wheel into a fresh environment, but the next re-solve (pixi add) silently puts the PyPI URL back, and an existing environment keeps the upstream bytes untilpixi reinstall.So this PR does not rewrite pixi files. Hosted mode names agent mode, and vendored mode keeps refusing (
pypi_no_requirements/pypi_pyproject_only, exit 1), which already names agent mode. Hosting or vendoring PyPI-sourced pixi dependencies is possible follow-up work; conda-provided ones would need patched conda packages.Verification
cargo clippy --locked --workspace --all-features -- -D warningsandcargo check --workspace --all-targets --all-features: clean.cargo test -p socket-patch-core --lib: 8316 passed.-p socket-patch-cli --lib: 1024 passed. CLI suitesapply(166),scan(267),in_process_python_envs(26),rollback(140),remove(89),mode_migration_pypi(83): all pass. Earlier heads of this branch also ranin_process_pypi_apply,in_process_pypi_multi_release,scan_requirements_lock_only,policy_pypi_names,hosted_superseding_pypi,in_process_alternate_installers,in_process_redirect_{poetry,pipenv},in_process_vendor_pypi_takeover,scan_vendor_requirements_unwiredand corecrawler_python_e2e; CI runs them all.scripts/backtest-pixi.pywith a build of this branch: every cell passes on Linux x86_64 userland (environments hard-linked into pixi's cache) for 0.20.1, 0.39.5, 0.63.2 and 0.84.2, and on macOS arm64 for 0.20.1 to 0.84.2. Against 5.1.0 the agent, hosted and vendored cells fail.scan --mode agentapplies both available patches,applyis idempotent,vexattests both, the environment's Python imports the patched modules, androllbackrestores the upstream bytes.Code review
/code-review highreported two important findings and five nits. All seven are addressed in the last commit:pip install -r requirements.txtand thensocket-patch applyin a repo that also has apixi.toml). Fixed: arequirements.txt,setup.pyorsetup.cfgbeside pixi's files keeps the fallback, and a pixi project whose own files name another lock tool keeps that tool's hosted remedy. (The second round extended this to a packagedpyproject.toml, below.)pixi runfrom a workspace member directory found nothing. Fixed: the activated environment counts from any directory at or below the exported workspace root, unless that directory has environments of its own.pip installfor a pixi project. Fixed: either pixi file counts, andpixi installis named beside another tool's install.PATH, runs on a shape with apyproject.toml, and uses dry runs only. It fails against a build without the fix.A second
/code-review high, after the conda rule was added, reported six important findings, one pre-existing and two nits:applyfail on a pure-Python conda build. Fixed: only a platform wheel is refused by its name; for an sdist or unnamed record the copy's own metadata decides.--strictwas loosened for conda builds. Fixed: only--forceand--allow-patch-conflictsare tightened to the default policy.pyproject.toml, installed with pip, was no longer found. Fixed: apyproject.tomlwith a[build-system]keeps the interpreter fallback. One that only holds metadata or tool settings (the project this was found on) does not.applyfail while staying patched. Fixed: a copy that already holds the patch is reported as already patched; a refusal namessocket-patch remove.--system-site-packagesvenv on a pixi environment's Python hid that environment's packages. Fixed.pyproject.tomlbuilt with hatchling goes down the Hatch lane before the pixi check in hosted mode. Not changed here: that is how the Hatch lane has always claimed such a project, and changing which lane a hosted run takes belongs with hosted support for pixi, not with this agent-mode change. The part this PR added is fixed: a build backend no longer stops the pixi warning; only a tool's own table or aPipfiledoes.~/.pixi/envs(pixi's global tools) for a project. Fixed:.pixi/envsis read only beside apixi.tomlorpixi.lock.scanorgetthat selects PyPI patches looks up their installed copies once more than before (local listing only, no network); folding that into the release filter would change its four callers.Bugbot reported two findings, both fixed by the PR shepherd in 72a5e5e:
conda activateinsidepixi shell). Fixed: the activated prefix needs pixi's ownconda-metarecord, which every tested pixi release writes.pixi installfor a pixi project that pip also installs. Fixed:pip installis named too when arequirements.txt,setup.pyorsetup.cfgis there.The PR shepherd's final review found one blocker, fixed in bddbcff:
applycould exit 1 depending on the order of the manifest's records. A release with a platform wheel beside its pure-Python one has a record for each, with the same Python files. On a pure-Python conda build the platform wheel's record was refused when it came first, although the pure wheel's record then patched the file. Fixed: on each copy the records a conda build never takes are tried after the others, in purl order, and such a record is an error only when it is the first one tried on the copy. After another record of the release it reads as already patched when its files hold the patch (as in a venv), and is otherwise not reported.scan --mode agentandgetleave such a record out without the warning when they keep another record of the same release. Tests:a_platform_wheel_record_beside_the_pure_one_does_not_fail_a_pure_python_conda_build(fails without the fix) anda_conda_build_two_records_fail_on_is_reported_once.A
/code-review highof that fix alone reported three findings, all addressed before the push: the skipped record was still listed as not installed (now it reads as already patched, and the tests pin that); a copy the pure wheel's record failed on got a second refusal naming the wrong cause (now reported once); the test's rounds did not cover what its comment said (comment corrected, outputs asserted).Two smaller points from the shepherd's review are not changed, because both only withhold a patch and never allow a wrong write:
.egg-infoinstall in a conda prefix has noINSTALLER, so it is judged as a conda build, including one pip installed withsetup.py install. Nothing in such a copy reliably says pip put it there: a conda recipe that ran an old pip leaves the same files. A pure-Python copy of this kind is still patched when its files are the release's; a compiled one is refused..egg-infoinstall the search for extension modules walks its whole top-level directory, so a pure distribution in a shared namespace package (zope,google) beside a compiled one can be taken for compiled.Not in this PR
pixi.lockis not read as a lockfile, so a fresh checkout has no packages untilpixi installhas run.vexin a project whose only manifest ispixi.tomland that has no git remote still needs--product.PATHwhen the project has a Python marker).🤖 Generated with Claude Code
Generated by Claude Code