diff options
| author | Dennis Fink | 2020-09-26 15:20:49 +0200 |
|---|---|---|
| committer | Dennis Fink | 2020-09-26 15:20:49 +0200 |
| commit | 9b80026a5bc0aa0504dfb46ef8a25e5204d5a86a (patch) | |
| tree | b3c871effea4ca1447569260daeb42e1ddb8dae4 | |
| parent | fe3da4725160110b2b4ac969190161a29204ba7c (diff) | |
| download | patternutils-9b80026a5bc0aa0504dfb46ef8a25e5204d5a86a.tar.gz patternutils-9b80026a5bc0aa0504dfb46ef8a25e5204d5a86a.zip | |
Fix targs
| -rw-r--r-- | patternutils/commands/targs.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 04c286d..6478377 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -12,16 +12,11 @@ from .. import config, template, utils def run_command( - data: Dict[str, str], + command: 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", "-?")}) @@ -89,7 +84,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 @@ -110,17 +105,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( @@ -134,12 +127,15 @@ def targs( 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__": |
