summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzu-ping Chung <uranusjr@gmail.com>2023-04-10 15:46:55 +0800
committerGitHub <noreply@github.com>2023-04-10 15:46:55 +0800
commitaebc0c5fc321141ede837c80572427ab7b795c3f (patch)
tree2515d5530574ce4bbebfa87904d8a0d6096ce847
parent3ac7e10c302bee199f84965ad34ae4adb7769bbb (diff)
parent2f1d4a0218f9daf013292be9656c362cbc1760e1 (diff)
downloadpip-aebc0c5fc321141ede837c80572427ab7b795c3f.tar.gz
Merge pull request #11940 from sbidoul/imp-req-file-parser-sbi
-rw-r--r--news/11935.feature.rst1
-rw-r--r--src/pip/_internal/req/req_file.py10
2 files changed, 11 insertions, 0 deletions
diff --git a/news/11935.feature.rst b/news/11935.feature.rst
new file mode 100644
index 000000000..b170ca1d8
--- /dev/null
+++ b/news/11935.feature.rst
@@ -0,0 +1 @@
+Warn if ``--hash`` is used on a line without requirement in a requirements file.
diff --git a/src/pip/_internal/req/req_file.py b/src/pip/_internal/req/req_file.py
index 18e77b6c0..f717c1ccc 100644
--- a/src/pip/_internal/req/req_file.py
+++ b/src/pip/_internal/req/req_file.py
@@ -2,6 +2,7 @@
Requirements file parsing
"""
+import logging
import optparse
import os
import re
@@ -77,6 +78,8 @@ SUPPORTED_OPTIONS_REQ: List[Callable[..., optparse.Option]] = [
# the 'dest' string values
SUPPORTED_OPTIONS_REQ_DEST = [str(o().dest) for o in SUPPORTED_OPTIONS_REQ]
+logger = logging.getLogger(__name__)
+
class ParsedRequirement:
def __init__(
@@ -210,6 +213,13 @@ def handle_option_line(
options: Optional[optparse.Values] = None,
session: Optional[PipSession] = None,
) -> None:
+ if opts.hashes:
+ logger.warning(
+ "%s line %s has --hash but no requirement, and will be ignored.",
+ filename,
+ lineno,
+ )
+
if options:
# percolate options upward
if opts.require_hashes: