Skip to content

Commit aebc0c5

Browse files
authored
Merge pull request #11940 from sbidoul/imp-req-file-parser-sbi
2 parents 3ac7e10 + 2f1d4a0 commit aebc0c5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

news/11935.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warn if ``--hash`` is used on a line without requirement in a requirements file.

src/pip/_internal/req/req_file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Requirements file parsing
33
"""
44

5+
import logging
56
import optparse
67
import os
78
import re
@@ -77,6 +78,8 @@
7778
# the 'dest' string values
7879
SUPPORTED_OPTIONS_REQ_DEST = [str(o().dest) for o in SUPPORTED_OPTIONS_REQ]
7980

81+
logger = logging.getLogger(__name__)
82+
8083

8184
class ParsedRequirement:
8285
def __init__(
@@ -210,6 +213,13 @@ def handle_option_line(
210213
options: Optional[optparse.Values] = None,
211214
session: Optional[PipSession] = None,
212215
) -> None:
216+
if opts.hashes:
217+
logger.warning(
218+
"%s line %s has --hash but no requirement, and will be ignored.",
219+
filename,
220+
lineno,
221+
)
222+
213223
if options:
214224
# percolate options upward
215225
if opts.require_hashes:

0 commit comments

Comments
 (0)