Skip to content

Commit 9a18628

Browse files
committed
pylock: read index field
1 parent 6ae54d3 commit 9a18628

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/pip/_internal/models/pylock.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class Package:
353353
vcs: Optional[PackageVcs]
354354
directory: Optional[PackageDirectory]
355355
archive: Optional[PackageArchive]
356-
# (not supported) index: Optional[str]
356+
index: Optional[str]
357357
sdist: Optional[PackageSdist]
358358
wheels: Optional[List[PackageWheel]]
359359
attestation_identities: Optional[List[Dict[str, Any]]]
@@ -385,6 +385,7 @@ def from_dict(cls, d: Dict[str, Any]) -> "Self":
385385
vcs=_get_object(d, PackageVcs, "vcs"),
386386
directory=_get_object(d, PackageDirectory, "directory"),
387387
archive=_get_object(d, PackageArchive, "archive"),
388+
index=_get(d, str, "index"),
388389
sdist=_get_object(d, PackageSdist, "sdist"),
389390
wheels=_get_list_of_objects(d, PackageWheel, "wheels"),
390391
attestation_identities=_get_list(d, dict, "attestation-identities"),

src/pip/_internal/utils/pylock.py

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def _pylock_package_from_install_requirement(
107107
vcs=package_vcs,
108108
directory=package_directory,
109109
archive=package_archive,
110+
index=None, # not supported
110111
sdist=package_sdist,
111112
wheels=package_wheels,
112113
attestation_identities=None, # not supported

tests/unit/test_utils_pylock.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
from pip._internal.utils.compat import tomllib
77
from pip._internal.utils.pylock import pylock_to_toml
88

9-
# This is the PEP 751 example, with a minor modification to the 'environments'
10-
# field to use double quotes instead of single quotes, since that is what
11-
# 'packaging' does when serializing markers.
9+
# This is the PEP 751 example, with the following differences:
10+
# - a minor modification to the 'environments' field to use double quotes
11+
# instead of single quotes, since that is what 'packaging' does when
12+
# serializing markers;
13+
# - added an index field, which was not demonstrated in the PEP 751 example.
1214

1315
PEP751_EXAMPLE = dedent(
1416
"""\
@@ -37,6 +39,7 @@
3739
dependencies = [
3840
{name = 'attrs'},
3941
]
42+
index = 'https://pypi.org/simple'
4043
wheels = [
4144
{name = 'cattrs-24.1.2-py3-none-any.whl', upload-time = 2024-09-22T14:58:34.812643+00:00, url = 'https://files.pythonhosted.org/packages/c8/d5/867e75361fc45f6de75fe277dd085627a9db5ebb511a87f27dc1396b5351/cattrs-24.1.2-py3-none-any.whl', size = 66446, hashes = {sha256 = '67c7495b760168d931a10233f979b28dc04daf853b30752246f4f8471c6d68d0'}},
4245
]

0 commit comments

Comments
 (0)