Skip to content

Commit

Permalink
fix(py_wheel): Fix parsing errors with requires_file attribute. (#1719
Browse files Browse the repository at this point in the history
)

The `requires_file` and `extra_requires_files` attributes added by
#1710 break wheels by
leaving trailing `;` and currently do not support `requirements.in`
files with comments following a constraint on the same line. This PR
fixes these issues.
  • Loading branch information
UebelAndre committed Jan 24, 2024
1 parent 3730191 commit 341db3c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/wheel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ write_file(
--index-url https://pypi.com
tomli>=2.0.0
starlark # Example comment
""".splitlines(),
)

Expand All @@ -290,7 +291,7 @@ write_file(
pyyaml>=6.0.0,!=6.0.1
toml; (python_version == "3.11" or python_version == "3.12") and python_version != "3.8"
wheel; python_version == "3.11" or python_version == "3.12"
wheel; python_version == "3.11" or python_version == "3.12" # Example comment
""".splitlines(),
)

Expand Down
3 changes: 2 additions & 1 deletion examples/wheel/wheel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ def test_requires_file_and_extra_requires_files(self):
print(requires)
self.assertEqual(
[
"Requires-Dist: tomli>=2.0.0;",
"Requires-Dist: tomli>=2.0.0",
"Requires-Dist: starlark",
"Requires-Dist: pyyaml!=6.0.1,>=6.0.0; extra == 'example'",
'Requires-Dist: toml; ((python_version == "3.11" or python_version == "3.12") and python_version != "3.8") and extra == \'example\'',
'Requires-Dist: wheel; (python_version == "3.11" or python_version == "3.12") and extra == \'example\'',
Expand Down
18 changes: 14 additions & 4 deletions tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,23 @@ def main() -> None:
if not reqs_text or reqs_text.startswith(("#", "-")):
continue

req = Requirement(reqs_text)
# Strip any comments
reqs_text, _, _ = reqs_text.partition("#")

req = Requirement(reqs_text.strip())
if req.marker:
if extra:
reqs.append(
f"Requires-Dist: {req.name}{req.specifier}; ({req.marker}) and {extra}"
)
else:
reqs.append(
f"Requires-Dist: {req.name}{req.specifier}; {req.marker}"
)
else:
reqs.append(
f"Requires-Dist: {req.name}{req.specifier}; ({req.marker}) and {extra}"
f"Requires-Dist: {req.name}{req.specifier}; {extra}".strip(" ;")
)
else:
reqs.append(f"Requires-Dist: {req.name}{req.specifier}; {extra}")

metadata = metadata.replace(meta_line, "\n".join(reqs))

Expand Down

0 comments on commit 341db3c

Please sign in to comment.