Skip to content

Support pylock.toml files in parse_requirements - #280

Draft
di with Copilot wants to merge 2 commits into
masterfrom
copilot/add-pylock-toml-support
Draft

Support pylock.toml files in parse_requirements#280
di with Copilot wants to merge 2 commits into
masterfrom
copilot/add-pylock-toml-support

Conversation

Copilot AI commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

pip 26.1 added experimental support for pylock.toml lock files (PEP 751). This extends pip_api.parse_requirements to parse these files, gated behind a pip >= 26.1 version check.

Changes

  • _is_pylock_file() — detects valid pylock filenames (pylock.toml or pylock.<name>.toml)
  • _parse_pylock_requirements() — parses TOML content, extracting name, version, environment markers, and hashes (from wheels, sdist, archive entries); raises PipError when pip < 26.1
  • parse_requirements() — routes pylock files through the new parser; works both when called directly and when referenced via -r pylock.toml inside a regular requirements file
  • tests/data/pylock.toml — fixture with two packages including wheel hashes
  • Tests — cover version gating, basic parsing, hash extraction, marker filtering, -r inclusion, and pylock.<name>.toml naming

Example

import pip_api

# Direct parsing
reqs = pip_api.parse_requirements("pylock.toml")
# {'foo': <Requirement('foo==1.2.3')>, 'bar': <Requirement('bar==2.0.0')>}

# Also works via -r reference in a requirements.txt
reqs = pip_api.parse_requirements("requirements.txt")
# where requirements.txt contains: -r pylock.toml

# Raises PipError if pip < 26.1
# PipError: Parsing pylock.toml files requires pip >= 26.1, but the current pip version is 24.0

Copilot AI assigned Copilot and di Apr 28, 2026
Copilot AI linked an issue Apr 28, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add support for reading pylock.toml files in pip_api Support pylock.toml files in parse_requirements Apr 28, 2026
Copilot AI requested a review from di April 28, 2026 13:37
Copilot finished work on behalf of di April 28, 2026 13:37
from pip_api._vendor.packaging import requirements, specifiers # type: ignore
from pip_api.exceptions import PipError

_PYLOCK_FILE_NAME_RE = re.compile(r"^pylock(\.[^.]+)?\.toml$")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now that we've vendored packaging==26.2, I bet we could replace a lot of this with packaging.pylock's APIs, e.g. is_valid_pylock_path.

(We could probably also use PyLock.from_dict for stronger validation.)

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.

Support pylock.toml files

3 participants