@@ -136,12 +136,12 @@ def SearchPath(name):
136136 return path
137137 return None
138138
139- def FindPythonBinary (module_space ):
139+ def FindPythonBinary (runfiles_root ):
140140 """Finds the real Python binary if it's not a normal absolute path."""
141141 if PYTHON_BINARY :
142- return FindBinary (module_space , PYTHON_BINARY )
142+ return FindBinary (runfiles_root , PYTHON_BINARY )
143143 else :
144- return FindBinary (module_space , PYTHON_BINARY_ACTUAL )
144+ return FindBinary (runfiles_root , PYTHON_BINARY_ACTUAL )
145145
146146
147147def print_verbose (* args , mapping = None , values = None ):
@@ -165,7 +165,7 @@ def print_verbose(*args, mapping=None, values=None):
165165 else :
166166 print ("bootstrap: stage 1:" , * args , file = sys .stderr , flush = True )
167167
168- def FindBinary (module_space , bin_name ):
168+ def FindBinary (runfiles_root , bin_name ):
169169 """Finds the real binary if it's not a normal absolute path."""
170170 if not bin_name :
171171 return None
@@ -180,12 +180,12 @@ def FindBinary(module_space, bin_name):
180180 # Use normpath() to convert slashes to os.sep on Windows.
181181 elif os .sep in os .path .normpath (bin_name ):
182182 # Case 3: Path is relative to the repo root.
183- return os .path .join (module_space , bin_name )
183+ return os .path .join (runfiles_root , bin_name )
184184 else :
185185 # Case 4: Path has to be looked up in the search path.
186186 return SearchPath (bin_name )
187187
188- def FindModuleSpace (main_rel_path ):
188+ def find_runfiles_root (main_rel_path ):
189189 """Finds the runfiles tree."""
190190 # When the calling process used the runfiles manifest to resolve the
191191 # location of this stub script, the path may be expanded. This means
@@ -214,9 +214,9 @@ def FindModuleSpace(main_rel_path):
214214 stub_filename = os .path .join (os .getcwd (), stub_filename )
215215
216216 while True :
217- module_space = stub_filename + ('.exe' if IsWindows () else '' ) + '.runfiles'
218- if os .path .isdir (module_space ):
219- return module_space
217+ runfiles_root = stub_filename + ('.exe' if IsWindows () else '' ) + '.runfiles'
218+ if os .path .isdir (runfiles_root ):
219+ return runfiles_root
220220
221221 runfiles_pattern = r'(.*\.runfiles)' + (r'\\' if IsWindows () else '/' ) + '.*'
222222 matchobj = re .match (runfiles_pattern , stub_filename )
@@ -261,14 +261,14 @@ def ExtractZip(zip_path, dest_dir):
261261 os .chmod (file_path , attrs & 0o7777 )
262262
263263# Create the runfiles tree by extracting the zip file
264- def CreateModuleSpace ():
264+ def create_runfiles_root ():
265265 temp_dir = tempfile .mkdtemp ('' , 'Bazel.runfiles_' )
266266 ExtractZip (os .path .dirname (__file__ ), temp_dir )
267- # IMPORTANT: Later code does `rm -fr` on dirname(module_space ) -- it's
267+ # IMPORTANT: Later code does `rm -fr` on dirname(runfiles_root ) -- it's
268268 # important that deletion code be in sync with this directory structure
269269 return os .path .join (temp_dir , 'runfiles' )
270270
271- def RunfilesEnvvar (module_space ):
271+ def RunfilesEnvvar (runfiles_root ):
272272 """Finds the runfiles manifest or the runfiles directory.
273273
274274 Returns:
@@ -288,30 +288,30 @@ def RunfilesEnvvar(module_space):
288288
289289 # If running from a zip, there's no manifest file.
290290 if IsRunningFromZip ():
291- return ('RUNFILES_DIR' , module_space )
291+ return ('RUNFILES_DIR' , runfiles_root )
292292
293293 # Look for the runfiles "output" manifest, argv[0] + ".runfiles_manifest"
294- runfiles = module_space + '_manifest'
294+ runfiles = runfiles_root + '_manifest'
295295 if os .path .exists (runfiles ):
296296 return ('RUNFILES_MANIFEST_FILE' , runfiles )
297297
298298 # Look for the runfiles "input" manifest, argv[0] + ".runfiles/MANIFEST"
299299 # Normally .runfiles_manifest and MANIFEST are both present, but the
300300 # former will be missing for zip-based builds or if someone copies the
301301 # runfiles tree elsewhere.
302- runfiles = os .path .join (module_space , 'MANIFEST' )
302+ runfiles = os .path .join (runfiles_root , 'MANIFEST' )
303303 if os .path .exists (runfiles ):
304304 return ('RUNFILES_MANIFEST_FILE' , runfiles )
305305
306306 # If running in a sandbox and no environment variables are set, then
307307 # Look for the runfiles next to the binary.
308- if module_space .endswith ('.runfiles' ) and os .path .isdir (module_space ):
309- return ('RUNFILES_DIR' , module_space )
308+ if runfiles_root .endswith ('.runfiles' ) and os .path .isdir (runfiles_root ):
309+ return ('RUNFILES_DIR' , runfiles_root )
310310
311311 return (None , None )
312312
313- def ExecuteFile (python_program , main_filename , args , env , module_space ,
314- workspace , delete_module_space ):
313+ def ExecuteFile (python_program , main_filename , args , env , runfiles_root ,
314+ workspace , delete_runfiles_root ):
315315 # type: (str, str, list[str], dict[str, str], str, str|None, str|None) -> ...
316316 """Executes the given Python file using the various environment settings.
317317
@@ -323,10 +323,10 @@ def ExecuteFile(python_program, main_filename, args, env, module_space,
323323 main_filename: (str) The Python file to execute
324324 args: (list[str]) Additional args to pass to the Python file
325325 env: (dict[str, str]) A dict of environment variables to set for the execution
326- module_space : (str) Path to the module space/ runfiles tree directory
326+ runfiles_root : (str) Path to the runfiles root directory
327327 workspace: (str|None) Name of the workspace to execute in. This is expected to be a
328328 directory under the runfiles tree.
329- delete_module_space : (bool), True if the module space should be deleted
329+ delete_runfiles_root : (bool), True if the runfiles root should be deleted
330330 after a successful (exit code zero) program run, False if not.
331331 """
332332 argv = [python_program ]
@@ -351,7 +351,7 @@ def ExecuteFile(python_program, main_filename, args, env, module_space,
351351 # can't execv because we need control to return here. This only
352352 # happens for targets built in the host config.
353353 #
354- if not (IsWindows () or workspace or delete_module_space ):
354+ if not (IsWindows () or workspace or delete_runfiles_root ):
355355 _RunExecv (python_program , argv , env )
356356
357357 ret_code = subprocess .call (
@@ -360,11 +360,11 @@ def ExecuteFile(python_program, main_filename, args, env, module_space,
360360 cwd = workspace
361361 )
362362
363- if delete_module_space :
364- # NOTE: dirname() is called because CreateModuleSpace () creates a
363+ if delete_runfiles_root :
364+ # NOTE: dirname() is called because create_runfiles_root () creates a
365365 # sub-directory within a temporary directory, and we want to remove the
366366 # whole temporary directory.
367- shutil .rmtree (os .path .dirname (module_space ), True )
367+ shutil .rmtree (os .path .dirname (runfiles_root ), True )
368368 sys .exit (ret_code )
369369
370370def _RunExecv (python_program , argv , env ):
@@ -401,33 +401,33 @@ def Main():
401401 print_verbose ("main_rel_path:" , main_rel_path )
402402
403403 if IsRunningFromZip ():
404- module_space = CreateModuleSpace ()
405- delete_module_space = True
404+ runfiles_root = create_runfiles_root ()
405+ delete_runfiles_root = True
406406 else :
407- module_space = FindModuleSpace (main_rel_path )
408- delete_module_space = False
407+ runfiles_root = find_runfiles_root (main_rel_path )
408+ delete_runfiles_root = False
409409
410- print_verbose ("runfiles root:" , module_space )
410+ print_verbose ("runfiles root:" , runfiles_root )
411411
412- if os .environ .get ("RULES_PYTHON_TESTING_TELL_MODULE_SPACE " ):
413- new_env ["RULES_PYTHON_TESTING_MODULE_SPACE " ] = module_space
412+ if os .environ .get ("RULES_PYTHON_TESTING_TELL_RUNFILES_ROOT " ):
413+ new_env ["RULES_PYTHON_TESTING_RUNFILES_ROOT " ] = runfiles_root
414414
415- runfiles_envkey , runfiles_envvalue = RunfilesEnvvar (module_space )
415+ runfiles_envkey , runfiles_envvalue = RunfilesEnvvar (runfiles_root )
416416 if runfiles_envkey :
417417 new_env [runfiles_envkey ] = runfiles_envvalue
418418
419419 # Don't prepend a potentially unsafe path to sys.path
420420 # See: https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONSAFEPATH
421421 new_env ['PYTHONSAFEPATH' ] = '1'
422422
423- main_filename = os .path .join (module_space , main_rel_path )
423+ main_filename = os .path .join (runfiles_root , main_rel_path )
424424 main_filename = GetWindowsPathWithUNCPrefix (main_filename )
425425 assert os .path .exists (main_filename ), \
426426 'Cannot exec() %r: file not found.' % main_filename
427427 assert os .access (main_filename , os .R_OK ), \
428428 'Cannot exec() %r: file not readable.' % main_filename
429429
430- program = python_program = FindPythonBinary (module_space )
430+ program = python_program = FindPythonBinary (runfiles_root )
431431 if python_program is None :
432432 raise AssertionError ("Could not find python binary: {} or {}" .format (
433433 repr (PYTHON_BINARY ),
@@ -449,15 +449,15 @@ def Main():
449449 # change directory to the right runfiles directory.
450450 # (So that the data files are accessible)
451451 if os .environ .get ('RUN_UNDER_RUNFILES' ) == '1' :
452- workspace = os .path .join (module_space , WORKSPACE_NAME )
452+ workspace = os .path .join (runfiles_root , WORKSPACE_NAME )
453453
454454 try :
455455 sys .stdout .flush ()
456456 # NOTE: ExecuteFile may call execve() and lines after this will never run.
457457 ExecuteFile (
458- python_program , main_filename , args , new_env , module_space ,
458+ python_program , main_filename , args , new_env , runfiles_root ,
459459 workspace ,
460- delete_module_space = delete_module_space ,
460+ delete_runfiles_root = delete_runfiles_root ,
461461 )
462462
463463 except EnvironmentError :
0 commit comments