summaryrefslogtreecommitdiff
path: root/patternutils/commands/targs.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--patternutils/commands/targs.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py
index 9fd0831..bcd2e8e 100644
--- a/patternutils/commands/targs.py
+++ b/patternutils/commands/targs.py
@@ -12,12 +12,7 @@ from .. import config, template, utils
def run_command(data: Dict[str, str], run: Callable[..., None], shell: bool,) -> None:
- if not shell:
- prepared_command = shlex.split(c) # type: Union[str, List[str]]
- else:
- prepared_command = c
-
- run(prepared_command)
+ run(shlex.split(command) if not shell else command)
@click.command(context_settings={"help_option_names": ("-h", "--help", "-?")})
@@ -85,7 +80,7 @@ def targs(
if not stream:
data = json.load(read_from) # type: ignore
else:
- data = [json.loads(line) for line in read_from]
+ data = [json.loads(line) for line in read_from] # type: ignore
except json.JSONDecodeError:
click.secho("JSON not valid!", fg="red", err=True)
raise SystemExit
@@ -106,17 +101,15 @@ def targs(
click.secho("jinja2 not installed!", fg="red", err=True)
raise SystemExit
- commands = [render(r) for r in data]
+ commands = {r: render(r) for r in data}
if editor:
try:
commands = utils.edit(commands)
- except RuntimeErro:
+ except RuntimeError:
click.secho("Your edit is not parseable!", fg="red", err=True)
raise SystemExit
- max_procs = utils.max_procs() if max_procs == 0 else max_procs
-
stdout = subprocess.DEVNULL if redirect_stdout else None
stderr = subprocess.DEVNULL if redirect_stderr else None
patched_subprocess = functools.partial(
@@ -125,12 +118,15 @@ def targs(
patched_run_command = functools.partial(
run_command, run=patched_subprocess, shell=shell,
)
+
+ max_procs = utils.max_procs() if max_procs == 0 else max_procs
+
if max_procs == 1:
for r in commands:
patched_run_command(r)
else:
with multiprocessing.Pool(max_procs) as p:
- p.map(patched_run_command, commands)
+ p.map(patched_run_command, commands.values())
if __name__ == "__main__":