From 078b88fe397f28283cc1ddd362e1a8ea73799581 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Wed, 22 Mar 2023 17:25:23 +1000 Subject: [PATCH 1/2] use exec mode when passed a list of strings --- src/subprocess_tee/__init__.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/subprocess_tee/__init__.py b/src/subprocess_tee/__init__.py index c13109e..17f76e3 100644 --- a/src/subprocess_tee/__init__.py +++ b/src/subprocess_tee/__init__.py @@ -34,7 +34,7 @@ async def _read_stream(stream: StreamReader, callback: Callable[..., Any]) -> No break -async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess: +async def _stream_subprocess(args: Union[str, List[str]], **kwargs: Any) -> CompletedProcess: platform_settings: Dict[str, Any] = {} if platform.system() == "Windows": platform_settings["env"] = os.environ @@ -64,14 +64,24 @@ async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess: # Some users are reporting that default (undocumented) limit 64k is too # low - process = await asyncio.create_subprocess_shell( - args, - limit=STREAM_LIMIT, - stdin=kwargs.get("stdin", False), - stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.PIPE, - **platform_settings, - ) + if isinstance(args, str): + process = await asyncio.create_subprocess_shell( + args, + limit=STREAM_LIMIT, + stdin=kwargs.get("stdin", False), + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, + **platform_settings, + ) + else: + process = await asyncio.create_subprocess_exec( + *args, + limit=STREAM_LIMIT, + stdin=kwargs.get("stdin", False), + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, + **platform_settings, + ) out: List[str] = [] err: List[str] = [] @@ -139,7 +149,7 @@ def run(args: Union[str, List[str]], **kwargs: Any) -> CompletedProcess: if kwargs.get("echo", False): print(f"COMMAND: {cmd}") - result = asyncio.run(_stream_subprocess(cmd, **kwargs)) + result = asyncio.run(_stream_subprocess(args, **kwargs)) # we restore original args to mimic subproces.run() result.args = args From f393a124012ae6095766ad65d0599f1b504b74b3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 07:29:00 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/subprocess_tee/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/subprocess_tee/__init__.py b/src/subprocess_tee/__init__.py index 17f76e3..365b77b 100644 --- a/src/subprocess_tee/__init__.py +++ b/src/subprocess_tee/__init__.py @@ -34,7 +34,9 @@ async def _read_stream(stream: StreamReader, callback: Callable[..., Any]) -> No break -async def _stream_subprocess(args: Union[str, List[str]], **kwargs: Any) -> CompletedProcess: +async def _stream_subprocess( + args: Union[str, List[str]], **kwargs: Any +) -> CompletedProcess: platform_settings: Dict[str, Any] = {} if platform.system() == "Windows": platform_settings["env"] = os.environ