Skip to content

Conversation

@matteius
Copy link
Member

@matteius matteius commented Apr 25, 2025

PEP 751 Experimental pylock.toml Support

This PR adds experimental support for PEP 751 pylock.toml files, which provide a standardized lock file format for recording Python dependencies to enable installation reproducibility.

Features

Reading pylock.toml Files

  • Pipenv can now detect and read pylock.toml files in your project directory
  • When both Pipfile.lock and pylock.toml exist, Pipenv will prioritize pylock.toml
  • Supports both pylock.toml and named variants matching the pattern pylock.*.toml
  • Automatically converts pylock.toml format to internal Pipfile.lock format for seamless compatibility

Writing pylock.toml Files

  • Enable generation by adding use_pylock = true to the [pipenv] section of your Pipfile
  • Whenever pipenv lock updates the lockfile, it will also generate a corresponding pylock.toml
  • Customize the output filename with pylock_name = "name" to generate pylock.<name>.toml

Example Configuration

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "*"

[dev-packages]
pytest = "*"

[pipenv]
use_pylock = true
pylock_name = "dev"  # Optional: generates pylock.dev.toml instead of pylock.toml

#6390

The checklist

  • Associated issue
  • A news fragment in the news/ directory to describe this fix with the extension .bugfix.rst, .feature.rst, .behavior.rst, .doc.rst. .vendor.rst. or .trivial.rst (this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.

@matteius matteius changed the title PEP 751 experimental pylock.yaml support PEP 751 experimental pylock.toml support Apr 25, 2025
@matteius matteius marked this pull request as ready for review December 9, 2025 11:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds experimental support for PEP 751 pylock.toml files to Pipenv, enabling both reading existing pylock files and generating them alongside Pipfile.lock. The implementation provides a standardized lock file format for recording Python dependencies to enable installation reproducibility across different Python packaging tools.

Key changes:

  • New pipenv/utils/pylock.py module implementing PylockFile class with read/write/convert operations
  • Integration with existing Project class to detect and use pylock.toml files
  • Comprehensive test coverage for both unit and integration scenarios

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pipenv/utils/pylock.py Core implementation of PEP 751 pylock.toml handling with conversion utilities
pipenv/project.py Integration of pylock detection, reading, and writing into Project workflow
pipenv/routines/install.py Updated install messaging to reflect pylock.toml usage
tests/unit/test_pylock.py Unit tests for PylockFile class and utility functions
tests/integration/test_pylock.py Integration tests for pylock.toml reading and writing workflows
pylock.toml Root-level pylock.toml generated for pipenv itself
examples/pylock.toml Example pylock.toml file demonstrating format
examples/Pipfile.with_pylock Example Pipfile with pylock configuration
docs/pylock.md Comprehensive documentation for pylock.toml support
news/7751.feature.rst Release note documenting the new feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Mark extras and dependency_groups as intentionally unused pending
future marker evaluation implementation.
…hancements

This commit adds several major enhancements to the PEP 751 pylock.toml support:

## New Features

### pipenv pylock CLI Command
- `pipenv pylock` - Show pylock.toml status
- `pipenv pylock --generate` - Generate pylock.toml from Pipfile.lock
- `pipenv pylock --from-pyproject` - Generate skeleton from pyproject.toml
- `pipenv pylock --validate` - Validate existing pylock.toml file
- `--output` and `--dev-groups` options for customization

### pyproject.toml Support (Path to Pipfile Replacement)
- New `PylockFile.from_pyproject()` method
- Reads [project.dependencies] (PEP 621)
- Reads [project.optional-dependencies] for extras
- Reads [dependency-groups] (PEP 735)
- Creates pylock.toml skeleton for further resolution

### packages.index Field
- Each package now includes its source index URL
- Enables SBOM generation and security auditing
- Extracted from Pipfile.lock _meta.sources

### Configurable Dependency Groups
- `dev_groups` parameter in `from_lockfile()`
- Supports custom dependency group names beyond 'dev'/'test'
- Proper PEP 751 marker syntax: "'group' in dependency_groups"

## Updated Files
- pipenv/cli/command.py: New pylock command
- pipenv/utils/pylock.py: New methods and enhancements
- docs/pylock.md: Comprehensive documentation
- examples/pylock.toml: Updated example with new features
- tests/unit/test_pylock.py: 4 new tests (13 total)
- tests/integration/test_pylock.py: Updated for new example
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 15 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@matteius matteius merged commit 379141d into main Dec 9, 2025
25 of 26 checks passed
@matteius matteius deleted the pep-751-I branch December 9, 2025 20:06
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.

2 participants