Skip to content

Commit

Permalink
use text=True on subprocess calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Jun 4, 2023
1 parent 071fc66 commit 1ec6d25
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 67 deletions.
3 changes: 2 additions & 1 deletion src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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
59 changes: 0 additions & 59 deletions tests/vcs/test_vcs.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
from __future__ import annotations

import subprocess

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

import pytest

from poetry.core.utils._compat import WINDOWS
from poetry.core.vcs.git import Git
from poetry.core.vcs.git import GitError
from poetry.core.vcs.git import GitUrl
from poetry.core.vcs.git import ParsedUrl
from poetry.core.vcs.git import _reset_executable


if TYPE_CHECKING:
from pytest_mock import MockerFixture


@pytest.mark.parametrize(
Expand Down Expand Up @@ -427,52 +417,3 @@ def test_git_checkout_raises_error_on_invalid_repository() -> None:
def test_git_rev_parse_raises_error_on_invalid_repository() -> None:
with pytest.raises(GitError):
Git().rev_parse("-u./payload")


@pytest.mark.skipif(
not WINDOWS,
reason=(
"Retrieving the complete path to git is only necessary on Windows, for security"
" reasons"
),
)
def test_ensure_absolute_path_to_git(mocker: MockerFixture) -> None:
_reset_executable()

def checkout_output(cmd: list[str], *args: Any, **kwargs: Any) -> str | bytes:
if Path(cmd[0]).name == "where.exe":
return "\n".join(
[
str(Path.cwd().joinpath("git.exe")),
"C:\\Git\\cmd\\git.exe",
]
)

return b""

mock = mocker.patch.object(subprocess, "check_output", side_effect=checkout_output)

Git().run("config")

assert mock.call_args_list[-1][0][0] == [
"C:\\Git\\cmd\\git.exe",
"config",
]


@pytest.mark.skipif(
not WINDOWS,
reason=(
"Retrieving the complete path to git is only necessary on Windows, for security"
" reasons"
),
)
def test_ensure_existing_git_executable_is_found(mocker: MockerFixture) -> None:
mock = mocker.patch.object(subprocess, "check_output", return_value=b"")

Git().run("config")

cmd = Path(mock.call_args_list[-1][0][0][0])

assert cmd.is_absolute()
assert cmd.name == "git.exe"

0 comments on commit 1ec6d25

Please sign in to comment.