Skip to content

Commit

Permalink
Fix requirement parser (bazelbuild#1009)
Browse files Browse the repository at this point in the history
Fix requirements_parser.bzl

Space in requirement.txt should delimit options into distinct arguments.
Otherwise, `pip` would be invoked with incorrect argument containing
space.
  • Loading branch information
tgeng authored and ianpegg-bc committed May 12, 2023
1 parent d6508e2 commit 497fae2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions python/pip_install/private/test/requirements_parser_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ certifi==2021.10.8 \

# Options
asserts.equals(env, ["--pre"], parse("--pre\n").options)
asserts.equals(env, ["--find-links /my/local/archives"], parse("--find-links /my/local/archives\n").options)
asserts.equals(env, ["--pre", "--find-links /my/local/archives"], parse("""\
asserts.equals(env, ["--find-links", "/my/local/archives"], parse("--find-links /my/local/archives\n").options)
asserts.equals(env, ["--pre", "--find-links", "/my/local/archives"], parse("""\
--pre
--find-links /my/local/archives
""").options)
asserts.equals(env, ["--pre", "--find-links /my/local/archives"], parse("""\
asserts.equals(env, ["--pre", "--find-links", "/my/local/archives"], parse("""\
--pre # Comment
--find-links /my/local/archives
""").options)
asserts.equals(env, struct(requirements = [("FooProject", "FooProject==1.0.0")], options = ["--pre", "--find-links /my/local/archives"]), parse("""\
asserts.equals(env, struct(requirements = [("FooProject", "FooProject==1.0.0")], options = ["--pre", "--find-links", "/my/local/archives"]), parse("""\
--pre # Comment
FooProject==1.0.0
--find-links /my/local/archives
Expand Down
3 changes: 3 additions & 0 deletions python/pip_install/requirements_parser.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def _handleParseDependency(input, buffer, result):
def _handleParseOption(input, buffer, result):
if input == "\n" and buffer.endswith("\\"):
return (_STATE.ParseOption, buffer[0:-1])
elif input == " ":
result.options.append(buffer.rstrip("\n"))
return (_STATE.ParseOption, "")
elif input == "\n" or input == EOF:
result.options.append(buffer.rstrip("\n"))
return (_STATE.ConsumeSpace, "")
Expand Down

0 comments on commit 497fae2

Please sign in to comment.