From ac81c3be50396028f91138c8169c932ddfb4ae5d Mon Sep 17 00:00:00 2001 From: David Hotham Date: Fri, 9 Jun 2023 18:51:58 +0100 Subject: [PATCH] improve use of subprocess (#602) --- src/poetry/core/masonry/builders/wheel.py | 6 +++--- src/poetry/core/utils/helpers.py | 14 -------------- src/poetry/core/vcs/__init__.py | 12 +++++------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index e29213243..25312ac23 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -27,7 +27,6 @@ from poetry.core.masonry.utils.helpers import distribution_name from poetry.core.masonry.utils.helpers import normalize_file_permissions from poetry.core.masonry.utils.package_include import PackageInclude -from poetry.core.utils.helpers import decode from poetry.core.utils.helpers import temporary_directory @@ -361,13 +360,14 @@ def _get_sys_tags(self) -> list[str]: """, ], stderr=subprocess.STDOUT, + text=True, ) except subprocess.CalledProcessError as e: raise RuntimeError( "Failed to get sys_tags for python interpreter" - f" '{self.executable.as_posix()}':\n{decode(e.output)}" + f" '{self.executable.as_posix()}':\n{e.output}" ) - return decode(output).strip().splitlines() + return output.strip().splitlines() @property def tag(self) -> str: diff --git a/src/poetry/core/utils/helpers.py b/src/poetry/core/utils/helpers.py index 83ff3436b..887bb2532 100644 --- a/src/poetry/core/utils/helpers.py +++ b/src/poetry/core/utils/helpers.py @@ -10,7 +10,6 @@ import warnings from contextlib import contextmanager -from contextlib import suppress from pathlib import Path from typing import TYPE_CHECKING from typing import Any @@ -28,19 +27,6 @@ def combine_unicode(string: str) -> str: return unicodedata.normalize("NFC", string) -def decode(string: bytes | str, encodings: list[str] | None = None) -> str: - if not isinstance(string, bytes): - return string - - encodings = encodings or ["utf-8", "latin1", "ascii"] - - for encoding in encodings: - with suppress(UnicodeEncodeError, UnicodeDecodeError): - return string.decode(encoding) - - return string.decode(encodings[0], errors="ignore") - - def module_name(name: str) -> str: return canonicalize_name(name).replace("-", "_") diff --git a/src/poetry/core/vcs/__init__.py b/src/poetry/core/vcs/__init__.py index f4096ec0e..4e03a8904 100644 --- a/src/poetry/core/vcs/__init__.py +++ b/src/poetry/core/vcs/__init__.py @@ -17,13 +17,11 @@ def get_vcs(directory: Path) -> Git | None: try: from poetry.core.vcs.git import executable - git_dir = ( - subprocess.check_output( - [executable(), "rev-parse", "--show-toplevel"], stderr=subprocess.STDOUT - ) - .decode() - .strip() - ) + git_dir = subprocess.check_output( + [executable(), "rev-parse", "--show-toplevel"], + stderr=subprocess.STDOUT, + text=True, + ).strip() vcs = Git(Path(git_dir))