Skip to content

Commit

Permalink
prefer stdlib TemporaryDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Mar 18, 2023
1 parent 584801e commit 9e5031d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import zipfile

from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING
from typing import Any

Expand All @@ -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

Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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

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
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions src/poetry/repositories/http_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9e5031d

Please sign in to comment.