diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index fe7ce6864e1..30a785accee 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 @@ -19,7 +20,6 @@ from poetry.core.packages.package import Package from poetry.core.pyproject.toml import PyProjectTOML 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() 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 6eb1ae3f21b..34de8fd5fef 100644 --- a/src/poetry/installation/chef.py +++ b/src/poetry/installation/chef.py @@ -9,6 +9,7 @@ from contextlib import redirect_stdout from io import StringIO from pathlib import Path +from tempfile import TemporaryDirectory from typing import TYPE_CHECKING from typing import Callable from typing import Collection @@ -16,7 +17,6 @@ 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.installation.chooser import InvalidWheelName @@ -165,7 +165,7 @@ def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path else: context = tarfile.open - with temporary_directory() as tmp_dir: + with TemporaryDirectory() 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 298fc1e815b..28e190435c7 100644 --- a/src/poetry/repositories/http_repository.py +++ b/src/poetry/repositories/http_repository.py @@ -8,6 +8,7 @@ from collections import defaultdict from pathlib import Path +from tempfile import TemporaryDirectory from typing import TYPE_CHECKING from typing import Any @@ -16,7 +17,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 @@ -83,7 +83,7 @@ def _get_info_from_wheel(self, url: str) -> PackageInfo: filename = os.path.basename(wheel_name) - with temporary_directory() as temp_dir: + with TemporaryDirectory() as temp_dir: filepath = Path(temp_dir) / filename self._download(url, filepath) @@ -99,7 +99,7 @@ def _get_info_from_sdist(self, url: str) -> PackageInfo: filename = os.path.basename(sdist_name) - with temporary_directory() as temp_dir: + with TemporaryDirectory() as temp_dir: filepath = Path(temp_dir) / filename self._download(url, filepath) @@ -237,7 +237,7 @@ def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any] and link.hash_name not in ("sha256", "sha384", "sha512") and hasattr(hashlib, link.hash_name) ): - with temporary_directory() as temp_dir: + with TemporaryDirectory() as temp_dir: filepath = Path(temp_dir) / link.filename self._download(link.url, filepath) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index d5755d152c3..ca37c9fe44b 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -17,6 +17,7 @@ from contextlib import contextmanager from copy import deepcopy from pathlib import Path +from tempfile import TemporaryDirectory from subprocess import CalledProcessError from typing import TYPE_CHECKING from typing import Any @@ -34,7 +35,6 @@ from poetry.core.constraints.version import Version from poetry.core.constraints.version import parse_constraint from poetry.core.toml.file import TOMLFile -from poetry.core.utils.helpers import temporary_directory from virtualenv.seed.wheels.embed import get_embed_wheel from poetry.utils._compat import WINDOWS @@ -1952,7 +1952,7 @@ def ephemeral_environment( executable: str | Path | None = None, flags: dict[str, bool] | None = None, ) -> Iterator[VirtualEnv]: - with temporary_directory() as tmp_dir: + with TemporaryDirectory() as tmp_dir: # TODO: cache PEP 517 build environment corresponding to each project venv venv_dir = Path(tmp_dir) / ".venv" EnvManager.build_venv(