|
| 1 | +# PEP 751 pylock.toml Support |
| 2 | + |
| 3 | +Pipenv supports [PEP 751](https://peps.python.org/pep-0751/) pylock.toml files, which provide a standardized format for recording Python dependencies to enable installation reproducibility. |
| 4 | + |
| 5 | +## What is pylock.toml? |
| 6 | + |
| 7 | +The pylock.toml file is a standardized lock file format introduced in PEP 751. It is designed to be: |
| 8 | + |
| 9 | +- Human-readable and machine-generated |
| 10 | +- Secure by default (includes file hashes) |
| 11 | +- Able to support both single-use and multi-use lock files |
| 12 | +- Compatible across different Python packaging tools |
| 13 | + |
| 14 | +## Using pylock.toml with Pipenv |
| 15 | + |
| 16 | +Pipenv can automatically detect and use pylock.toml files in your project. When both a Pipfile.lock and a pylock.toml file exist, Pipenv will prioritize the pylock.toml file. |
| 17 | + |
| 18 | +### Reading pylock.toml Files |
| 19 | + |
| 20 | +When you run commands like `pipenv install` or `pipenv sync`, Pipenv will check for a pylock.toml file in your project directory. If found, it will use the dependencies specified in the pylock.toml file instead of Pipfile.lock. |
| 21 | + |
| 22 | +Pipenv looks for pylock.toml files in the following order: |
| 23 | +1. A file named `pylock.toml` in the project directory |
| 24 | +2. A file matching the pattern `pylock.*.toml` in the project directory |
| 25 | + |
| 26 | +### Example pylock.toml File |
| 27 | + |
| 28 | +Here's a simplified example of a pylock.toml file: |
| 29 | + |
| 30 | +```toml |
| 31 | +lock-version = '1.0' |
| 32 | +environments = ["sys_platform == 'win32'", "sys_platform == 'linux'", "sys_platform == 'darwin'"] |
| 33 | +requires-python = '>=3.8' |
| 34 | +extras = [] |
| 35 | +dependency-groups = [] |
| 36 | +default-groups = [] |
| 37 | +created-by = 'pipenv' |
| 38 | + |
| 39 | +[[packages]] |
| 40 | +name = 'requests' |
| 41 | +version = '2.28.1' |
| 42 | +requires-python = '>=3.7' |
| 43 | + |
| 44 | +[[packages.wheels]] |
| 45 | +name = 'requests-2.28.1-py3-none-any.whl' |
| 46 | +upload-time = '2022-07-13T14:00:00Z' |
| 47 | +url = 'https://files.pythonhosted.org/packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c61441f4AE7b7338a82051330d70/requests-2.28.1-py3-none-any.whl' |
| 48 | +size = 61805 |
| 49 | +hashes = {sha256 = 'b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7'} |
| 50 | +``` |
| 51 | + |
| 52 | +## Benefits of Using pylock.toml |
| 53 | + |
| 54 | +- **Standardization**: pylock.toml is a standardized format that can be used by multiple Python packaging tools. |
| 55 | +- **Security**: pylock.toml includes file hashes by default, making it more secure against supply chain attacks. |
| 56 | +- **Flexibility**: pylock.toml can support both single-use and multi-use lock files, allowing for more complex dependency scenarios. |
| 57 | +- **Interoperability**: pylock.toml can be used by different tools, reducing vendor lock-in. |
| 58 | + |
| 59 | +## Limitations |
| 60 | + |
| 61 | +- Currently, Pipenv only supports reading pylock.toml files, not writing them. |
| 62 | +- Some advanced features of pylock.toml, such as environment markers for extras and dependency groups, are not fully supported yet. |
| 63 | + |
| 64 | +## Future Plans |
| 65 | + |
| 66 | +In future releases, Pipenv plans to add support for: |
| 67 | + |
| 68 | +- Writing pylock.toml files |
| 69 | +- Full support for environment markers for extras and dependency groups |
| 70 | +- Converting between Pipfile.lock and pylock.toml formats |
0 commit comments