8000 fix: allow url fragments in requirements file (#1195) · chrislovecnm/rules_python@02ace45 · GitHub
[go: up one dir, main page]

Skip to content

Commit 02ace45

Browse files
authored
fix: allow url fragments in requirements file (bazel-contrib#1195)
This commit addresses issue bazel-contrib#1194 (see issue for details). It brings the `comment` detection of `requirements_parser.bzl` closer to the spec described here: - https://pip.pypa.io/en/stable/reference/requirements-file-format/#comments 1. Lines that begin with `#` are comments. 2. Content after (and including) ` #` is a comment. Prior to this commit, a dependency like this would result in invalid `pip wheel` arguments: ``` requests @ https://github.com/psf/requests/releases/download/v2.29.0/requests-2.29.0.tar.gz#sha1=3897c249b51a1a405d615a8c9cb92e5fdbf0dd49 ```
1 parent 07e6856 commit 02ace45

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

python/pip_install/private/test/requirements_parser_tests.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ SomeProject == 1.3 # This is a comment
6262
FooProject==1.0.0
6363
# Comment
6464
BarProject==2.0.0 #Comment
65+
""").requirements)
66+
asserts.equals(env, [("requests", "requests @ https://github.com/psf/requests/releases/download/v2.29.0/requests-2.29.0.tar.gz#sha1=3897c249b51a1a405d615a8c9cb92e5fdbf0dd49")], parse("""\
67+
requests @ https://github.com/psf/requests/releases/download/v2.29.0/requests-2.29.0.tar.gz#sha1=3897c249b51a1a405d615a8c9cb92e5fdbf0dd49
6568
""").requirements)
6669

6770
# Multiline
@@ -71,6 +74,11 @@ certifi==2021.10.8 \
7174
--hash=sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569
7275
# via requests
7376
""").requirements)
77+
asserts.equals(env, [("requests", "requests @ https://github.com/psf/requests/releases/download/v2.29.0/requests-2.29.0.tar.gz#sha1=3897c249b51a1a405d615a8c9cb92e5fdbf0dd49 --hash=sha256:eca58eb564b134e4ff521a02aa6f566c653835753e1fc8a50a20cb6bee4673cd")], parse("""\
78+
requests @ https://github.com/psf/requests/releases/download/v2.29.0/requests-2.29.0.tar.gz#sha1=3897c249b51a1a405d615a8c9cb92e5fdbf0dd49 \
79+
--hash=sha256:eca58eb564b134e4ff521a02aa6f566c653835753e1fc8a50a20cb6bee4673cd
80+
# via requirements.txt
81+
""").requirements)
7482

7583
# Options
7684
asserts.equals(env, ["--pre"], parse("--pre\n").options)

python/pip_install/requirements_parser.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _handleParseOption(input, buffer, result):
116116
elif input == "\n" or input == EOF:
117117
result.options.append(buffer.rstrip("\n"))
118118
return (_STATE.ConsumeSpace, "")
119-
elif input == "#":
119+
elif input == "#" and (len(buffer) == 0 or buffer[-1].isspace()):
120120
return (_STATE.ConsumeComment, buffer)
121121

122122
return (_STATE.ParseOption, buffer + input)
@@ 61FD -127,7 +127,7 @@ def _handleParseRequirement(input, buffer, result):
127127
elif input == "\n" or input == EOF:
128128
result.requirements[-1] = (result.requirements[-1][0], buffer.rstrip(" \n"))
129129
return (_STATE.ConsumeSpace, "")
130-
elif input == "#":
130+
elif input == "#" and (len(buffer) == 0 or buffer[-1].isspace()):
131131
return (_STATE.ConsumeComment, buffer)
132132

133133
return (_STATE.ParseRequirement, buffer + input)

0 commit comments

Comments
 (0)
0