diff --git a/looper/main.py b/looper/main.py index 4bc12ba..4fb5c62 100755 --- a/looper/main.py +++ b/looper/main.py @@ -3,18 +3,18 @@ import sys import cli_ui as ui -from typing import List, Optional +from typing import List, Optional, Any ArgsList = Optional[List[str]] -def run(cmd: str, capture: bool) -> int: + +def run(cmd: str, capture: bool, **kwargs: Any) -> int: ui.info_2(cmd) - cmd = cmd.split() - kwargs = {} + cmd_list = cmd.split() if capture: kwargs['stdout'] = subprocess.PIPE kwargs['stderr'] = subprocess.PIPE - process = subprocess.run(cmd, **kwargs) + process = subprocess.run(cmd_list, **kwargs) if process.returncode: if process.stdout: ui.info_1(process.stdout.decode("utf-8")) @@ -23,26 +23,26 @@ def run(cmd: str, capture: bool) -> int: return process.returncode -def loop(cmd: List, max_tries: int, stop_on_first_fail: bool, capture: bool) -> None: +def loop(cmd: List[str], max_tries: int, stop_on_first_fail: bool, capture: bool) -> None: if not cmd or not cmd[0]: ui.error("no command provided") sys.exit(1) - cmd = cmd[0] + cmd_str = cmd[0] runs = 0 fails = 0 try: while True: - if run(cmd, capture): + if run(cmd_str, capture): if stop_on_first_fail: return fails += 1 runs += 1 if max_tries and runs >= max_tries: - ui.info_1(f"command \"{cmd}\" failed {fails} times after {max_tries} tries") + ui.info_1(f"command \"{cmd_str}\" failed {fails} times after {max_tries} tries") return except KeyboardInterrupt: ui.info_2("Interrupted by user") - ui.info_1(f"command \"{cmd}\" failed {fails} times after {max_tries} tries") + ui.info_1(f"command \"{cmd_str}\" failed {fails} times after {max_tries} tries") def main(args: ArgsList = None) -> None: diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..6a9fdec --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[flake8] +max-line-length=100 + +exclude = + .venv diff --git a/setup.py b/setup.py index 86c69f0..55b342f 100644 --- a/setup.py +++ b/setup.py @@ -4,10 +4,12 @@ if sys.version_info.major < 3: sys.exit("Error: Please upgrade to Python3") -def get_long_description(): + +def get_long_description() -> str: with open("README.md") as fp: return fp.read() + setup( name="py-loop", version="0.1.0",