MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_temp_dir

Function get_temp_dir

Lib/test/libregrtest/utils.py:404–445  ·  view source on GitHub ↗
(tmp_dir: StrPath | None = None)

Source from the content-addressed store, hash-verified

402
403
404def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
405 if tmp_dir:
406 tmp_dir = os.path.expanduser(tmp_dir)
407 else:
408 # When tests are run from the Python build directory, it is best practice
409 # to keep the test files in a subfolder. This eases the cleanup of leftover
410 # files using the "make distclean" command.
411 if sysconfig.is_python_build():
412 if not support.is_wasi:
413 tmp_dir = sysconfig.get_config_var('abs_builddir')
414 if tmp_dir is None:
415 tmp_dir = sysconfig.get_config_var('abs_srcdir')
416 if not tmp_dir:
417 # gh-74470: On Windows, only srcdir is available. Using
418 # abs_builddir mostly matters on UNIX when building
419 # Python out of the source tree, especially when the
420 # source tree is read only.
421 tmp_dir = sysconfig.get_config_var('srcdir')
422 if not tmp_dir:
423 raise RuntimeError(
424 "Could not determine the correct value for tmp_dir"
425 )
426 tmp_dir = os.path.join(tmp_dir, 'build')
427 else:
428 # WASI platform
429 tmp_dir = sysconfig.get_config_var('projectbase')
430 if not tmp_dir:
431 raise RuntimeError(
432 "sysconfig.get_config_var('projectbase') "
433 f"unexpectedly returned {tmp_dir!r} on WASI"
434 )
435 tmp_dir = os.path.join(tmp_dir, 'build')
436
437 # When get_temp_dir() is called in a worker process,
438 # get_temp_dir() path is different than in the parent process
439 # which is not a WASI process. So the parent does not create
440 # the same "tmp_dir" than the test worker process.
441 os.makedirs(tmp_dir, exist_ok=True)
442 else:
443 tmp_dir = tempfile.gettempdir()
444
445 return os.path.abspath(tmp_dir)
446
447
448def get_work_dir(parent_dir: StrPath, worker: bool = False) -> StrPath:

Callers 2

_initMethod · 0.70
mainFunction · 0.70

Calls 2

expanduserMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected