Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/11935.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warn if ``--hash`` is used on a line without requirement in a requirements file.
10 changes: 10 additions & 0 deletions src/pip/_internal/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Requirements file parsing
"""

import logging
import optparse
import os
import re
Expand Down Expand Up @@ -76,6 +77,8 @@
# 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__(
Expand Down Expand Up @@ -209,6 +212,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:
Expand Down