Skip to content

Commit

Permalink
Merge pull request pypa#11940 from sbidoul/imp-req-file-parser-sbi
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Apr 10, 2023
2 parents 3ac7e10 + 2f1d4a0 commit aebc0c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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 @@ -77,6 +78,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 @@ -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:
Expand Down

0 comments on commit aebc0c5

Please sign in to comment.