Commit ac3d3827 by David Hotham Committed by Bjorn Neergaard

retire temporary_directory()

parent a00eb5c3
......@@ -8,6 +8,7 @@ import tarfile
import zipfile
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING
from typing import Iterator
......@@ -18,7 +19,6 @@ from poetry.core.packages.dependency import Dependency
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.utils.env import EnvCommandError
......@@ -286,7 +286,7 @@ class PackageInfo:
context = tarfile.open
with temporary_directory() as tmp:
with TemporaryDirectory() as tmp:
tmp = Path(tmp)
with context(path.as_posix()) as archive:
archive.extractall(tmp.as_posix())
......
......@@ -8,6 +8,7 @@ import urllib.parse
from abc import ABC
from collections import defaultdict
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING
from typing import Any
......@@ -24,7 +25,6 @@ from poetry.repositories.exceptions import RepositoryError
from poetry.repositories.link_sources.html import HTMLPage
from poetry.utils.authenticator import Authenticator
from poetry.utils.helpers import download_file
from poetry.utils.helpers import temporary_directory
from poetry.utils.patterns import wheel_file_re
......@@ -87,7 +87,7 @@ class HTTPRepository(CachedRepository, ABC):
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, str(filepath))
......@@ -103,7 +103,7 @@ class HTTPRepository(CachedRepository, ABC):
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, str(filepath))
......@@ -232,7 +232,7 @@ class HTTPRepository(CachedRepository, ABC):
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, str(filepath))
......
......@@ -15,6 +15,7 @@ from contextlib import contextmanager
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
from typing import ContextManager
......@@ -45,7 +46,6 @@ from poetry.utils._compat import metadata
from poetry.utils.helpers import is_dir_writable
from poetry.utils.helpers import paths_csv
from poetry.utils.helpers import remove_directory
from poetry.utils.helpers import temporary_directory
if TYPE_CHECKING:
......@@ -1831,7 +1831,7 @@ def ephemeral_environment(
executable: str | Path | None = None,
flags: dict[str, bool] = None,
) -> ContextManager[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(
......
......@@ -7,12 +7,10 @@ import stat
import tempfile
from collections.abc import Mapping
from contextlib import contextmanager
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import Iterator
if TYPE_CHECKING:
......@@ -34,15 +32,6 @@ def module_name(name: str) -> str:
return canonicalize_name(name).replace(".", "_").replace("-", "_")
@contextmanager
def temporary_directory(*args: Any, **kwargs: Any) -> Iterator[str]:
name = tempfile.mkdtemp(*args, **kwargs)
yield name
remove_directory(name, force=True)
def get_cert(config: Config, repository_name: str) -> Path | None:
cert = config.get(f"certificates.{repository_name}.cert")
if cert:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment