Fixes for all of the plugins. Added a script to invoke mypy. (I'm stiiiick of .bat files. They are just broken.)

This commit is contained in:
Simon Edwards 2017-01-17 16:57:37 +01:00
parent fb70eb6813
commit 1b43e4981e
12 changed files with 62 additions and 20 deletions

View file

@ -12,10 +12,14 @@ from UM.Logger import Logger
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
try: MYPY = False
from cura.CuraVersion import CuraDebugMode if MYPY:
except ImportError: CuraDebugMode = False
CuraDebugMode = False # [CodeStyle: Reflecting imported value] 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. # 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 # These are primarily some exception types that we simply cannot really recover from

View file

@ -17,8 +17,10 @@ from cura.Settings.ExtruderManager import ExtruderManager
from cura.QualityManager import QualityManager from cura.QualityManager import QualityManager
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
MYPY = False
try: try:
import xml.etree.cElementTree as ET if not MYPY:
import xml.etree.cElementTree as ET
except ImportError: except ImportError:
Logger.log("w", "Unable to load cElementTree, switching to slower version") Logger.log("w", "Unable to load cElementTree, switching to slower version")
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET

View file

@ -1,16 +1,16 @@
# Copyright (c) 2015 Ultimaker B.V. # Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from typing import Dict
from . import ThreeMFReader from . import ThreeMFReader
from . import ThreeMFWorkspaceReader from . import ThreeMFWorkspaceReader
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
import UM.Platform from UM.Platform import Platform
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
def getMetaData() -> Dict:
def getMetaData():
# Workarround for osx not supporting double file extensions correclty. # Workarround for osx not supporting double file extensions correclty.
if UM.Platform.isOSX(): if Platform.isOSX():
workspace_extension = "3mf" workspace_extension = "3mf"
else: else:
workspace_extension = "curaproject.3mf" workspace_extension = "curaproject.3mf"

View file

@ -7,8 +7,10 @@ from UM.Logger import Logger
from UM.Math.Matrix import Matrix from UM.Math.Matrix import Matrix
from UM.Application import Application from UM.Application import Application
MYPY = False
try: try:
import xml.etree.cElementTree as ET if not MYPY:
import xml.etree.cElementTree as ET
except ImportError: except ImportError:
Logger.log("w", "Unable to load cElementTree, switching to slower version") Logger.log("w", "Unable to load cElementTree, switching to slower version")
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET

View file

@ -8,7 +8,7 @@ catalog = i18nCatalog("cura")
from . import RemovableDrivePlugin from . import RemovableDrivePlugin
import string 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 ctypes import wintypes # Using ctypes.wintypes in the code below does not seem to work
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog

View file

@ -1,5 +1,6 @@
# Copyright (c) 2015 Ultimaker B.V. # Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from typing import Any
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
@ -26,8 +27,8 @@ import json
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
class SliceInfoJob(Job): class SliceInfoJob(Job):
data = None data = None # type: Any
url = None url = None # type: str
def __init__(self, url, data): def __init__(self, url, data):
super().__init__() super().__init__()

View file

@ -1,7 +1,7 @@
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
from . import NetworkPrinterOutputDevice 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.Logger import Logger
from UM.Signal import Signal, signalemitter from UM.Signal import Signal, signalemitter
from UM.Application import Application from UM.Application import Application

View file

@ -2,7 +2,7 @@
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from .avr_isp import stk500v2, ispBase, intelHex from .avr_isp import stk500v2, ispBase, intelHex
import serial import serial # type: ignore
import threading import threading
import time import time
import queue import queue

View file

@ -258,7 +258,7 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
def getSerialPortList(self, only_list_usb = False): def getSerialPortList(self, only_list_usb = False):
base_list = [] base_list = []
if platform.system() == "Windows": if platform.system() == "Windows":
import winreg #@UnresolvedImport import winreg # type: ignore @UnresolvedImport
try: try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
i = 0 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/*") 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) return list(base_list)
_instance = None _instance = None # type: "USBPrinterOutputDeviceManager"

View file

@ -7,7 +7,7 @@ import struct
import sys import sys
import time import time
from serial import Serial from serial import Serial # type: ignore
from serial import SerialException from serial import SerialException
from serial import SerialTimeoutException from serial import SerialTimeoutException
from UM.Logger import Logger from UM.Logger import Logger
@ -184,7 +184,7 @@ class Stk500v2(ispBase.IspBase):
def portList(): def portList():
ret = [] ret = []
import _winreg import _winreg # type: ignore
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") #@UndefinedVariable key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") #@UndefinedVariable
i=0 i=0
while True: while True:

View file

@ -13,8 +13,10 @@ from UM.Mesh.MeshBuilder import MeshBuilder
from UM.Mesh.MeshReader import MeshReader from UM.Mesh.MeshReader import MeshReader
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
MYPY = False
try: try:
import xml.etree.cElementTree as ET if not MYPY:
import xml.etree.cElementTree as ET
except ImportError: except ImportError:
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET

31
run_mypy.py Normal file
View file

@ -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.
""")