Skip to content

Commit

Permalink
Fixes for all of the plugins. Added a script to invoke mypy. (I'm sti…
Browse files Browse the repository at this point in the history
…iiick of .bat files. They are just broken.)
  • Loading branch information
sedwards2009 committed Jan 17, 2017
1 parent fb70eb6 commit 1b43e49
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 20 deletions.
12 changes: 8 additions & 4 deletions cura/CrashHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
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
Expand Down
4 changes: 3 additions & 1 deletion plugins/3MFReader/ThreeMFReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
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
Expand Down
8 changes: 4 additions & 4 deletions plugins/3MFReader/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 3 additions & 1 deletion plugins/3MFWriter/ThreeMFWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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
Expand Down
5 changes: 3 additions & 2 deletions plugins/SliceInfoPlugin/SliceInfo.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -26,8 +27,8 @@
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__()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugins/USBPrinting/USBPrinterOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugins/USBPrinting/USBPrinterOutputDeviceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def connectedPrinterList(self):
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
Expand All @@ -277,4 +277,4 @@ def getSerialPortList(self, only_list_usb = False):
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"
4 changes: 2 additions & 2 deletions plugins/USBPrinting/avr_isp/stk500v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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
Expand Down Expand Up @@ -184,7 +184,7 @@ def recvMessage(self):

def portList():
ret = []
import _winreg
import _winreg # type: ignore
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") #@UndefinedVariable
i=0
while True:
Expand Down
4 changes: 3 additions & 1 deletion plugins/X3DReader/X3DReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
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

Expand Down
31 changes: 31 additions & 0 deletions run_mypy.py
Original file line number Diff line number Diff line change
@@ -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.
""")

0 comments on commit 1b43e49

Please sign in to comment.