run_mypy.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!env python
  2. import os
  3. import sys
  4. import subprocess
  5. # A quick Python implementation of unix 'where' command.
  6. def where(exeName):
  7. searchPath = os.getenv("PATH")
  8. paths = searchPath.split(";" if sys.platform == "win32" else ":")
  9. for path in paths:
  10. candidatePath = os.path.join(path, exeName)
  11. if os.path.exists(candidatePath):
  12. return candidatePath
  13. return None
  14. def findModules(path):
  15. result = []
  16. for entry in os.scandir(path):
  17. if entry.is_dir() and os.path.exists(os.path.join(path, entry.name, "__init__.py")):
  18. result.append(entry.name)
  19. return result
  20. def main():
  21. if sys.platform == "win32":
  22. os.putenv("MYPYPATH", r".;.\plugins;.\plugins\VersionUpgrade;..\Uranium\;..\Uranium\stubs\\" )
  23. else:
  24. os.putenv("MYPYPATH", r".:./plugins:./plugins/VersionUpgrade:../Uranium/:../Uranium\stubs/")
  25. # Mypy really needs to be run via its Python script otherwise it can't find its data files.
  26. mypyExe = where("mypy.bat" if sys.platform == "win32" else "mypy")
  27. mypyModule = os.path.join(os.path.dirname(mypyExe), "mypy")
  28. plugins = findModules("plugins")
  29. plugins.sort()
  30. mods = ["cura"] + plugins + findModules("plugins/VersionUpgrade")
  31. for mod in mods:
  32. print("------------- Checking module {mod}".format(**locals()))
  33. result = subprocess.run([sys.executable, mypyModule, "-p", mod])
  34. if result.returncode != 0:
  35. print("""
  36. Module {mod} failed checking. :(
  37. """.format(**locals()))
  38. break
  39. else:
  40. print("""
  41. Done checking. All is good.
  42. """)
  43. return 0
  44. sys.exit(main())