Skip to content

Commit 2f1d4a0

Browse files
committed
Warn if --hash is used on a line without requirement
in a requirements file
1 parent 81f6a9f commit 2f1d4a0

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
@@ -76,6 +77,8 @@
7677
# the 'dest' string values
7778
SUPPORTED_OPTIONS_REQ_DEST = [str(o().dest) for o in SUPPORTED_OPTIONS_REQ]
7879

80+
logger = logging.getLogger(__name__)
81+
7982

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

0 commit comments

Comments
 (0)