Skip to content

Commit 43e18f0

Browse files
authored
Fix requirement parser (#1009)
Fix requirements_parser.bzl Space in requirement.txt should delimit options into distinct arguments. Otherwise, `pip` would be invoked with incorrect argument containing space.
1 parent 6c6c70b commit 43e18f0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

python/pip_install/private/test/requirements_parser_tests.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ certifi==2021.10.8 \
6060

6161
# Options
6262
asserts.equals(env, ["--pre"], parse("--pre\n").options)
63-
asserts.equals(env, ["--find-links /my/local/archives"], parse("--find-links /my/local/archives\n").options)
64-
asserts.equals(env, ["--pre", "--find-links /my/local/archives"], parse("""\
63+
asserts.equals(env, ["--find-links", "/my/local/archives"], parse("--find-links /my/local/archives\n").options)
64+
asserts.equals(env, ["--pre", "--find-links", "/my/local/archives"], parse("""\
6565
--pre
6666
--find-links /my/local/archives
6767
""").options)
68-
asserts.equals(env, ["--pre", "--find-links /my/local/archives"], parse("""\
68+
asserts.equals(env, ["--pre", "--find-links", "/my/local/archives"], parse("""\
6969
--pre # Comment
7070
--find-links /my/local/archives
7171
""").options)
72-
asserts.equals(env, struct(requirements = [("FooProject", "FooProject==1.0.0")], options = ["--pre", "--find-links /my/local/archives"]), parse("""\
72+
asserts.equals(env, struct(requirements = [("FooProject", "FooProject==1.0.0")], options = ["--pre", "--find-links", "/my/local/archives"]), parse("""\
7373
--pre # Comment
7474
FooProject==1.0.0
7575
--find-links /my/local/archives

python/pip_install/requirements_parser.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def _handleParseDependency(input, buffer, result):
9696
def _handleParseOption(input, buffer, result):
9797
if input == "\n" and buffer.endswith("\\"):
9898
return (_STATE.ParseOption, buffer[0:-1])
99+
elif input == " ":
100+
result.options.append(buffer.rstrip("\n"))
101+
return (_STATE.ParseOption, "")
99102
elif input == "\n" or input == EOF:
100103
result.options.append(buffer.rstrip("\n"))
101104
return (_STATE.ConsumeSpace, "")

0 commit comments

Comments
 (0)