(tmp_dir: StrPath | None = None)
| 421 | |
| 422 | |
| 423 | def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath: |
| 424 | if tmp_dir: |
| 425 | tmp_dir = os.path.expanduser(tmp_dir) |
| 426 | else: |
| 427 | # When tests are run from the Python build directory, it is best practice |
| 428 | # to keep the test files in a subfolder. This eases the cleanup of leftover |
| 429 | # files using the "make distclean" command. |
| 430 | if sysconfig.is_python_build(): |
| 431 | if not support.is_wasi: |
| 432 | tmp_dir = sysconfig.get_config_var('abs_builddir') |
| 433 | if tmp_dir is None: |
| 434 | tmp_dir = sysconfig.get_config_var('abs_srcdir') |
| 435 | if not tmp_dir: |
| 436 | # gh-74470: On Windows, only srcdir is available. Using |
| 437 | # abs_builddir mostly matters on UNIX when building |
| 438 | # Python out of the source tree, especially when the |
| 439 | # source tree is read only. |
| 440 | tmp_dir = sysconfig.get_config_var('srcdir') |
| 441 | if not tmp_dir: |
| 442 | raise RuntimeError( |
| 443 | "Could not determine the correct value for tmp_dir" |
| 444 | ) |
| 445 | tmp_dir = os.path.join(tmp_dir, 'build') |
| 446 | else: |
| 447 | # WASI platform |
| 448 | tmp_dir = sysconfig.get_config_var('projectbase') |
| 449 | if not tmp_dir: |
| 450 | raise RuntimeError( |
| 451 | "sysconfig.get_config_var('projectbase') " |
| 452 | f"unexpectedly returned {tmp_dir!r} on WASI" |
| 453 | ) |
| 454 | tmp_dir = os.path.join(tmp_dir, 'build') |
| 455 | else: |
| 456 | tmp_dir = tempfile.gettempdir() |
| 457 | |
| 458 | return os.path.abspath(tmp_dir) |
| 459 | |
| 460 | |
| 461 | def get_work_dir(parent_dir: StrPath, worker: bool = False) -> StrPath: |
no test coverage detected
searching dependent graphs…