diff -r 5ea038882dd6 -r c1a2ff7e3575 scripts/install.py --- a/scripts/install.py Tue Nov 21 11:42:45 2023 +0100 +++ b/scripts/install.py Wed Nov 22 17:19:10 2023 +0100 @@ -611,14 +611,12 @@ """ Clean up the Desktop and Start Menu entries for Windows. """ - global doCleanDesktopLinks, forceCleanDesktopLinks - - try: - from pywintypes import com_error # __IGNORE_WARNING__ - except ImportError: + if importlib.util.find_spec("pywintypes") is None: # links were not created by install.py return + global doCleanDesktopLinks, forceCleanDesktopLinks + regPath = ( "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" + "\\User Shell Folders" @@ -1045,10 +1043,7 @@ """ Create Desktop and Start Menu links. """ - try: - # check, if pywin32 is available - from win32com.client import Dispatch # __IGNORE_WARNING__ - except (ImportError, ModuleNotFoundError): # noqa: M514 + if importlib.util.find_spec("win32com") is None: installed = pipInstall( "pywin32", "\nThe Python package 'pywin32' could not be imported.", @@ -1525,9 +1520,10 @@ print("Yours is {0}.".format(".".join(str(v) for v in sys.version_info[:3]))) exit(5) - try: - import xml.etree # __IGNORE_WARNING__ - except ImportError: + if ( + importlib.util.find_spec("xml") is None + or importlib.util.find_spec("xml.etree") is None + ): print("Your Python installation is missing the XML module.") print("Please install it and try again.") exit(5) @@ -1557,25 +1553,17 @@ exit(1) print("Found PyQt6") - try: - pyuic = "pyuic6" - from PyQt6 import uic # __IGNORE_WARNING__ - except ImportError as err: + pyuic = "pyuic6" + if importlib.util.find_spec("PyQt6.uic") is None: print("Sorry, {0} is not installed.".format(pyuic)) - if verbose: - print("Error: {0}".format(err)) exit(1) print("Found {0}".format(pyuic)) - try: - from PyQt6 import QtWebEngineWidgets # __IGNORE_WARNING__ - except ImportError as err: + if importlib.util.find_spec("PyQt6.QtWebEngineWidgets") is None: if isSudo: print("Optional 'PyQt6-WebEngine' could not be detected.") else: - msg = "Optional 'PyQt6-WebEngine' could not be detected.{0}".format( - "\nError: {0}".format(err) if verbose else "" - ) + msg = "Optional 'PyQt6-WebEngine' could not be detected." pipInstall( "PyQt6-WebEngine>={0}".format( versionToStr(requiredVersions["pyqt6-webengine"]) @@ -1584,15 +1572,11 @@ ) print("Found PyQt6-WebEngine") - try: - from PyQt6 import QtCharts # __IGNORE_WARNING__ - except ImportError as err: + if importlib.util.find_spec("PyQt6.QtCharts") is None: if isSudo: print("Optional 'PyQt6-Charts' could not be detected.") else: - msg = "Optional 'PyQt6-Charts' could not be detected.{0}".format( - "\nError: {0}".format(err) if verbose else "" - ) + msg = "Optional 'PyQt6-Charts' could not be detected." pipInstall( "PyQt6-Charts>={0}".format( versionToStr(requiredVersions["pyqt6-charts"]) @@ -1601,28 +1585,15 @@ ) print("Found PyQt6-Charts") - try: - from PyQt6 import Qsci # __IGNORE_WARNING__ - except ImportError as err: - msg = "'PyQt6-QScintilla' could not be detected.{0}".format( - "\nError: {0}".format(err) if verbose else "" - ) + if importlib.util.find_spec("PyQt6.Qsci") is None: + msg = "'PyQt6-QScintilla' could not be detected." installed = not isSudo and pipInstall( "PyQt6-QScintilla>={0}".format( versionToStr(requiredVersions["pyqt6-qscintilla"]) ), msg, ) - if installed: - # try to import it again - try: - from PyQt6 import Qsci # __IGNORE_WARNING__ - - message = None - except ImportError as msg: - message = str(msg) - else: - message = "PyQt6-QScintilla could not be installed." + message = None if installed else "PyQt6-QScintilla could not be installed." if message: print("Sorry, please install QScintilla2 and") print("its PyQt6 wrapper.") @@ -1845,7 +1816,9 @@ # print version info for additional modules with contextlib.suppress(NameError, AttributeError): - print("PyQt6-Charts:", QtCharts.PYQT_CHART_VERSION_STR) + from PyQt6.QtCharts import PYQT_CHART_VERSION_STR # noqa: I101, I102 + + print("PyQt6-Charts:", PYQT_CHART_VERSION_STR) with contextlib.suppress(ImportError, AttributeError): from PyQt6 import QtWebEngineCore # noqa: I101, I102 @@ -1928,7 +1901,7 @@ ProcessPoolExecutor = None if workers != 1: try: - from concurrent.futures import ProcessPoolExecutor # __IGNORE_WARNING__ + from concurrent.futures import ProcessPoolExecutor # noqa: I101, I103 except NotImplementedError: workers = 1