Skip to content

Commit

Permalink
MAINT: ignore_cleanup_errors only on Python 3.10+
Browse files Browse the repository at this point in the history
  • Loading branch information
thalassemia committed Jan 11, 2024
1 parent d936c10 commit c311558
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,16 +940,18 @@ def _project(config_settings: Optional[Dict[Any, Any]] = None) -> Iterator[Proje
build_dir = settings.get('build-dir')
editable_verbose = bool(settings.get('editable-verbose'))

ignore_cleanup_errors = False
temp_dir_kwargs = {
'prefix': '.mesonpy-',
'dir': source_dir
}
# Files failing to delete on Windows is a known issue
# (https://bugs.python.org/issue29982)
if os.name == 'nt':
ignore_cleanup_errors = True
# (https://bugs.python.org/issue29982). `ignore_cleanup_errors`
# was added to `TemporaryDirectory` in Python 3.10
if sys.version_info[0] == 3 and sys.version_info[1] >= 10 and os.name == 'nt':
temp_dir_kwargs['ignore_cleanup_errors'] = True

Check warning on line 951 in mesonpy/__init__.py

View check run for this annotation

Codecov / codecov/patch

mesonpy/__init__.py#L951

Added line #L951 was not covered by tests
with contextlib.ExitStack() as ctx:
if build_dir is None:
build_dir = ctx.enter_context(tempfile.TemporaryDirectory(
prefix='.mesonpy-', dir=source_dir,
ignore_cleanup_errors=ignore_cleanup_errors))
build_dir = ctx.enter_context(tempfile.TemporaryDirectory(**temp_dir_kwargs))
yield Project(source_dir, build_dir, meson_args, editable_verbose)


Expand Down

0 comments on commit c311558

Please sign in to comment.