diff --git a/src/poetry/utils/env/base_env.py b/src/poetry/utils/env/base_env.py index 00957285b62..487a0aa2276 100644 --- a/src/poetry/utils/env/base_env.py +++ b/src/poetry/utils/env/base_env.py @@ -14,8 +14,6 @@ from virtualenv.seed.wheels.embed import get_embed_wheel -from poetry.utils._compat import decode -from poetry.utils._compat import encode from poetry.utils.env.exceptions import EnvCommandError from poetry.utils.env.site_packages import SitePackages from poetry.utils.helpers import get_real_windows_path @@ -343,13 +341,14 @@ def _run(self, cmd: list[str], **kwargs: Any) -> str: try: if input_: - output = subprocess.run( + output: str = subprocess.run( cmd, stdout=subprocess.PIPE, stderr=stderr, - input=encode(input_), + input=input_, check=True, env=env, + text=True, **kwargs, ).stdout elif call: @@ -357,11 +356,13 @@ def _run(self, cmd: list[str], **kwargs: Any) -> str: subprocess.check_call(cmd, stderr=stderr, env=env, **kwargs) output = "" else: - output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs) + output = subprocess.check_output( + cmd, stderr=stderr, env=env, text=True, **kwargs + ) except CalledProcessError as e: raise EnvCommandError(e, input=input_) - return decode(output) + return output def execute(self, bin: str, *args: str, **kwargs: Any) -> int: command = self.get_command_from_bin(bin) + list(args) diff --git a/src/poetry/utils/env/env_manager.py b/src/poetry/utils/env/env_manager.py index a2f45ad799e..438dc7455f5 100644 --- a/src/poetry/utils/env/env_manager.py +++ b/src/poetry/utils/env/env_manager.py @@ -23,7 +23,6 @@ from poetry.toml.file import TOMLFile from poetry.utils._compat import WINDOWS -from poetry.utils._compat import decode from poetry.utils._compat import encode from poetry.utils.env.exceptions import EnvCommandError from poetry.utils.env.exceptions import IncorrectEnvError @@ -67,11 +66,9 @@ def _full_python_path(python: str) -> Path | None: return None try: - executable = decode( - subprocess.check_output( - [path_python, "-c", "import sys; print(sys.executable)"], - ).strip() - ) + executable = subprocess.check_output( + [path_python, "-c", "import sys; print(sys.executable)"], text=True + ).strip() return Path(executable) except CalledProcessError: @@ -115,11 +112,9 @@ def get_python_version( executable = EnvManager._detect_active_python(io) if executable: - python_patch = decode( - subprocess.check_output( - [executable, "-c", GET_PYTHON_VERSION_ONELINER], - ).strip() - ) + python_patch = subprocess.check_output( + [executable, "-c", GET_PYTHON_VERSION_ONELINER], text=True + ).strip() version = ".".join(str(v) for v in python_patch.split(".")[:precision]) @@ -150,10 +145,8 @@ def activate(self, python: str) -> Env: raise PythonVersionNotFound(python) try: - python_version_string = decode( - subprocess.check_output( - [python_path, "-c", GET_PYTHON_VERSION_ONELINER], - ) + python_version_string = subprocess.check_output( + [python_path, "-c", GET_PYTHON_VERSION_ONELINER], text=True ) except CalledProcessError as e: raise EnvCommandError(e) @@ -334,10 +327,8 @@ def remove(self, python: str) -> Env: if python_path.is_file(): # Validate env name if provided env is a full path to python try: - env_dir = decode( - subprocess.check_output( - [python, "-c", GET_ENV_PATH_ONELINER], - ) + env_dir = subprocess.check_output( + [python, "-c", GET_ENV_PATH_ONELINER], text=True ).strip("\n") env_name = Path(env_dir).name if not self.check_env_is_for_current_project(env_name, base_env_name): @@ -393,10 +384,8 @@ def remove(self, python: str) -> Env: pass try: - python_version_string = decode( - subprocess.check_output( - [python, "-c", GET_PYTHON_VERSION_ONELINER], - ) + python_version_string = subprocess.check_output( + [python, "-c", GET_PYTHON_VERSION_ONELINER], text=True ) except CalledProcessError as e: raise EnvCommandError(e) @@ -485,11 +474,9 @@ def create_venv( python_patch = ".".join([str(v) for v in sys.version_info[:3]]) python_minor = ".".join([str(v) for v in sys.version_info[:2]]) if executable: - python_patch = decode( - subprocess.check_output( - [executable, "-c", GET_PYTHON_VERSION_ONELINER], - ).strip() - ) + python_patch = subprocess.check_output( + [executable, "-c", GET_PYTHON_VERSION_ONELINER], text=True + ).strip() python_minor = ".".join(python_patch.split(".")[:2]) supported_python = self._poetry.package.python_constraint @@ -533,12 +520,11 @@ def create_venv( continue try: - python_patch = decode( - subprocess.check_output( - [python, "-c", GET_PYTHON_VERSION_ONELINER], - stderr=subprocess.STDOUT, - ).strip() - ) + python_patch = subprocess.check_output( + [python, "-c", GET_PYTHON_VERSION_ONELINER], + stderr=subprocess.STDOUT, + text=True, + ).strip() except CalledProcessError: continue diff --git a/src/poetry/vcs/git/system.py b/src/poetry/vcs/git/system.py index 6be52747ddf..935fc732344 100644 --- a/src/poetry/vcs/git/system.py +++ b/src/poetry/vcs/git/system.py @@ -53,15 +53,12 @@ def run(*args: Any, **kwargs: Any) -> str: git_command = find_git_command() env = os.environ.copy() env["GIT_TERMINAL_PROMPT"] = "0" - return ( - subprocess.check_output( - git_command + list(args), - stderr=subprocess.STDOUT, - env=env, - ) - .decode() - .strip() - ) + return subprocess.check_output( + git_command + list(args), + stderr=subprocess.STDOUT, + env=env, + text=True, + ).strip() @staticmethod def _check_parameter(parameter: str) -> None: