Skip to content

Commit c65343c

Browse files
committed
pylock: read tool sections
1 parent ea9f595 commit c65343c

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/pip/_internal/models/pylock.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,18 @@ def from_dict(cls, d: Dict[str, Any]) -> "Self":
342342
@dataclass
343343
class Package:
344344
name: str
345-
version: Optional[Version] = None
346-
marker: Optional[Marker] = None
347-
requires_python: Optional[SpecifierSet] = None
345+
version: Optional[Version]
346+
marker: Optional[Marker]
347+
requires_python: Optional[SpecifierSet]
348348
# (not supported) dependencies
349-
vcs: Optional[PackageVcs] = None
350-
directory: Optional[PackageDirectory] = None
351-
archive: Optional[PackageArchive] = None
349+
vcs: Optional[PackageVcs]
350+
directory: Optional[PackageDirectory]
351+
archive: Optional[PackageArchive]
352352
# (not supported) index: Optional[str]
353-
sdist: Optional[PackageSdist] = None
354-
wheels: Optional[List[PackageWheel]] = None
353+
sdist: Optional[PackageSdist]
354+
wheels: Optional[List[PackageWheel]]
355355
# (not supported) attestation_identities: Optional[List[Dict[str, Any]]]
356-
# (not supported) tool: Optional[Dict[str, Any]]
356+
tool: Optional[Dict[str, Any]]
357357

358358
def __post_init__(self) -> None:
359359
if self.sdist or self.wheels:
@@ -382,6 +382,7 @@ def from_dict(cls, d: Dict[str, Any]) -> "Self":
382382
archive=_get_object(d, PackageArchive, "archive"),
383383
sdist=_get_object(d, PackageSdist, "sdist"),
384384
wheels=_get_list_of_objects(d, PackageWheel, "wheels"),
385+
tool=_get(d, dict, "tool"),
385386
)
386387
return package
387388

@@ -396,7 +397,7 @@ class Pylock:
396397
default_groups: List[str]
397398
created_by: str
398399
packages: List[Package]
399-
# (not supported) tool: Optional[Dict[str, Any]]
400+
tool: Optional[Dict[str, Any]]
400401

401402
def __post_init__(self) -> None:
402403
if self.lock_version < Version("1") or self.lock_version >= Version("2"):
@@ -422,4 +423,5 @@ def from_dict(cls, d: Dict[str, Any]) -> "Self":
422423
created_by=_get_required(d, str, "created-by"),
423424
requires_python=_get_as(d, str, SpecifierSet, "requires-python"),
424425
packages=_get_required_list_of_objects(d, Package, "packages"),
426+
tool=_get(d, dict, "tool"),
425427
)

src/pip/_internal/utils/pylock.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def _pylock_package_from_install_requirement(
105105
archive=package_archive,
106106
sdist=package_sdist,
107107
wheels=package_wheels,
108+
tool=None,
108109
)
109110

110111

@@ -126,6 +127,7 @@ def pylock_from_install_requirements(
126127
),
127128
key=lambda p: p.name,
128129
),
130+
tool=None,
129131
)
130132

131133

tests/unit/test_pylock.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,26 @@ def test_pylock_extras_and_groups() -> None:
227227
assert pylock.extras == ["feat1", "feat2"]
228228
assert pylock.dependency_groups == ["dev", "docs"]
229229
assert pylock.default_groups == ["dev"]
230+
231+
232+
def test_pylock_tool() -> None:
233+
data = {
234+
"lock-version": "1.0",
235+
"created-by": "pip",
236+
"packages": [
237+
{
238+
"name": "example",
239+
"sdist": {
240+
"name": "example-1.0.tar.gz",
241+
"path": "./example-1.0.tar.gz",
242+
"hashes": {"sha256": "f" * 40},
243+
},
244+
"tool": {"pip": {"foo": "bar"}},
245+
}
246+
],
247+
"tool": {"pip": {"version": "25.2"}},
248+
}
249+
pylock = Pylock.from_dict(data)
250+
assert pylock.tool == {"pip": {"version": "25.2"}}
251+
package = pylock.packages[0]
252+
assert package.tool == {"pip": {"foo": "bar"}}

0 commit comments

Comments
 (0)