Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve use of subprocess #602

Merged
merged 2 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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