Skip to content

Commit

Permalink
proc.pipeline: deprecate shell_executable, use executable instead
Browse files Browse the repository at this point in the history
matches `subprocess` better
  • Loading branch information
ryan-williams committed Dec 26, 2024
1 parent 5e0557f commit 97a6e3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions utz/process/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from warnings import warn

from io import UnsupportedOperation, StringIO
from os import environ as env
from subprocess import Popen, PIPE
Expand All @@ -17,16 +19,26 @@ def pipeline(
out: str | IO[AnyStr] | None = None,
mode: Literal['b', 't', None] = None,
shell: bool = True,
executable: str | None = _Unset,
shell_executable: str | None = _Unset,
wait: bool = True,
**kwargs,
) -> str | list[Popen] | None:
"""Run a pipeline of commands, writing the final stdout to a file or ``IO``, or returning it as a ``str``"""
processes = []
prev_process: Popen | None = None
if shell_executable is _Unset:
if executable is _Unset:
shell_executable = env.get('SHELL')

if shell_executable is not _Unset:
warn(
"`shell_executable` kwarg is deprecated, use `executable` instead",
FutureWarning,
stacklevel=2
)
if executable is _Unset:
executable = shell_executable

return_output = False
if out is None:
out = StringIO()
Expand Down Expand Up @@ -57,7 +69,7 @@ def mkproc(stdout=PIPE):
stdin=stdin,
stdout=stdout,
shell=shell,
executable=shell_executable,
executable=executable,
**kwargs
)

Expand Down
6 changes: 6 additions & 0 deletions utz/tests/test_proc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os.path import join

import json
from os import environ as env
import pytest
from subprocess import CalledProcessError
from tempfile import NamedTemporaryFile, TemporaryDirectory
Expand Down Expand Up @@ -75,3 +76,8 @@ def test_pipeline():
pipeline(['seq 10', 'head -n5'], tmp_path)
with open(tmp_path) as f:
assert f.read() == '1\n2\n3\n4\n5\n'


def test_pipeline_shell_executable_warning():
with pytest.warns(FutureWarning, match="`shell_executable` kwarg is deprecated"):
pipeline(['seq 10', 'head -n5'], shell_executable=env['SHELL'])

0 comments on commit 97a6e3e

Please sign in to comment.