Skip to content

Commit 3517841

Browse files
committed
-r pylock: refine filename pylock-ness test
1 parent 2f7ad8c commit 3517841

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/pip/_internal/cli/cmdoptions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from textwrap import dedent
2323
from typing import Any, Callable
2424

25-
from pip._vendor.packaging import pylock
2625
from pip._vendor.packaging.utils import canonicalize_name
2726

2827
from pip._internal.cli.parser import ConfigOptionParser
@@ -32,6 +31,7 @@
3231
from pip._internal.models.index import PyPI
3332
from pip._internal.models.release_control import ReleaseControl
3433
from pip._internal.models.target_python import TargetPython
34+
from pip._internal.utils import pylock as pylock_utils
3535
from pip._internal.utils.datetime import parse_iso_datetime
3636
from pip._internal.utils.hashes import STRONG_HASHES
3737
from pip._internal.utils.misc import strtobool
@@ -105,8 +105,7 @@ def check_dist_restriction(options: Values, check_target: bool = False) -> None:
105105
)
106106

107107
for filename in options.requirements:
108-
# TODO: filename may be a URL, so pathlib.Path may not be entirely correct
109-
if dist_restriction_set and pylock.is_valid_pylock_path(pathlib.Path(filename)):
108+
if dist_restriction_set and pylock_utils.is_valid_pylock_filename(filename):
110109
raise CommandError(
111110
"Patform and interpreter constraints using "
112111
"--python-version, --platform, --abi, or --implementation, "

src/pip/_internal/cli/req_command.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
import os
1212
from functools import partial
1313
from optparse import Values
14-
from pathlib import Path
1514
from typing import Any, Callable, TypeVar
1615

17-
from pip._vendor.packaging import pylock
18-
1916
from pip._internal.build_env import (
2017
BuildEnvironmentInstaller,
2118
InprocessBuildEnvironmentInstaller,
@@ -51,7 +48,10 @@
5148
from pip._internal.req.req_install import InstallRequirement
5249
from pip._internal.resolution.base import BaseResolver
5350
from pip._internal.utils.packaging import check_requires_python
54-
from pip._internal.utils.pylock import select_from_pylock_path_or_url
51+
from pip._internal.utils.pylock import (
52+
is_valid_pylock_filename,
53+
select_from_pylock_path_or_url,
54+
)
5555
from pip._internal.utils.temp_dir import (
5656
TempDirectory,
5757
TempDirectoryTypeRegistry,
@@ -337,8 +337,7 @@ def get_requirements(
337337

338338
# NOTE: options.require_hashes may be set if --require-hashes is True
339339
for filename in options.requirements:
340-
# TODO: filename may be a URL, so pathlib.Path may not be entirely correct
341-
if pylock.is_valid_pylock_path(Path(filename)):
340+
if is_valid_pylock_filename(filename):
342341
logger.warning(
343342
"Using pylock.toml as a requirements source "
344343
"is an experimental feature. "

src/pip/_internal/utils/pylock.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
PackageVcs,
1616
PackageWheel,
1717
Pylock,
18+
is_valid_pylock_path,
1819
)
1920
from pip._vendor.packaging.version import Version
2021

2122
from pip._internal.exceptions import InstallationError
2223
from pip._internal.models.link import Link
23-
from pip._internal.req.req_install import InstallRequirement
2424
from pip._internal.utils.compat import tomllib
2525
from pip._internal.utils.urls import path_to_url, url_to_path
2626

2727
if TYPE_CHECKING:
2828
from pip._internal.network.session import PipSession
29+
from pip._internal.req.req_install import InstallRequirement
2930

3031

3132
def _pylock_package_from_install_requirement(
@@ -135,6 +136,14 @@ def _is_url(s: str) -> bool:
135136
return bool(_SCHEME_RE.match(s))
136137

137138

139+
def is_valid_pylock_filename(filename: str) -> bool:
140+
if _is_url(filename):
141+
path = Path(urlsplit(filename).path.rpartition("/")[-1])
142+
else:
143+
path = Path(filename)
144+
return is_valid_pylock_path(path)
145+
146+
138147
def _package_dist_url(
139148
pylock_path_or_url: str, path: str | None, url: str | None
140149
) -> str:

0 commit comments

Comments
 (0)