Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
643c70e
Add pylock
sbidoul May 6, 2025
a28379f
pylock: clarify error messages
sbidoul May 7, 2025
c1601cf
pylock: simplify
sbidoul May 7, 2025
06351c3
pylock: make from_dict a classmethod again
sbidoul May 9, 2025
5540bc4
pylock: Apply suggestions from code review
sbidoul Jul 26, 2025
f1fcc63
pylock: type name as NormalizedName
sbidoul Jul 26, 2025
5b6009c
pylock: type extras as NormalizedName, and validate
sbidoul Jul 26, 2025
cde1384
pylock: move PEP751 example to a standalone file
sbidoul Jul 27, 2025
258d35b
pylock: make more module level stuff "private"
sbidoul Jul 27, 2025
4628411
pylock: re-enable default None values
sbidoul Jul 27, 2025
b9d782b
pylock: add validate method
sbidoul Jul 27, 2025
3df903d
pylock: validate everything in from_dict
sbidoul Jul 27, 2025
a22bcfa
pylock: add documentation
sbidoul Jul 27, 2025
6460df3
pylock: improve version check readability and test coverage
sbidoul Sep 13, 2025
c9eb0f2
pylock: fix and clarify package validation logic
sbidoul Sep 13, 2025
3537c64
pylock: add positional-only parrameter marker to from_dict
sbidoul Oct 9, 2025
f36caf7
pylock: handle review nit
sbidoul Oct 9, 2025
2e41829
pylock: simplify validation of sequences of objects
sbidoul Oct 12, 2025
066a479
pylock: rename helper function for consistency
sbidoul Oct 12, 2025
bdf84b3
pylock: add missing walrus assignment for consistency
sbidoul Oct 12, 2025
2fa5f17
pylock: fix contructor type annotation for extras
sbidoul Oct 12, 2025
686d204
pylock: reject str and bytes when Sequence is expected
sbidoul Oct 12, 2025
394ed84
pylock: make internal exception class private
sbidoul Oct 12, 2025
96ce64a
pylock: validate attestation-identities kind field
sbidoul Oct 17, 2025
02d1db3
Merge branch 'main' into pylock
brettcannon Oct 21, 2025
91cd0dd
Merge branch 'main' into pylock
brettcannon Oct 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The ``packaging`` library uses calendar-based versioning (``YY.N``).
requirements
metadata
tags
pylock
utils

.. toctree::
Expand Down
83 changes: 83 additions & 0 deletions docs/pylock.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Lock Files
==========

.. currentmodule:: packaging.pylock

Parse and validate `pylock.toml files <https://packaging.python.org/en/latest/specifications/pylock-toml/>`_.

Usage
-----

.. code-block:: python

import tomllib
from pathlib import Path

from packaging.pylock import Package, PackageWheel, Pylock
from packaging.utils import NormalizedName
from packaging.version import Version

# validate a pylock file name
assert is_valid_pylock_path(Path("pylock.example.toml"))

# parse and validate pylock file
toml_dict = tomllib.loads(Path("pylock.toml").read_text(encoding="utf-8"))
pylock = PyLock.from_dict(toml_dict)
# the resulting pylock object is validated against the specification,
# else a PylockValidationError is raised

# generate a pylock file
pylock = Pylock(
lock_version=Version("1.0"),
created_by="some_tool",
packages=[
Package(
name=NormalizedName("example-package"),
version=Version("1.0.0"),
wheels=[
PackageWheel(
url="https://example.com/example_package-1.0.0-py3-none-any.whl",
hashes={"sha256": "0fd.."},
)
],
)
],
)
toml_dict = pylock.to_dict()
# use a third-party library to serialize to TOML

# you can validate a manually constructed Pylock class
pylock.validate()

Reference
---------

.. autofunction:: is_valid_pylock_path

The following frozen keyword-only dataclasses are used to represent the
structure of a pylock file. The attributes correspond to the fields in the
pylock file specification.

.. autoclass:: Pylock
:members: from_dict, to_dict, validate
:exclude-members: __init__, __new__

.. class:: Package

.. class:: PackageWheel

.. class:: PackageSdist

.. class:: PackageArchive

.. class:: PackageVcs

.. class:: PackageDirectory

The following exception may be raised by this module:

.. autoexception:: PylockValidationError
:exclude-members: __init__, __new__

.. autoexception:: PylockUnsupportedVersionError
:exclude-members: __init__, __new__
Loading
Loading