From c1d26e240fc1f84ed46db03c852625949aa6f1ff Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sat, 18 Mar 2023 19:34:30 +0000 Subject: [PATCH] prefer stdlib TemporaryDirectory --- src/poetry/inspection/info.py | 4 ++-- src/poetry/installation/chef.py | 4 ++-- src/poetry/repositories/http_repository.py | 8 ++++---- src/poetry/utils/env.py | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 10bd7d04ac9..e9d36d8f450 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() 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 d9114441191..15952f61ab7 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() 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 47d5ac62a3f..fc9de097e8a 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -19,6 +19,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 @@ -34,7 +35,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 @@ -1955,7 +1955,7 @@ def ephemeral_environment( executable: 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(