2222del sys .path [0 ]
2323
2424import os
25- from os .path import join
2625import shutil
2726import stat
2827import subprocess
2928import tempfile
3029import zipfile
30+ from os .path import dirname , join
3131
3232# runfiles-root-relative path
3333_STAGE2_BOOTSTRAP = "%stage2_bootstrap%"
@@ -124,7 +124,7 @@ def search_path(name):
124124 search_path = os .getenv ("PATH" , os .defpath ).split (os .pathsep )
125125 for directory in search_path :
126126 if directory :
127- path = os . path . join (directory , name )
127+ path = join (directory , name )
128128 if os .path .isfile (path ) and os .access (path , os .X_OK ):
129129 return path
130130 return None
@@ -145,7 +145,7 @@ def find_binary(runfiles_root, bin_name):
145145 # Use normpath() to convert slashes to os.sep on Windows.
146146 elif os .sep in os .path .normpath (bin_name ):
147147 # Case 3: Path is relative to the repo root.
148- return os . path . join (runfiles_root , bin_name )
148+ return join (runfiles_root , bin_name )
149149 else :
150150 # Case 4: Path has to be looked up in the search path.
151151 return search_path (bin_name )
@@ -167,7 +167,7 @@ def extract_zip(zip_path, dest_dir):
167167 dest_dir = get_windows_path_with_unc_prefix (dest_dir )
168168 with zipfile .ZipFile (zip_path ) as zf :
169169 for info in zf .infolist ():
170- file_path = os .path .abspath (os . path . join (dest_dir , info .filename ))
170+ file_path = os .path .abspath (join (dest_dir , info .filename ))
171171 # If the file exists, it might be a symlink or read-only file from a previous extraction.
172172 # Unlink it first so zipfile.extract doesn't corrupt the symlink target or fail on read-only files.
173173 if os .path .lexists (file_path ) and not os .path .isdir (file_path ):
@@ -177,7 +177,7 @@ def extract_zip(zip_path, dest_dir):
177177 # On Windows, unlinking a read-only file fails.
178178 os .chmod (file_path , stat .S_IWRITE )
179179 os .unlink (file_path )
180-
180+
181181 zf .extract (info , dest_dir )
182182 # The Unix st_mode bits (see "man 7 inode") are stored in the upper 16
183183 # bits of external_attr.
@@ -200,10 +200,10 @@ def create_runfiles_root():
200200 extract_root = join (EXTRACT_ROOT , EXTRACT_DIR )
201201 else :
202202 extract_root = tempfile .mkdtemp ("" , "Bazel.runfiles_" )
203- extract_zip (os . path . dirname (__file__ ), extract_root )
203+ extract_zip (dirname (__file__ ), extract_root )
204204 # IMPORTANT: Later code does `rm -fr` on dirname(runfiles_root) -- it's
205205 # important that deletion code be in sync with this directory structure
206- return os . path . join (extract_root , "runfiles" )
206+ return join (extract_root , "runfiles" )
207207
208208
209209def execute_file (
@@ -242,7 +242,7 @@ def execute_file(
242242 try :
243243 subprocess_argv = [python_program ]
244244 if not EXTRACT_ROOT :
245- subprocess_argv .append (f"-XRULES_PYTHON_ZIP_DIR={ os . path . dirname (runfiles_root )} " )
245+ subprocess_argv .append (f"-XRULES_PYTHON_ZIP_DIR={ dirname (runfiles_root )} " )
246246 subprocess_argv .append (main_filename )
247247 subprocess_argv += args
248248 print_verbose ("subprocess argv:" , values = subprocess_argv )
@@ -255,7 +255,7 @@ def execute_file(
255255 # NOTE: dirname() is called because create_runfiles_root() creates a
256256 # sub-directory within a temporary directory, and we want to remove the
257257 # whole temporary directory.
258- extract_root = os . path . dirname (runfiles_root )
258+ extract_root = dirname (runfiles_root )
259259 print_verbose ("cleanup: rmtree: " , extract_root )
260260 shutil .rmtree (extract_root , True )
261261
@@ -289,7 +289,7 @@ def main():
289289 # See: https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONSAFEPATH
290290 new_env ["PYTHONSAFEPATH" ] = "1"
291291
292- main_filename = os . path . join (runfiles_root , main_rel_path )
292+ main_filename = join (runfiles_root , main_rel_path )
293293 main_filename = get_windows_path_with_unc_prefix (main_filename )
294294 assert os .path .exists (main_filename ), (
295295 "Cannot exec() %r: file not found." % main_filename
@@ -299,7 +299,7 @@ def main():
299299 )
300300
301301 if _PYTHON_BINARY_VENV :
302- python_program = os . path . join (runfiles_root , _PYTHON_BINARY_VENV )
302+ python_program = join (runfiles_root , _PYTHON_BINARY_VENV )
303303 # When a venv is used, the `bin/python3` symlink may need to be created.
304304 # This case occurs when "create venv at runtime" or "resolve python at
305305 # runtime" modes are enabled.
@@ -311,7 +311,7 @@ def main():
311311 "Program's venv binary not under runfiles: {python_program}"
312312 )
313313 symlink_to = find_binary (runfiles_root , _PYTHON_BINARY_ACTUAL )
314- os .makedirs (os . path . dirname (python_program ), exist_ok = True )
314+ os .makedirs (dirname (python_program ), exist_ok = True )
315315 try :
316316 os .symlink (symlink_to , python_program )
317317 except OSError as e :
@@ -340,7 +340,7 @@ def main():
340340 # change directory to the right runfiles directory.
341341 # (So that the data files are accessible)
342342 if os .environ .get ("RUN_UNDER_RUNFILES" ) == "1" :
343- workspace = os . path . join (runfiles_root , _WORKSPACE_NAME )
343+ workspace = join (runfiles_root , _WORKSPACE_NAME )
344344
345345 sys .stdout .flush ()
346346 execute_file (
0 commit comments