File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,12 @@ def parse_install_requirements(
37
37
):
38
38
if parsed_line .is_requirement :
39
39
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
+ ):
41
46
unpinned_reqs .append (str (install_req ))
42
47
install_req_and_lines .append (
43
48
(install_req , line )
Original file line number Diff line number Diff line change @@ -119,6 +119,33 @@ def test_parse_install_requirements_with_args(self):
119
119
),
120
120
)
121
121
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
+
122
149
123
150
if __name__ == "__main__" :
124
151
unittest .main ()
You can’t perform that action at this time.
0 commit comments