Skip to content

Commit

Permalink
improve use of subprocess (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Jun 9, 2023
1 parent d97811f commit ac81c3b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
14 changes: 0 additions & 14 deletions src/poetry/core/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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("-", "_")

Expand Down
12 changes: 5 additions & 7 deletions src/poetry/core/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit ac81c3b

Please sign in to comment.