Skip to content

fix(install_pypi): preserve files when migrating dependency from pypi to conda - #7051

Open
aoright wants to merge 1 commit into
prefix-dev:mainfrom
aoright:fix-pypi-to-conda-preserved-files
Open

aoright wants to merge 1 commit into
prefix-dev:mainfrom
aoright:fix-pypi-to-conda-preserved-files

Conversation

@aoright

@aoright aoright commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Description

When an environment is updated such that a package previously installed via PyPI is moved to conda dependencies, conda installs the conda package into the environment prefix first.

During the subsequent PyPI update phase, InstallPlanner::plan inspects site-packages. Previously, packages not in required_dists were partitioned into duplicates only if dists.len() > 1. If conda did not install a separate .dist-info (or replaced it, or only module files exist), dists.len() == 1, causing the old PyPI package to be classified as extraneous. Then remove_packages invoked uv_installer::uninstall(dist), which read the old PyPI RECORD file and deleted all the files that conda had just extracted into site-packages/.

This PR fixes this by:

  1. Collecting conda package names and PyPI purls from pixi_records during planning setup.
  2. Passing conda_packages to InstallPlanner.
  3. Partitioning unrequired distributions into duplicates when dists.len() > 1 || self.conda_packages.contains(name).
  4. Ensuring that remove_duplicate_metadata removes only the stale PyPI .dist-info directory without calling uv_installer::uninstall, leaving the conda-installed package files intact.

Fixes #6902

How Has This Been Tested?

  • Added unit test test_conda_package_not_extraneous_when_replacing_pypi in crates/pixi_install_pypi/src/plan/test/mod.rs.
  • Ran cargo test -p pixi_install_pypi across unit and integration tests.
  • Ran cargo clippy -p pixi_install_pypi --all-targets and cargo fmt --check.

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Google Antigravity

Checklist:

  • I have performed a self-review of my own code
  • I have added sufficient tests to cover my changes.

… to conda

When updating an environment where a package previously installed from
PyPI is switched to a conda dependency, conda extracts the package files
into the environment prefix first. In the subsequent PyPI update phase,
the old PyPI distribution was identified as extraneous (if only one
distribution remained or conda did not write a separate dist-info).
Calling remove_packages then invoked uv_installer::uninstall, which
walked the old PyPI RECORD file and deleted all the files that conda
had just extracted.

To fix this, pass conda package names from pixi_records (including
both conda package names and PyPI purl names) to InstallPlanner.
When an installed package matches a conda-provided package and is no
longer required from PyPI, treat it as duplicate metadata rather than
extraneous. remove_duplicate_metadata then removes only the stale PyPI
dist-info directory without deleting any package source files.

Fixes prefix-dev#6902

Signed-off-by: aoright <102943475+aoright@users.noreply.github.com>
@aoright
aoright force-pushed the fix-pypi-to-conda-preserved-files branch from 20329b0 to a462ee0 Compare September 18, 2026 13:25

This branch has not been deployed

No deployments
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.

Updating pypi-dependency to a conda one results in broken python package in env

1 participant