Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 834149d

Browse filesBrowse files
authored
Fix for requirements_lock with PEP440 direct references (bazel-contrib#756)
1 parent 636f55c commit 834149d
Copy full SHA for 834149d

File tree

Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed

‎python/pip_install/extract_wheels/parse_requirements_to_bzl.py

Copy file name to clipboardExpand all lines: python/pip_install/extract_wheels/parse_requirements_to_bzl.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def parse_install_requirements(
3737
):
3838
if parsed_line.is_requirement:
3939
install_req = constructors.install_req_from_line(parsed_line.requirement)
40-
if not install_req.is_pinned:
40+
if (
41+
# PEP-440 direct references are considered pinned
42+
# See: https://peps.python.org/pep-0440/#direct-references and https://peps.python.org/pep-0508/
43+
not install_req.link and
44+
not install_req.is_pinned
45+
):
4146
unpinned_reqs.append(str(install_req))
4247
install_req_and_lines.append(
4348
(install_req, line)

‎python/pip_install/extract_wheels/parse_requirements_to_bzl_test.py

Copy file name to clipboardExpand all lines: python/pip_install/extract_wheels/parse_requirements_to_bzl_test.py
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,33 @@ def test_parse_install_requirements_with_args(self):
119119
),
120120
)
121121

122+
def test_parse_install_requirements_pinned_direct_reference(self):
123+
# Test PEP-440 direct references
124+
with tempfile.TemporaryDirectory() as temp_dir:
125+
requirements_lock = Path(temp_dir) / "requirements.txt"
126+
requirements_lock.write_text(
127+
dedent(
128+
"""\
129+
onnx @ https://files.pythonhosted.org/packages/24/93/f5b001dc0f5de84ce049a34ff382032cd9478e1080aa6ac48470fa810577/onnx-1.11.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl \
130+
--hash=sha256:67c6d2654c1c203e5c839a47900b51f588fd0de71bbd497fb193d30a0b3ec1e9
131+
"""
132+
)
133+
)
134+
135+
install_req_and_lines = parse_install_requirements(
136+
str(requirements_lock), ["-v"]
137+
)
138+
139+
self.assertEqual(len(install_req_and_lines), 1)
140+
self.assertEqual(install_req_and_lines[0][0].name, "onnx")
141+
142+
self.assertTupleEqual(
143+
install_req_and_lines[0][1:],
144+
(
145+
"onnx @ https://files.pythonhosted.org/packages/24/93/f5b001dc0f5de84ce049a34ff382032cd9478e1080aa6ac48470fa810577/onnx-1.11.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl --hash=sha256:67c6d2654c1c203e5c839a47900b51f588fd0de71bbd497fb193d30a0b3ec1e9",
146+
),
147+
)
148+
122149

123150
if __name__ == "__main__":
124151
unittest.main()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.