Skip to content

Commit

Permalink
prefer stdlib TemporaryDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed May 20, 2023
1 parent fe045cd commit 8c7cd5f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 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 @@ -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

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(ignore_cleanup_errors=True) 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 @@ -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
Expand Down Expand Up @@ -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)

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

Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 6 additions & 4 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c7cd5f

Please sign in to comment.