16
16
17
17
import atexit
18
18
import os
19
- import re
20
19
import shutil
21
20
import sys
22
21
from pathlib import Path
@@ -118,6 +117,7 @@ def main(
118
117
absolute_path_prefix = resolved_requirements_file [
119
118
: - (len (requirements_file ) - len (repository_prefix ))
120
119
]
120
+
121
121
# As srcs might contain references to generated files we want to
122
122
# use the runfiles file first. Thus, we need to compute the relative path
123
123
# from the execution root.
@@ -162,19 +162,12 @@ def main(
162
162
argv .append (
163
163
f"--output-file={ requirements_file_relative if UPDATE else requirements_out } "
164
164
)
165
- src_files = [
165
+ argv . extend (
166
166
(src_relative if Path (src_relative ).exists () else resolved_src )
167
167
for src_relative , resolved_src in zip (srcs_relative , resolved_srcs )
168
- ]
169
- argv .extend (src_files )
168
+ )
170
169
argv .extend (extra_args )
171
170
172
- # Replace in the output lock file
173
- # the lines like: # via -r /absolute/path/to/<requirements_file>
174
- # with: # via -r <requirements_file>
175
- # For Windows, we should explicitly call .as_posix() to convert \\ -> /
176
- absolute_src_prefixes = [Path (src ).absolute ().parent .as_posix () + "/" for src in src_files ]
177
-
178
171
if UPDATE :
179
172
print ("Updating " + requirements_file_relative )
180
173
@@ -192,14 +185,14 @@ def main(
192
185
# and we should copy the updated requirements back to the source tree.
193
186
if not absolute_output_file .samefile (requirements_file_tree ):
194
187
atexit .register (
195
- lambda : shutil .copy (absolute_output_file , requirements_file_tree )
188
+ lambda : shutil .copy (
189
+ absolute_output_file , requirements_file_tree
190
+ )
196
191
)
197
- cli (argv , standalone_mode = False )
192
+ cli (argv , standalone_mode = False )
198
193
requirements_file_relative_path = Path (requirements_file_relative )
199
194
content = requirements_file_relative_path .read_text ()
200
195
content = content .replace (absolute_path_prefix , "" )
201
- for absolute_src_prefix in absolute_src_prefixes :
202
- content = content .replace (absolute_src_prefix , "" )
203
196
requirements_file_relative_path .write_text (content )
204
197
else :
205
198
# cli will exit(0) on success
@@ -221,15 +214,6 @@ def main(
221
214
golden = open (_locate (bazel_runfiles , requirements_file )).readlines ()
222
215
out = open (requirements_out ).readlines ()
223
216
out = [line .replace (absolute_path_prefix , "" ) for line in out ]
224
-
225
- def replace_via_minus_r (line ):
226
- if "# via -r " in line :
227
- for absolute_src_prefix in absolute_src_prefixes :
228
- line = line .replace (absolute_src_prefix , "" )
229
- return line
230
- return line
231
-
232
- out = [replace_via_minus_r (line ) for line in out ]
233
217
if golden != out :
234
218
import difflib
235
219
0 commit comments