From 1101ff5f2e7172763917192e48a713b07a3c6a8c Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 4 Jun 2023 14:36:50 +0100 Subject: [PATCH 1/2] use text=True on subprocess calls --- src/poetry/core/masonry/builders/wheel.py | 3 ++- src/poetry/core/vcs/__init__.py | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index e29213243..cc48f161a 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -361,13 +361,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)}" ) - return decode(output).strip().splitlines() + return output.strip().splitlines() @property def tag(self) -> str: 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)) From 7a5e24c117dac0c3ddd471f4ef7ca82d2262e7ce Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 4 Jun 2023 15:57:58 +0100 Subject: [PATCH 2/2] remove redundant decode --- src/poetry/core/masonry/builders/wheel.py | 3 +-- src/poetry/core/utils/helpers.py | 14 -------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index cc48f161a..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 @@ -366,7 +365,7 @@ def _get_sys_tags(self) -> list[str]: 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 output.strip().splitlines() 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("-", "_")