Skip to content

Commit

Permalink
Some very minor improvements (next release, whenever)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos Bairaktaris committed Sep 20, 2022
1 parent 24b63c9 commit e2ff95b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
20 changes: 12 additions & 8 deletions src/pipepy/pipepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import pathlib
import reprlib
import types
from collections.abc import Iterable
from copy import copy
from glob import glob
from subprocess import PIPE, Popen, TimeoutExpired

from .exceptions import PipePyError
from .utils import _File, is_iterable
from .utils import _File

ALWAYS_RAISE = False
ALWAYS_STREAM = False
Expand Down Expand Up @@ -276,8 +277,6 @@ def _convert_args(args, kwargs):
>>> PipePy('ls', '--sort=size', '-l')
"""

args = [str(arg) for arg in args]

final_args = []
for arg in args:
arg = str(arg)
Expand All @@ -290,7 +289,10 @@ def _convert_args(args, kwargs):
for key, value in kwargs.items():
key = key.replace("_", "-")
if value is True:
final_args.append(f"--{key}")
if len(key) == 1:
final_args.append(f"-{key}")
else:
final_args.append(f"--{key}")
elif value is False:
final_args.append(f"--no-{key}")
elif len(key) == 1:
Expand All @@ -301,7 +303,7 @@ def _convert_args(args, kwargs):

# Lifetime implementation
def _evaluate(self):
"""Start an evaluations, Lazy commands that have been evaluated before
"""Start an evaluation, Lazy commands that have been evaluated before
will abort. The lifetime of a command being evaluated consists of 3
steps:
Expand Down Expand Up @@ -341,7 +343,9 @@ def _start_background_job(self, stdin_to_pipe=False):
self._input._start_background_job(stdin_to_pipe=stdin_to_pipe)
stdin = self._input._process.stdout
elif (
is_iterable(self._input) or stdin_to_pipe or isinstance(self._input, _File)
isinstance(self._input, Iterable)
or stdin_to_pipe
or isinstance(self._input, _File)
):
stdin = PIPE
else:
Expand Down Expand Up @@ -405,7 +409,7 @@ def _feed_input(self):
self._process.stdin.write(line)
self._process.stdin.flush()
self._process.stdin.close()
elif is_iterable(left):
elif isinstance(left, Iterable):
if isinstance(left, (str, bytes)):
left = [left]
for chunk in left:
Expand Down Expand Up @@ -802,7 +806,7 @@ def _pipe(left, right):
if isinstance(left, PipePy) and isinstance(right, PipePy):
return right(_input=left)
elif isinstance(right, PipePy):
if is_iterable(left):
if isinstance(left, Iterable):
return right(_input=left)
else:
return NotImplemented
Expand Down
9 changes: 0 additions & 9 deletions src/pipepy/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
def is_iterable(value):
try:
iter(value)
except TypeError:
return False
else:
return True


class _File:
"""Simple container for a filename. Mainly needed to be able to run
`isinstance(..., _FILE)`
Expand Down

0 comments on commit e2ff95b

Please sign in to comment.