From fdf7caab3310327d6cd15b56ac22c73248890832 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 22 Sep 2019 11:25:50 -0400 Subject: [PATCH] restore -i --- bake/bakefile.py | 8 ++++---- bake/bash.py | 17 +++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/bake/bakefile.py b/bake/bakefile.py index abcf5df..65f97ed 100644 --- a/bake/bakefile.py +++ b/bake/bakefile.py @@ -545,18 +545,18 @@ class TaskScript(BaseAction): args = " ".join([shlex_quote(a) for a in self.bashfile.args]) args = args if args else "\b" - sed_magic = "sed >&2 's/^/ | /'" if not silent else "sed >&2 's/^//'" + sed_magic = "2>&1 | sed >&2 's/^/ | /'" if not (silent or interactive) else "" script = ( f"t=$(mktemp) && bake --source {self.name} " - f"> $t && chmod +x $t && $t {args} 2>&1 | " - f"{sed_magic}" + ' && exit "${PIPESTATUS[1]}"; rm -fr $t' + "> ${t} && chmod +x ${t} && ${t} " + f"{args}" + " && EXIT=${?} " + f"{sed_magic}" + "; rm -fr ${t} && exit ${EXIT}" ) if debug: click.echo(f" {click.style('$', fg='green')} {script}", err=True) - bash = Bash() + bash = Bash(interactive=interactive) return bash.command(script, quote=False) @property diff --git a/bake/bash.py b/bake/bash.py index deef365..2ebdda3 100644 --- a/bake/bash.py +++ b/bake/bash.py @@ -130,13 +130,11 @@ class BashProcess: class Bash: """an instance of bash""" - def __init__(self, *, path=WHICH_BASH, environ=None): + def __init__(self, *, path=WHICH_BASH, environ=None, **kwargs): """constructor""" self.path = path self.environ = environ or {} - - ver_proc = self("--version") - self.about = ver_proc.output + self.kwargs = kwargs @property def version(self) -> str: @@ -145,16 +143,15 @@ class Bash: # ...GNU Bash, version 4.4.19(1)-release ... --> 4.4.19(1)-release return matches.group(1) if matches else "version_unknown" + @property + def about(self): + return self("--version").output + def __call__(self, *args) -> BashProcess: """execute the bash process as a child of this process""" - return BashProcess(parent=self, args=args) + return BashProcess(parent=self, args=args, **self.kwargs) def command(self, script: str, quote=True) -> BashProcess: """form up the command with shlex and execute""" maybe_quote = shlex_quote if quote else str return self(f"-c", maybe_quote(script)) - - -def run(script=None, **kwargs): - """Runs the given bash script.""" - return Bash(**kwargs).command(script)