Skip to content

Pixi doesn't use the uv cache if using a non-default PyPI package index #5507

Closed

Description

@dhirschfeld

Checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pixi, using pixi --version.

Reproducible example

When using a non-default PyPI index (e.g., a private Cloudsmith repository), pixi's PyPI package installer always re-downloads packages from remote, even when they are already present in the local uv cache. This defeats Docker buildx cache mounts and significantly slows down CI builds.

The root cause is a hardcoded DEFAULT_PYPI_INDEX_URL in the convert_to_dist() function, which causes a cache key mismatch between the resolution phase (which writes cache entries keyed by the actual index URL) and the installation phase (which looks up cache entries using the hardcoded PyPI URL).

pkg.requires_python.clone(),
)?;
// Recreate the filename from the extracted last component
// If this errors this is not a valid wheel filename
// and we should consider it a sdist
let filename = WheelFilename::from_str(filename_decoded.as_ref());
if let Ok(filename) = filename {
Dist::Built(BuiltDist::Registry(RegistryBuiltDist {
wheels: vec![RegistryBuiltWheel {
filename,
file: Box::new(file),
// This should be fine because currently it is only used for caching
// When upgrading uv and running into problems we would need to sort this
// out but it would require adding the indexes to
// the lock file
index: IndexUrl::Pypi(Arc::new(uv_pep508::VerbatimUrl::from_url(
uv_redacted::DisplaySafeUrl::from(
consts::DEFAULT_PYPI_INDEX_URL.clone(),
),
))),
}],
best_wheel_index: 0,
sdist: None,
}))
} else {
let pkg_name = to_uv_normalize(&pkg.name)?;
let pkg_version = to_uv_version(&pkg.version)?;
Dist::Source(SourceDist::Registry(RegistrySourceDist {
name: pkg_name,
version: pkg_version,
file: Box::new(file),
// This should be fine because currently it is only used for caching
index: IndexUrl::Pypi(Arc::new(uv_pep508::VerbatimUrl::from_url(
uv_redacted::DisplaySafeUrl::from(consts::DEFAULT_PYPI_INDEX_URL.clone()),
))),
// I don't think this really matters for the install
wheels: vec![],
ext: SourceDistExtension::from_path(Path::new(filename_raw)).map_err(|e| {
ConvertToUvDistError::Extension(e, filename_raw.to_string())
})?,
}))
}
}
UrlOrPath::Path(path) => {
let native_path = Path::new(path.as_str());

Activity

  1. added
    bug
    on Feb 15, 2026
  2. dhirschfeld commented on Feb 15, 2026

    @dhirschfeld
    ContributorAuthor

    Some more analysis from the LLM:

    The convert_to_dist() function converts lock file PypiPackageData into uv Dist objects for
    the installation planner. When constructing a RegistryBuiltDist (wheel) or RegistrySourceDist
    (sdist), it hardcodes the index URL:

    For wheels

    file: Box::new(file),
    // This should be fine because currently it is only used for caching
    // When upgrading uv and running into problems we would need to sort this
    // out but it would require adding the indexes to
    // the lock file
    index: IndexUrl::Pypi(Arc::new(uv_pep508::VerbatimUrl::from_url(
    uv_redacted::DisplaySafeUrl::from(
    consts::DEFAULT_PYPI_INDEX_URL.clone(),
    ),
    ))),
    }],

    For sdists

    // This should be fine because currently it is only used for caching
    index: IndexUrl::Pypi(Arc::new(uv_pep508::VerbatimUrl::from_url(
    uv_redacted::DisplaySafeUrl::from(consts::DEFAULT_PYPI_INDEX_URL.clone()),
    ))),
    // I don't think this really matters for the install
    wheels: vec![],
    ext: SourceDistExtension::from_path(Path::new(filename_raw)).map_err(|e| {
    ConvertToUvDistError::Extension(e, filename_raw.to_string())
    })?,
    }))
    }

    1. Cache Structure Evidence

    Inspecting the uv-cache inside rattler reveals two different index-keyed directories:

    wheels-v5/
    ├── pypi/              ← keyed by hardcoded https://pypi.org/simple/
    │   └── numpy/
    │       └── *.http     ← written during installation (download)
    └── index/
        └── 863dd82dcb84841e/   ← keyed by hash of Cloudsmith URL
            └── numpy/
                └── *.msgpack   ← written during resolution (metadata)
    

    The installation planner looks up wheels-v5/pypi/numpy/ for a cached wheel, but the actual cached metadata was stored under wheels-v5/index/863dd82dcb84841e/numpy/. The .http files under pypi/ are only created after pixi downloads the wheel (because the Dist object carries the hardcoded PyPI index URL), so on subsequent runs the lookup still fails — the cache entry written by the resolver and the cache entry read by the installer use different keys.

    This bug does NOT manifest with the default PyPI index, because in that case both the resolver and the hardcoded value agree on https://pypi.org/simple/.

    2. The Cache Comparison: Index URL Mismatch

    impl<'a> DistCache<'a> for CachedWheels<'a> {
    fn is_cached(
    &mut self,
    dist: &'a Dist,
    uv_cache: &uv_cache::Cache,
    build_options: &BuildOptions,
    ) -> Result<Option<CachedDist>, DistCacheError> {
    // Check if installation of a binary version of the package should be allowed.
    // we do not allow to set `no_binary` just yet but let's handle it here
    // because, then this just works
    let no_binary = build_options.no_binary_package(dist.name());
    // We can set no-build
    let no_build = build_options.no_build_package(dist.name());
    match dist {
    Dist::Built(BuiltDist::Registry(wheel)) => {
    let cached = self.registry.get(wheel.name()).find_map(|entry| {
    if entry.index.url() != &wheel.best_wheel().index {
    return None;
    }
    if entry.built && no_build {
    return None;
    }
    if !entry.built && no_binary {
    return None;
    }
    if entry.dist.filename == wheel.best_wheel().filename {
    Some(&entry.dist)
    } else {
    None
    }
    });
    if let Some(distribution) = cached {
    Ok(Some(CachedDist::Registry(distribution.clone())))
    } else {
    Ok(None)
    }
    }
    Dist::Built(BuiltDist::DirectUrl(wheel)) => {
    if no_binary {
    return Err(DistCacheError::NoBinaryConflictUrl {
    url: wheel.url.to_string(),
    });
    }

    The CachedWheels::is_cached() method checks registry distributions against the cache.

    For built wheels

    if entry.index.url() != &wheel.best_wheel().index {
    return None;
    }

    For source dists

    if entry.index.url() != &sdist.index {
    return None;
    }

    These comparisons are correct — they ensure cache entries match the index the dist claims to be from. The problem is that the Dist object has a wrong index (hardcoded PyPI) while the cache entries were written by the resolver under the actual index (Cloudsmith).

    3. The Call Chain

    The full call chain from lock data to cache miss:

    1. RequiredDists::from_packages()
      Calls convert_to_dist() for each locked PyPI package
      pub fn from_packages(
      packages: &[PypiPackageData],
      lock_file_dir: impl AsRef<Path>,
      ) -> Result<Self, ConvertToUvDistError> {
      let mut dists = HashMap::new();
      for pkg in packages {
      let uv_name = PackageName::from_str(pkg.name.as_ref()).map_err(|_| {
      ConvertToUvDistError::InvalidPackageName(pkg.name.as_ref().to_string())
      })?;
      let dist = convert_to_dist(pkg, lock_file_dir.as_ref())?;
      dists.insert(uv_name, (pkg.clone(), dist));
      }
      Ok(Self(dists))
      }
    2. convert_to_dist()
      Creates Dist with hardcoded IndexUrl::Pypi(DEFAULT_PYPI_INDEX_URL)
      index: IndexUrl::Pypi(Arc::new(uv_pep508::VerbatimUrl::from_url(
      uv_redacted::DisplaySafeUrl::from(
      consts::DEFAULT_PYPI_INDEX_URL.clone(),
      ),
    3. decide_installation_source()
      Calls dist_cache.is_cached(dist, ...)
      match dist_cache.is_cached(dist, uv_cache, build_options)? {
      Some(cached_dist) => {
      installation_sources.add_cached(&cached_dist, operation.cached());
      }
      None => {
      installation_sources.add_remote(dist, operation.missing());
      }
      }
    4. CachedWheels::is_cached()
      Compares entry.index.url() (actual Cloudsmith URL) with wheel.best_wheel().index
      (hardcoded PyPI URL) → mismatch → returns None
      if entry.index.url() != &wheel.best_wheel().index {
      return None;
      }
    5. log_installation_details()
      logs: "installing from remote because no version is cached: {name}=={version}"
      tracing::debug!(
      "*installing* from remote because no version is cached: {}",
      install_missing.iter().join(", ")
      );

    4. How the Resolver Writes the Cache

    During pixi lock / resolution, uv's built-in resolver stores metadata in the cache keyed by
    the actual index URL. For a Cloudsmith index, the cache path uses a SHA-256 hash of the URL:

    lock_pypi_packages():

    ResolvedDist::Installable { dist, .. } => match &**dist {
    Dist::Built(dist) => {
    let (location, hash) = match &dist {
    BuiltDist::Registry(dist) => {
    let best_wheel = dist.best_wheel();
    let hash = parse_hashes_from_hash_vec(&dist.best_wheel().file.hashes)
    .into_diagnostic()
    .context("cannot parse hashes for registry dist")?;
    let url_or_path = get_url_or_path(
    &best_wheel.index,
    &best_wheel.file.url,
    abs_project_root,
    )
    .into_diagnostic()
    .context("cannot convert registry dist")?;
    (url_or_path, hash)
    }
    BuiltDist::DirectUrl(dist) => {
    let url = dist.url.to_url();
    let direct_url = Url::parse(&format!("direct+{url}"))
    .into_diagnostic()
    .context("cannot create direct url")?;
    (UrlOrPath::Url(direct_url), None)
    }
    BuiltDist::Path(dist) => (
    UrlOrPath::Path(
    process_uv_path_url(
    &dist.url,
    &dist.install_path,
    abs_project_root,
    )
    .into_diagnostic()?,
    ),
    None,
    ),
    };

    stores the best_wheel.index (the real index URL from the resolver) into the lock file's
    UrlOrPath. This means the lock file URLs point to the actual Cloudsmith download URL, but the
    index origin information is lost.

  3. baszalmstra commented on Feb 15, 2026

    @baszalmstra
    Contributor

    This is caused by us not (yet) storing the indexes for each wheel in the lockfile. We are currently working on this.

  4. dhirschfeld commented on Feb 15, 2026

    @dhirschfeld
    ContributorAuthor

    Thanks @baszalmstra! I did note the TODO in the source! 😆

    I wasn't too hopeful I'd track down the problem once I realised it only happened with our internal Cloudsmith package registry. Fortunately the LLM, having access to our package registry, was able to debug!

  5. dhirschfeld commented on Feb 15, 2026

    @dhirschfeld
    ContributorAuthor

    In case it's useful, here's the dockerfile I used to test:

    # syntax=docker/dockerfile:1
    # https://hub.docker.com/r/docker/dockerfile
    
    
    # Example Dockerfile for compring pixi and uv caching behviour.
    # Build with:
    # docker buildx build --load --progress plain --secret id=CLOUDSMITH_API_KEY --build-arg CACHEBUST=$(date +%s) -t pixi-test:latest . 2>&1 | tee build.log
    
    
    FROM ghcr.io/prefix-dev/pixi:latest AS build
    
    SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
    
    
    ENV PIXI_COLOR="always"
    
    
    RUN pixi global install bat eza uv
    
    
    COPY --link <<EOF /etc/pixi/config.toml
    default-channels = ["https://conda.cloudsmith.io/<company>/conda/"]
    
    [pypi-config]
    index-url ="https://dl.cloudsmith.io/<token>/<company>/python/python/simple/"
    EOF
    
    
    COPY --link <<EOF /etc/uv/uv.toml
    index-url = "https://dl.cloudsmith.io/<token>/<company>/python/python/simple"
    link-mode = "copy"
    cache-dir = "/tmp/uv/cache"
    [pip]
    system = true
    EOF
    
    
    # Bust the docker layer cache (pixi package cache should still work)
    # Pass --build-arg CACHEBUST=$(date +%s) to force re-run
    ARG CACHEBUST
    
    
    WORKDIR /pixi-app
    
    RUN --mount=type=secret,id=CLOUDSMITH_API_KEY,env=CLOUDSMITH_API_KEY <<EOF
    set +x
    pixi auth login conda.cloudsmith.io --username token --password "${CLOUDSMITH_API_KEY}"
    set -x
    pixi info
    pixi init
    pixi add python=3.12
    EOF
    
    RUN --mount=type=cache,target=/root/.cache/rattler <<EOF
    eza -ahloTDL3 --color always /root/.cache/rattler
    pixi add --pypi -vvv numpy scipy polars pyarrow
    EOF
    
    
    WORKDIR /uv-app
    
    RUN <<EOF
    pixi init
    pixi add python=3.12
    EOF
    
    RUN --mount=type=cache,target=/tmp/uv/cache <<EOF
    eza -ahloTDL2 --color always /tmp/uv/cache
    pixi run uv pip install -v --cache-dir /tmp/uv/cache numpy scipy polars pyarrow
    EOF
    
  6. dhirschfeld commented on Feb 15, 2026

    @dhirschfeld
    ContributorAuthor

    This is caused by us not (yet) storing the indexes for each wheel in the lockfile. We are currently working on this.

    Given it involves changes to the lockfile I assume it'll be part of:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions