From 1ec6d25818330b6d6ce901c271dde5b19d4faccf Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 4 Jun 2023 14:36:50 +0100 Subject: [PATCH] use text=True on subprocess calls --- src/poetry/core/masonry/builders/wheel.py | 3 +- src/poetry/core/vcs/__init__.py | 12 ++--- tests/vcs/test_vcs.py | 59 ----------------------- 3 files changed, 7 insertions(+), 67 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)) diff --git a/tests/vcs/test_vcs.py b/tests/vcs/test_vcs.py index 26898bf61..c8f1f0c25 100644 --- a/tests/vcs/test_vcs.py +++ b/tests/vcs/test_vcs.py @@ -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( @@ -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"