Skip to content

Commit 335e114

Browse files
authored
Merge pull request #11966 from sbidoul/clarify-is-direct-sbi
Add ireq.is_direct property, for readability
2 parents 5c06e60 + 0621e5a commit 335e114

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/pip/_internal/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def body(self) -> str:
544544
# so the output can be directly copied into the requirements file.
545545
package = (
546546
self.req.original_link
547-
if self.req.original_link
547+
if self.req.is_direct
548548
# In case someone feeds something downright stupid
549549
# to InstallRequirement's constructor.
550550
else getattr(self.req, "req", None)

src/pip/_internal/models/installation_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _install_req_to_dict(cls, ireq: InstallRequirement) -> Dict[str, Any]:
2222
# is_direct is true if the requirement was a direct URL reference (which
2323
# includes editable requirements), and false if the requirement was
2424
# downloaded from a PEP 503 index or --find-links.
25-
"is_direct": bool(ireq.original_link),
25+
"is_direct": ireq.is_direct,
2626
# requested is true if the requirement was specified by the user (aka
2727
# top level requirement), and false if it was installed as a dependency of a
2828
# requirement. https://peps.python.org/pep-0376/#requested

src/pip/_internal/operations/prepare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def _get_linked_req_hashes(self, req: InstallRequirement) -> Hashes:
352352
# a surprising hash mismatch in the future.
353353
# file:/// URLs aren't pinnable, so don't complain about them
354354
# not being pinned.
355-
if req.original_link is None and not req.is_pinned:
355+
if not req.is_direct and not req.is_pinned:
356356
raise HashUnpinned()
357357

358358
# If known-good hashes are missing for this requirement,

src/pip/_internal/req/req_install.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def __init__(
104104
if link.is_file:
105105
self.source_dir = os.path.normpath(os.path.abspath(link.file_path))
106106

107+
# original_link is the direct URL that was provided by the user for the
108+
# requirement, either directly or via a constraints file.
107109
if link is None and req and req.url:
108110
# PEP 508 URL requirement
109111
link = Link(req.url)
@@ -244,6 +246,11 @@ def supports_pyproject_editable(self) -> bool:
244246
def specifier(self) -> SpecifierSet:
245247
return self.req.specifier
246248

249+
@property
250+
def is_direct(self) -> bool:
251+
"""Whether this requirement was specified as a direct URL."""
252+
return self.original_link is not None
253+
247254
@property
248255
def is_pinned(self) -> bool:
249256
"""Return whether I am pinned to an exact version.
@@ -293,7 +300,7 @@ def hashes(self, trust_internet: bool = True) -> Hashes:
293300
good_hashes = self.hash_options.copy()
294301
if trust_internet:
295302
link = self.link
296-
elif self.original_link and self.user_supplied:
303+
elif self.is_direct and self.user_supplied:
297304
link = self.original_link
298305
else:
299306
link = None
@@ -804,7 +811,7 @@ def install(
804811
req_description=str(self.req),
805812
pycompile=pycompile,
806813
warn_script_location=warn_script_location,
807-
direct_url=self.download_info if self.original_link else None,
814+
direct_url=self.download_info if self.is_direct else None,
808815
requested=self.user_supplied,
809816
)
810817
self.install_succeeded = True

0 commit comments

Comments
 (0)