From e28a662d7ce3e63929da5e5cb9e89bad64ad9fbb Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 30 Dec 2019 13:44:54 +0100 Subject: [PATCH] Speed up mypy checking Checking Cura takes up most of the time, but during that time we could check for the plugins. --- run_mypy.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/run_mypy.py b/run_mypy.py index 6be424bda8..d93e1cafc8 100644 --- a/run_mypy.py +++ b/run_mypy.py @@ -1,8 +1,9 @@ #!/usr/bin/env python import os import sys -import subprocess - +from multiprocessing.dummy import Pool +from functools import partial +from subprocess import call # A quick Python implementation of unix 'where' command. def where(exe_name: str, search_path: str = os.getenv("PATH")) -> str: @@ -62,21 +63,23 @@ def main(): mods = ["cura"] + plugins + findModules("plugins/VersionUpgrade") success_code = 0 - for mod in mods: - print("------------- Checking module {mod}".format(**locals())) - if sys.platform == "win32": - result = subprocess.run([mypy_module, "-p", mod, "--ignore-missing-imports"]) - else: - result = subprocess.run([sys.executable, mypy_module, "-p", mod, "--ignore-missing-imports"]) - if result.returncode != 0: - print("\nModule {mod} failed checking. :(".format(**locals())) - success_code = 1 - if success_code: - print("\n\nSome modules failed checking!") + + pool = Pool(2) # Run two commands at once + + if sys.platform == "win32": + commands = ["%s -p %s --ignore-missing-imports" % (mypy_module, mod) for mod in mods] else: - print("\n\nDone checking. All is good.") + commands = ["%s %s -p %s --ignore-missing-imports" % (sys.executable, mypy_module, mod) for mod in mods] + + for i, returncode in enumerate(pool.imap(partial(call, shell=True), commands)): + if returncode != 0: + print("\nCommand %s failed checking. :(" % commands[i]) + success_code = 1 + if success_code: + print("MYPY check was compleded, but did not pass") + else: + print("MYPY check was compleded and passed with flying colors") return success_code - if __name__ == "__main__": - sys.exit(main()) + sys.exit(main()) \ No newline at end of file