Skip to content

feat(pypi)!: private Python indexes from lockfiles; drop pip requirements - #164

Merged
sweepies merged 17 commits into
mainfrom
feat/pypi-registries
Nov 3, 2026
Merged

sweepies merged 17 commits into
mainfrom
feat/pypi-registries

Conversation

@sweepies

@sweepies sweepies commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Phase 3 of #157, PyPI. A Python package can now come from a private index. This builds on PackageId from #162.

Where a package's index comes from: its lockfile

  • uv.lock (at the uv workspace root for members; a member's own lockfile is ignored) and poetry.lock record each package's index. The Count uses what they record; entries that disagree are ambiguous.
  • A package no lockfile records is PyPI's only when the project configures no index at all. Otherwise its lookup fails, asking for a lockfile that records it.
  • Settings are read only to tell whether any index is configured. uv and Poetry settings use strict types; every uv setting is classified, checked against uv's own list, and Poetry's keys against its schema.
  • Anything unreadable fails every lookup, locked or not: unknown keys, unparsable files, symlinked or unreadable settings, uncertain workspace globs, and PDM, Rye, Pixi or Hatch index settings.
  • Packages a manifest takes from git, a path, a URL or a workspace member are listed as skipped.
  • A stale lockfile is caught by the update, which runs the real uv lock or poetry lock.

Earlier revisions predicted the index from each tool's settings; reviews kept finding places where that copy of uv's and Poetry's resolution disagreed with the tools, so the lockfile now decides.

Removed: pip requirements files

The requirements manager is gone (breaking: managers no longer accepts requirements). pip takes each package from whatever index a file's options, includes and environment name; each requirements file is listed as skipped, recommending uv.

Private indexes

Read through the simple API as PEP 691 JSON or PEP 503 HTML, with operator credentials and mirrors, keeping only the requested project's files. Secrets in index URLs are never recorded (URL parsing with a randomised test).

Tests

  • real_python_indexes: generated uv and Poetry projects resolved by the real tools, then read by the Count with the lockfile they wrote; key lists checked against uv and Poetry.
  • Extraction tests for lockfile decisions, fail-closed settings, secrets and skipped packages.

A Python package's registry is its pin (uv `[tool.uv.sources]`, a Poetry
dependency's `source`), else the index its lockfile records (`uv.lock`,
`poetry.lock`), else the only index the project names (pip `--index-url`,
a uv default index or `index-url`, a Poetry primary source; a `uv.toml`
replaces `[tool.uv]`). A package that could come from several indexes is
ambiguous: its lookup fails asking for a pin or a lockfile, and it never
falls back to PyPI, where the same name may be someone else's.

Private indexes are read through their simple API, as PEP 691 JSON or PEP
503 HTML. PyPI extractors take a `registry` template. Registry lookups
that cannot run say why. The extraction cache key moves to v13.

Refs #157
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 515f977 Commit Preview URL

Branch Preview URL
Nov 03 2026, 09:13 PM

@deepsource-io

deepsource-io Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in f737a97...515f977 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Nov 3, 2026 9:15p.m. Review ↗
JavaScript Nov 3, 2026 9:15p.m. Review ↗
Shell Nov 3, 2026 9:15p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Comment thread crates/manager/src/pyproject.rs Outdated
Comment on lines +161 to +170
source
.get("priority")
.and_then(Item::as_str)
.unwrap_or(if legacy("default") {
"default"
} else if legacy("secondary") {
"supplemental"
} else {
"primary"
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead


Calls to unwrap_or followed by a function call should be replaced with
unwrap_or_else or unwrap_or_default, to increase laziness. The argument to
unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or
unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.

@context7

context7 Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Docs7 for sweepies/count-patchula

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit 515f977

From review:
- `[tool.uv.sources]` pins come from the project and its workspace root
  whatever a `uv.toml` says; index settings come from the nearest
  `uv.toml` or `[tool.uv]`, as uv reads them.
- Packages from git, a path, a URL or a workspace member, pinned or
  locked, are left alone instead of looked up on PyPI. Marker-split pins
  to several indexes, and lock entries that disagree, are ambiguous.
- Requirements files share index options across `-r`/`-c` includes;
  `--find-links` adds a non-index source and `--no-index` stops lookups.
- A pin to an undefined index fails; Poetry names match without case,
  and a URL-less PyPI source is PyPI.
- Only the project's own lockfile, or its workspace root's, counts.
- The HTML simple-page parser handles case, quoted `>` and entities.

The corpus drops pydantic's workspace member `pydantic-core`.
Comment thread crates/manager/src/pypi.rs Outdated
Comment on lines +119 to +123
Origin::of(
std::iter::once(Origin::Index(default))
.chain(self.extras.iter().cloned().map(Origin::Index)),
)
.unwrap_or(Origin::Index(Named::Public))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead


Calls to unwrap_or followed by a function call should be replaced with
unwrap_or_else or unwrap_or_default, to increase laziness. The argument to
unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or
unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reverted: clippy (unnecessary_lazy_evaluations, which CI enforces with -D warnings) rejects the closure here, since building Origin::Index(Named::Public) costs nothing.

Clippy's unnecessary_lazy_evaluations rejects the closure DeepSource
suggested; constructing the variant is free.
Comment thread crates/manager/src/pypi.rs Outdated
Comment on lines +119 to +123
Origin::of(
std::iter::once(Origin::Index(default))
.chain(self.extras.iter().cloned().map(Origin::Index)),
)
.unwrap_or(Origin::Index(Named::Public))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead


Calls to unwrap_or followed by a function call should be replaced with
unwrap_or_else or unwrap_or_default, to increase laziness. The argument to
unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or
unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.

A match satisfies both clippy and DeepSource, which disagree on
unwrap_or here.
From a second review:
- Every pyproject.toml, uv.toml, uv.lock and poetry.lock is fetched when
  pyproject is on, and every .txt/.in outside `exclude` when requirements
  is, whatever `files` selects, so a workspace root or `-r` target is never
  missed.
- Requirements options come only from .txt/.in files, parsed once per
  scan; joined short options and line continuations are read.
- Registry values the Count cannot use are recorded without user,
  password or query, for npm and PyPI alike.
- Poetry's built-in `pypi` source counts as PyPI.
- Packages from git, a path, a URL or a workspace member are reported as
  skipped.

Docs: `--no-index` fails lookups; requirements files read only their own
options; PDM sources are not read yet.
Requirements includes are fetched by following -r and -c rather than
reading every text file, and a file takes the options of each pip run
that reads it. An include the Count cannot read makes its run ambiguous.
uv workspace members take index settings from their root, membership
follows members and exclude, find-links, flat indexes and no-index are
read, and an unparsable pyproject.toml or uv.toml above a project fails
its lookups. PDM sources are read. Redaction handles a slash in a
password and a query with no path.
Comment thread crates/manager/src/pyproject.rs Outdated
Comment on lines +540 to +543
let member = ancestors[0]
.strip_prefix(*dir)
.map(|rest| rest.trim_start_matches('/'))
.unwrap_or(ancestors[0]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Called `.map().unwrap_or()` on a `Option` value, use `.map_or(, )`


Chains of the form .map(..).unwrap_or(..) can be simplified to use .map_or(..). These shorthands
are available on Result as well as Option. Replace:

  • .map(<f>).unwrap_or(<g>) with .map_or(<g>, <f>)
  • .map(<f>).unwrap_or_else(<g>) with .map_or_else(<g>, <f>)

Workspace membership uses the nearest root and normalises ./ and
trailing slashes in its globs. Requirements runs start from every file
named like one, even an excluded one, and the default name pattern
takes dev-requirements.txt and the like. Includes through symlinks stay
unread, at most 256 are fetched, concurrently, and a failed fetch leaves
the include unread instead of failing the scan. A byte order mark and
quoted include paths are read as pip reads them. Redaction drops a
password holding ? or #, and an unusable registry fails without a
request.
The Count now reads a fixed list of pip options, uv settings and index
keys, Poetry and PDM source keys and pin keys, and anything else that
could move a package makes its lookup fail instead of falling back to
PyPI. Pins that hold only under markers, extras, groups or Pythons are
ambiguous. Redaction parses URLs with the url crate and records
<unreadable URL> for any it cannot split cleanly, with a randomised test
that no secret survives. A real_ test resolves fixtures with uv, pip and
Poetry against a local index server and checks the Count's choice of
index against theirs.
Comment thread crates/manager/src/lib.rs Outdated
usize::try_from(state % bound as u64).unwrap_or_default()
};
for _ in 0..20_000 {
let secret: String = (0..1 + next(12))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Found exclusive range where 1 is added to upper bound: `0..1 + next(12)`


Exclusive ranges where 1 is added to the upper bound, e.g., 1..x + 1 are more
readable when written with an inclusive range, e.g., 1..=x.

…ements

uv and Poetry index settings are read into types that describe every
key the Count understands and reject the rest, so [[x]] and inline
arrays read alike and nothing is skipped unread. Every setting uv
accepts is classified as read or irrelevant, and real_ tests check the
lists against uv's own and Poetry's schemas. PDM, Rye, Pixi and Hatch
settings that could name an index fail closed. A lockfile entry for an
index the project no longer searches is ambiguous, as is a uv.lock
entry without a source. A generated real_ test compares the Count's
choice of index with uv's and Poetry's across declaration forms, roles,
pin forms and workspace layouts.

The requirements manager is removed: pip's index can be set by options,
includes and the environment in ways the Count cannot settle from the
repository. A repository with pip requirements files gets a warning
recommending a move to uv.
Comment thread crates/manager/src/pypi.rs Outdated
Comment on lines +127 to +131
Some(Origin::Index(named)) if !candidates.contains(&named) => Origin::of(
std::iter::once(Origin::Index(named))
.chain(candidates.into_iter().map(Origin::Index)),
)
.unwrap_or(Origin::Index(Named::Public)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead


Calls to unwrap_or followed by a function call should be replaced with
unwrap_or_else or unwrap_or_default, to increase laziness. The argument to
unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or
unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.

Comment thread crates/manager/src/pypi.rs Outdated
Comment on lines +133 to +134
None => Origin::of(candidates.into_iter().map(Origin::Index))
.unwrap_or(Origin::Index(Named::Public)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead


Calls to unwrap_or followed by a function call should be replaced with
unwrap_or_else or unwrap_or_default, to increase laziness. The argument to
unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or
unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.

Comment thread crates/manager/src/pypi/settings.rs Outdated
Comment on lines +482 to +494
match (globs(&workspace.members), globs(&workspace.exclude)) {
(Some(members), Some(exclude)) => (!workspace.members.is_empty()
&& members.matches(member)
&& (workspace.exclude.is_empty() || !exclude.matches(member)))
.then_some(dir),
_ => {
indexes.extras.push(unreadable(format!(
"workspace globs in {}",
join(dir, "pyproject.toml")
)));
None
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using match to destructure a single pattern: `(Some(members), Some(exclude))`, prefer an `if-let-else`


match statements with only one useful arm can be reduced to an if-else statement.
This helps improve readability, an if-else statement nests lesser than a match.

Whether a lock entry without a source means PyPI depends on the tool
that wrote it, so the lockfile's name decides, not its contents. Fixtures
now carry the source uv always writes.
…rements files quietly

uv's [pip] table names indexes uv pip reads for the project, so they are
candidates. A lockfile counts only when its tool could have written it,
and a project with both [tool.uv] and [tool.poetry] takes both tools'
indexes as candidates. Conflicting pins across Poetry groups are
ambiguous. PDM, Rye, Pixi and Hatch settings fail closed in any ancestor
and in pdm.toml, pixi.toml and hatch.toml, and a settings file behind a
symlink or not in UTF-8 is unreadable, not absent. Workspace globs use
globset as filesystem globs do, a URL's scheme is case-insensitive, and a
private index page lends a project only its own files' versions.

pip requirements files are reported as skipped rather than as a
warning, which would have held back branch cleanup and automerge. The
real-tool test now checks that a PyPI expectation reached PyPI, covers
overrides, no-sources and root pins, and checks uv's [pip] keys; it
showed that uv ignores overrides in uv.toml when locking.
Working out which index uv or Poetry would pick from their settings
meant re-implementing each tool's resolution, and every review found
another place the copy disagreed with the tool. The lockfile is the
tool's own answer: a package uv.lock or poetry.lock records comes from
what it records, uv's taken at the workspace root. A package no lockfile
records is PyPI's only where the project configures no index at all;
elsewhere its lookup fails until a lockfile records it. Settings are
read only to tell whether any index is configured, and anything the
Count cannot read still fails every lookup, locked or not. A stale lock
is caught by the update itself, which runs the real tool with the
project's settings.

Packages from git, a path, a URL or a workspace member, by source, by
Poetry dependency or by a name @ url requirement, are reported as
skipped. Requirements files are listed as skipped rather than as a
warning, and an unreadable local settings file counts as unreadable.
@sweepies sweepies changed the title feat(pypi): look Python packages up in the index the project pins feat(pypi)!: private Python indexes from lockfiles; drop pip requirements Nov 3, 2026
@sweepies
sweepies merged commit b6fbeb6 into main Nov 3, 2026
16 checks passed
@sweepies
sweepies deleted the feat/pypi-registries branch November 3, 2026 21:27
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.

1 participant