diff options
-rw-r--r-- | cura/CrashHandler.py | 12 | ||||
-rw-r--r-- | plugins/3MFReader/ThreeMFReader.py | 4 | ||||
-rw-r--r-- | plugins/3MFReader/__init__.py | 8 | ||||
-rw-r--r-- | plugins/3MFWriter/ThreeMFWriter.py | 4 | ||||
-rw-r--r-- | plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py | 2 | ||||
-rw-r--r-- | plugins/SliceInfoPlugin/SliceInfo.py | 5 | ||||
-rw-r--r-- | plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py | 2 | ||||
-rw-r--r-- | plugins/USBPrinting/USBPrinterOutputDevice.py | 2 | ||||
-rw-r--r-- | plugins/USBPrinting/USBPrinterOutputDeviceManager.py | 4 | ||||
-rw-r--r-- | plugins/USBPrinting/avr_isp/stk500v2.py | 4 | ||||
-rw-r--r-- | plugins/X3DReader/X3DReader.py | 4 | ||||
-rw-r--r-- | run_mypy.py | 31 |
12 files changed, 62 insertions, 20 deletions
diff --git a/cura/CrashHandler.py b/cura/CrashHandler.py index ba8499d4f2..b658f88824 100644 --- a/cura/CrashHandler.py +++ b/cura/CrashHandler.py @@ -12,10 +12,14 @@ from UM.Logger import Logger from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") -try: - from cura.CuraVersion import CuraDebugMode -except ImportError: - CuraDebugMode = False # [CodeStyle: Reflecting imported value] +MYPY = False +if MYPY: + CuraDebugMode = False +else: + try: + from cura.CuraVersion import CuraDebugMode + except ImportError: + CuraDebugMode = False # [CodeStyle: Reflecting imported value] # List of exceptions that should be considered "fatal" and abort the program. # These are primarily some exception types that we simply cannot really recover from diff --git a/plugins/3MFReader/ThreeMFReader.py b/plugins/3MFReader/ThreeMFReader.py index 976f54ba25..5638ce551c 100644 --- a/plugins/3MFReader/ThreeMFReader.py +++ b/plugins/3MFReader/ThreeMFReader.py @@ -17,8 +17,10 @@ from cura.Settings.ExtruderManager import ExtruderManager from cura.QualityManager import QualityManager from UM.Scene.SceneNode import SceneNode +MYPY = False try: - import xml.etree.cElementTree as ET + if not MYPY: + import xml.etree.cElementTree as ET except ImportError: Logger.log("w", "Unable to load cElementTree, switching to slower version") import xml.etree.ElementTree as ET diff --git a/plugins/3MFReader/__init__.py b/plugins/3MFReader/__init__.py index 3e05cb8dc7..cb4f9b9761 100644 --- a/plugins/3MFReader/__init__.py +++ b/plugins/3MFReader/__init__.py @@ -1,16 +1,16 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. +from typing import Dict from . import ThreeMFReader from . import ThreeMFWorkspaceReader from UM.i18n import i18nCatalog -import UM.Platform +from UM.Platform import Platform catalog = i18nCatalog("cura") - -def getMetaData(): +def getMetaData() -> Dict: # Workarround for osx not supporting double file extensions correclty. - if UM.Platform.isOSX(): + if Platform.isOSX(): workspace_extension = "3mf" else: workspace_extension = "curaproject.3mf" diff --git a/plugins/3MFWriter/ThreeMFWriter.py b/plugins/3MFWriter/ThreeMFWriter.py index 882740c4ed..361cf796d0 100644 --- a/plugins/3MFWriter/ThreeMFWriter.py +++ b/plugins/3MFWriter/ThreeMFWriter.py @@ -7,8 +7,10 @@ from UM.Logger import Logger from UM.Math.Matrix import Matrix from UM.Application import Application +MYPY = False try: - import xml.etree.cElementTree as ET + if not MYPY: + import xml.etree.cElementTree as ET except ImportError: Logger.log("w", "Unable to load cElementTree, switching to slower version") import xml.etree.ElementTree as ET diff --git a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py index 14a4681bc3..42f3935f65 100644 --- a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py +++ b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py @@ -8,7 +8,7 @@ catalog = i18nCatalog("cura") from . import RemovableDrivePlugin import string -import ctypes +import ctypes # type: ignore from ctypes import wintypes # Using ctypes.wintypes in the code below does not seem to work from UM.i18n import i18nCatalog diff --git a/plugins/SliceInfoPlugin/SliceInfo.py b/plugins/SliceInfoPlugin/SliceInfo.py index 4f39fd4818..05f7c0e6f5 100644 --- a/plugins/SliceInfoPlugin/SliceInfo.py +++ b/plugins/SliceInfoPlugin/SliceInfo.py @@ -1,5 +1,6 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. +from typing import Any from cura.CuraApplication import CuraApplication @@ -26,8 +27,8 @@ import json catalog = i18nCatalog("cura") class SliceInfoJob(Job): - data = None - url = None + data = None # type: Any + url = None # type: str def __init__(self, url, data): super().__init__() diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py index 2725fa8d17..fe35b60de5 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py @@ -1,7 +1,7 @@ from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin from . import NetworkPrinterOutputDevice -from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo +from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo # type: ignore from UM.Logger import Logger from UM.Signal import Signal, signalemitter from UM.Application import Application diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index e344caee1d..7adb0b0d08 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -2,7 +2,7 @@ # Cura is released under the terms of the AGPLv3 or higher. from .avr_isp import stk500v2, ispBase, intelHex -import serial +import serial # type: ignore import threading import time import queue diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 4dec2e3a06..ed97076df6 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -258,7 +258,7 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): def getSerialPortList(self, only_list_usb = False): base_list = [] if platform.system() == "Windows": - import winreg #@UnresolvedImport + import winreg # type: ignore @UnresolvedImport try: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") i = 0 @@ -277,4 +277,4 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*") return list(base_list) - _instance = None + _instance = None # type: "USBPrinterOutputDeviceManager" diff --git a/plugins/USBPrinting/avr_isp/stk500v2.py b/plugins/USBPrinting/avr_isp/stk500v2.py index 91bef53875..dbfc8dc756 100644 --- a/plugins/USBPrinting/avr_isp/stk500v2.py +++ b/plugins/USBPrinting/avr_isp/stk500v2.py @@ -7,7 +7,7 @@ import struct import sys import time -from serial import Serial +from serial import Serial # type: ignore from serial import SerialException from serial import SerialTimeoutException from UM.Logger import Logger @@ -184,7 +184,7 @@ class Stk500v2(ispBase.IspBase): def portList(): ret = [] - import _winreg + import _winreg # type: ignore key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") #@UndefinedVariable i=0 while True: diff --git a/plugins/X3DReader/X3DReader.py b/plugins/X3DReader/X3DReader.py index 0a81e98d0d..f78023dfab 100644 --- a/plugins/X3DReader/X3DReader.py +++ b/plugins/X3DReader/X3DReader.py @@ -13,8 +13,10 @@ from UM.Mesh.MeshBuilder import MeshBuilder from UM.Mesh.MeshReader import MeshReader from UM.Scene.SceneNode import SceneNode +MYPY = False try: - import xml.etree.cElementTree as ET + if not MYPY: + import xml.etree.cElementTree as ET except ImportError: import xml.etree.ElementTree as ET diff --git a/run_mypy.py b/run_mypy.py new file mode 100644 index 0000000000..7c203f87d9 --- /dev/null +++ b/run_mypy.py @@ -0,0 +1,31 @@ +#!env python
+import os
+import subprocess
+
+os.putenv("MYPYPATH", r".;.\plugins;..\Uranium_hint\;..\Uranium_hint\stubs\\" )
+
+def findModules(path):
+ result = []
+ for entry in os.scandir(path):
+ if entry.is_dir() and os.path.exists(os.path.join(path, entry.name, "__init__.py")):
+ result.append(entry.name)
+ return result
+
+plugins = findModules("plugins")
+plugins.sort()
+
+mods = ["cura"] + plugins
+
+for mod in mods:
+ print("------------- Checking module {mod}".format(**locals()))
+ result = subprocess.run(["python", r"c:\python35\Scripts\mypy", "-p", mod])
+ if result.returncode != 0:
+ print("""
+Module {mod} failed checking. :(
+""".format(**locals()))
+ break
+else:
+ print("""
+
+Done checking. All is good.
+""")
|