diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index d1461d4ed76..7a4ca464325 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -9,6 +9,7 @@ import zipfile from pathlib import Path +from tempfile import TemporaryDirectory from typing import TYPE_CHECKING from typing import Any @@ -18,7 +19,6 @@ from poetry.core.packages.dependency import Dependency from poetry.core.packages.package import Package from poetry.core.utils.helpers import parse_requires -from poetry.core.utils.helpers import temporary_directory from poetry.core.version.markers import InvalidMarker from poetry.core.version.requirements import InvalidRequirement @@ -308,7 +308,7 @@ def _from_sdist_file(cls, path: Path) -> PackageInfo: context = tarfile.open - with temporary_directory() as tmp_str: + with TemporaryDirectory(ignore_cleanup_errors=True) as tmp_str: tmp = Path(tmp_str) with context(path.as_posix()) as archive: archive.extractall(tmp.as_posix()) diff --git a/src/poetry/installation/chef.py b/src/poetry/installation/chef.py index da8679df21f..f33ebabcc67 100644 --- a/src/poetry/installation/chef.py +++ b/src/poetry/installation/chef.py @@ -7,12 +7,12 @@ from contextlib import redirect_stdout from io import StringIO from pathlib import Path +from tempfile import TemporaryDirectory from typing import TYPE_CHECKING from build import BuildBackendException from build import ProjectBuilder from build.env import IsolatedEnv as BaseIsolatedEnv -from poetry.core.utils.helpers import temporary_directory from pyproject_hooks import quiet_subprocess_runner # type: ignore[import] from poetry.utils._compat import decode @@ -160,7 +160,7 @@ def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path else: context = tarfile.open - with temporary_directory() as tmp_dir: + with TemporaryDirectory(ignore_cleanup_errors=True) as tmp_dir: with context(archive.as_posix()) as archive_archive: archive_archive.extractall(tmp_dir) diff --git a/src/poetry/repositories/http_repository.py b/src/poetry/repositories/http_repository.py index ae96481a71d..ef0d25f6ebd 100644 --- a/src/poetry/repositories/http_repository.py +++ b/src/poetry/repositories/http_repository.py @@ -6,6 +6,7 @@ from collections import defaultdict from contextlib import contextmanager from pathlib import Path +from tempfile import TemporaryDirectory from typing import TYPE_CHECKING from typing import Any from typing import Iterator @@ -15,7 +16,6 @@ from poetry.core.constraints.version import parse_constraint from poetry.core.packages.dependency import Dependency from poetry.core.packages.utils.link import Link -from poetry.core.utils.helpers import temporary_directory from poetry.core.version.markers import parse_marker from poetry.repositories.cached_repository import CachedRepository @@ -81,7 +81,7 @@ def _cached_or_downloaded_file(self, link: Link) -> Iterator[Path]: yield filepath else: self._log(f"Downloading: {link.url}", level="debug") - with temporary_directory() as temp_dir: + with TemporaryDirectory(ignore_cleanup_errors=True) as temp_dir: filepath = Path(temp_dir) / link.filename self._download(link.url, filepath) yield filepath diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 007d386398b..be5e10ca30d 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -18,6 +18,7 @@ from copy import deepcopy from pathlib import Path from subprocess import CalledProcessError +from tempfile import TemporaryDirectory from typing import TYPE_CHECKING from typing import Any @@ -33,7 +34,6 @@ from packaging.tags import sys_tags from poetry.core.constraints.version import Version from poetry.core.constraints.version import parse_constraint -from poetry.core.utils.helpers import temporary_directory from virtualenv.seed.wheels.embed import get_embed_wheel from poetry.toml.file import TOMLFile @@ -1889,7 +1889,7 @@ def ephemeral_environment( executable: Path | None = None, flags: dict[str, bool] | None = None, ) -> Iterator[VirtualEnv]: - with temporary_directory() as tmp_dir: + with TemporaryDirectory(ignore_cleanup_errors=True) as tmp_dir: # TODO: cache PEP 517 build environment corresponding to each project venv venv_dir = Path(tmp_dir) / ".venv" EnvManager.build_venv( diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index 715ba5efb33..e85660687db 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -1090,11 +1090,13 @@ def test_lock_file_resolves_file_url_symlinks(root: ProjectPackage) -> None: See https://github.com/python-poetry/poetry/issues/5849 """ - with tempfile.TemporaryDirectory() as d1: + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as d1: symlink_path = Path(d1).joinpath("testsymlink") - with tempfile.TemporaryDirectory(dir=d1) as d2, tempfile.TemporaryDirectory( - dir=d1 - ) as d4, tempfile.TemporaryDirectory(dir=d2) as d3, tempfile.NamedTemporaryFile( + with tempfile.TemporaryDirectory( + dir=d1, ignore_cleanup_errors=True + ) as d2, tempfile.TemporaryDirectory(dir=d1) as d4, tempfile.TemporaryDirectory( + dir=d2, ignore_cleanup_errors=True + ) as d3, tempfile.NamedTemporaryFile( dir=d4 ) as source_file, tempfile.NamedTemporaryFile( dir=d3