PluginPyright.py

Tue, 07 Nov 2023 16:45:04 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 07 Nov 2023 16:45:04 +0100
branch
eric7
changeset 3
109b8e5513d8
parent 1
191e9ec72893
child 9
1ef1797f5f58
permissions
-rw-r--r--

Added the plugin function to determine the interfaced executable version information.

1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
1 # -*- coding: utf-8 -*-
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
2
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
3 # Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de>
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
4 #
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
5
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
6 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
7 Module implementing the pyright plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
8 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
9
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
10 import contextlib
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
11 import os
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
12
3
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
13 from PyQt6.QtCore import QCoreApplication, QObject, QTranslator, pyqtSlot
1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
14
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
15 from eric7 import Preferences
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
16 from eric7.EricGui.EricAction import EricAction
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
17 from eric7.EricWidgets.EricApplication import ericApp
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
18 from eric7.Project.ProjectBrowserModel import ProjectBrowserFileItem
3
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
19 from eric7.SystemUtilities import PythonUtilities
1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
20
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
21 # Start-Of-Header
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
22 __header__ = {
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
23 "name": "Python Typing Checker Plug-in",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
24 "author": "Detlev Offenbach <detlev@die-offenbachs.de>",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
25 "autoactivate": True,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
26 "deactivateable": True,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
27 "version": "10.0.0",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
28 "className": "PyrightPlugin",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
29 "packageName": "PyrightChecker",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
30 "shortDescription": "Plug-in to check Python sources for typing issues.",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
31 "longDescription": ("""Plug-in to check Python sources for typing issues."""),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
32 "needsRestart": False,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
33 "pyqtApi": 2,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
34 }
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
35 # End-Of-Header
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
36
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
37 error = "" # noqa: U200
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
38
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
39
3
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
40 def exeDisplayData():
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
41 """
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
42 Public method to support the display of some executable info.
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
43
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
44 @return dictionary containing the data to query the presence of
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
45 the executable
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
46 @rtype dict
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
47 """
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
48 data = {
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
49 "programEntry": True,
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
50 "header": QCoreApplication.translate(
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
51 "PyrightPlugin", "Checkers - Pyright"
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
52 ),
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
53 "exe": PythonUtilities.getPythonExecutable(),
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
54 "versionCommand": "--version",
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
55 "versionStartsWith": "pyright",
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
56 "versionPosition": -1,
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
57 "version": "",
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
58 "versionCleanup": None,
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
59 "exeModule": ["-m", "pyright"]
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
60 }
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
61
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
62 return data
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
63
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
64
1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
65 def prepareUninstall():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
66 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
67 Module function to prepare for an uninstallation.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
68 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
69 Preferences.Prefs.settings.remove(PyrightPlugin.PreferencesKey)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
70
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
71
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
72 class PyrightPlugin(QObject):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
73 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
74 Class documentation goes here.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
75 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
76
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
77 PreferencesKey = "Pyright"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
78
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
79 def __init__(self, ui):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
80 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
81 Constructor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
82
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
83 @param ui reference to the user interface object
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
84 @type UI.UserInterface
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
85 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
86 super().__init__(ui)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
87 self.__ui = ui
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
88 self.__initialize()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
89
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
90 def __initialize(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
91 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
92 Private slot to (re)initialize the plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
93 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
94 self.__projectAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
95 self.__projectPyrightCheckerDialog = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
96
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
97 self.__projectBrowserAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
98 self.__projectBrowserMenu = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
99 self.__projectBrowserPyrightCheckerDialog = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
100
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
101 self.__editors = []
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
102 self.__editorAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
103 self.__editorPyrightCheckerDialog = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
104
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
105 def activate(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
106 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
107 Public method to activate this plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
108
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
109 @return tuple of None and activation status
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
110 @rtype bool
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
111 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
112 global error
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
113 error = "" # clear previous error
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
114
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
115 menu = ericApp().getObject("Project").getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
116 if menu:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
117 self.__projectAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
118 self.tr("Static Type Check"),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
119 self.tr("Static &Typing..."),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
120 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
121 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
122 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
123 "project_check_pyright",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
124 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
125 self.__projectAct.setStatusTip(self.tr("Check for typing issues"))
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
126 self.__projectAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
127 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
128 """<b>Static Type Check...</b>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
129 """<p>This checks a Python project for static typing issues.</p>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
130 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
131 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
132 self.__projectAct.triggered.connect(self.__projectPyrightCheck)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
133 ericApp().getObject("Project").addEricActions([self.__projectAct])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
134 menu.addAction(self.__projectAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
135
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
136 self.__editorAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
137 self.tr("Static Type Check"), self.tr("Static &Typing..."), 0, 0, self, ""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
138 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
139 self.__editorAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
140 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
141 """<b>Static Type Check...</b>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
142 """<p>This checks a Python file for static typing issues.</p>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
143 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
144 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
145 self.__editorAct.triggered.connect(self.__editorPyrightCheck)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
146
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
147 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
148 ericApp().getObject("ProjectBrowser").getProjectBrowser(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
149 "sources"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
150 ).showMenu.connect(self.__projectBrowserShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
151 ericApp().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
152 ericApp().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
153
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
154 for editor in ericApp().getObject("ViewManager").getOpenEditors():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
155 self.__editorOpened(editor)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
156
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
157 return None, True
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
158
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
159 def deactivate(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
160 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
161 Public method to deactivate this plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
162 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
163 ericApp().getObject("Project").showMenu.disconnect(self.__projectShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
164 ericApp().getObject("ProjectBrowser").getProjectBrowser(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
165 "sources"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
166 ).showMenu.disconnect(self.__projectBrowserShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
167
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
168 menu = ericApp().getObject("Project").getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
169 if menu is not None and self.__projectAct is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
170 menu.removeAction(self.__projectAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
171 ericApp().getObject("Project").removeEricActions([self.__projectAct])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
172
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
173 if self.__projectBrowserMenu and self.__projectBrowserAct:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
174 self.__projectBrowserMenu.removeAction(self.__projectBrowserAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
175
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
176 for editor in self.__editors:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
177 editor.showMenu.disconnect(self.__editorShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
178 menu = editor.getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
179 if menu is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
180 menu.removeAction(self.__editorAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
181
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
182 self.__initialize()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
183
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
184 def __loadTranslator(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
185 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
186 Private method to load the translation file.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
187 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
188 if self.__ui is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
189 loc = self.__ui.getLocale()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
190 if loc and loc != "C":
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
191 locale_dir = os.path.join(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
192 os.path.dirname(__file__), "PyrightChecker", "i18n"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
193 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
194 translation = "pyright_{0}".format(loc)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
195 translator = QTranslator(None)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
196 loaded = translator.load(translation, locale_dir)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
197 if loaded:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
198 self.__translator = translator
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
199 ericApp().installTranslator(self.__translator)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
200 else:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
201 print(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
202 "Warning: translation file '{0}' could not be"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
203 " loaded.".format(translation)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
204 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
205 print("Using default.")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
206
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
207 def __projectShowMenu(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
208 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
209 menuName,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
210 menu, # noqa: U100
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
211 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
212 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
213 Private slot called, when the the project menu or a submenu is
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
214 about to be shown.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
215
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
216 @param menuName name of the menu to be shown
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
217 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
218 @param menu reference to the menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
219 @type QMenu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
220 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
221 if menuName == "Check" and self.__projectAct is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
222 self.__projectAct.setEnabled(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
223 ericApp().getObject("Project").getProjectLanguage() == "Python3"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
224 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
225
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
226 def __projectBrowserShowMenu(self, menuName, menu):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
227 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
228 Private slot called, when the the project browser menu or a submenu is
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
229 about to be shown.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
230
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
231 @param menuName name of the menu to be shown
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
232 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
233 @param menu reference to the menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
234 @type QMenu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
235 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
236 if (
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
237 menuName == "Checks"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
238 and ericApp().getObject("Project").getProjectLanguage() == "Python3"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
239 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
240 self.__projectBrowserMenu = menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
241 if self.__projectBrowserAct is None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
242 self.__projectBrowserAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
243 self.tr("Static Type Check"),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
244 self.tr("Static &Typing..."),
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
245 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
246 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
247 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
248 "",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
249 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
250 self.__projectBrowserAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
251 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
252 """<b>Static Type Check...</b>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
253 """<p>This checks Python files for static typing issues.</p>"""
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
254 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
255 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
256 self.__projectBrowserAct.triggered.connect(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
257 self.__projectBrowserPyrightCheck
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
258 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
259 if self.__projectBrowserAct not in menu.actions():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
260 menu.addAction(self.__projectBrowserAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
261
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
262 @pyqtSlot()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
263 def __projectPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
264 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
265 Private slot used to check the project for static typing issues.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
266 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
267 from PyrightChecker.PyrightCheckerDialog import PyrightCheckerDialog
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
268
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
269 project = ericApp().getObject("Project")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
270 project.saveAllScripts()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
271
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
272 if self.__projectPyrightCheckerDialog is None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
273 self.__projectPyrightCheckerDialog = PyrightCheckerDialog(self)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
274 self.__projectPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
275 self.__projectPyrightCheckerDialog.prepare(project)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
276
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
277 @pyqtSlot()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
278 def __projectBrowserPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
279 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
280 Private method to handle the static typing check context menu action of
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
281 the project sources browser.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
282 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
283 from PyrightChecker.PyrightCheckerDialog import PyrightCheckerDialog
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
284
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
285 browser = ericApp().getObject("ProjectBrowser").getProjectBrowser("sources")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
286 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
287 fn = []
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
288 for itm in browser.getSelectedItems([ProjectBrowserFileItem]):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
289 fn.append(itm.fileName())
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
290 else:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
291 itm = browser.model().item(browser.currentIndex())
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
292 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
293 fn = [itm.fileName()]
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
294 except AttributeError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
295 fn = [itm.dirName()]
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
296
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
297 self.__projectBrowserPyrightCheckerDialog = PyrightCheckerDialog(self)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
298 self.__projectBrowserPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
299 self.__projectBrowserPyrightCheckerDialog.start(fn, save=True)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
300
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
301 def __editorOpened(self, editor):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
302 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
303 Private slot called, when a new editor was opened.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
304
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
305 @param editor reference to the new editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
306 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
307 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
308 menu = editor.getMenu("Checks")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
309 if menu is not None:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
310 menu.addAction(self.__editorAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
311 editor.showMenu.connect(self.__editorShowMenu)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
312 self.__editors.append(editor)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
313
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
314 def __editorClosed(self, editor):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
315 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
316 Private slot called, when an editor was closed.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
317
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
318 @param editor reference to the editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
319 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
320 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
321 with contextlib.suppress(ValueError):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
322 self.__editors.remove(editor)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
323
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
324 def __editorShowMenu(self, menuName, menu, editor):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
325 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
326 Private slot called, when the the editor context menu or a submenu is
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
327 about to be shown.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
328
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
329 @param menuName name of the menu to be shown
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
330 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
331 @param menu reference to the menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
332 @type QMenu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
333 @param editor reference to the editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
334 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
335 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
336 if menuName == "Checks":
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
337 if self.__editorAct not in menu.actions():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
338 menu.addAction(self.__editorAct)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
339 self.__editorAct.setEnabled(editor.isPyFile())
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
340
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
341 def __editorPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
342 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
343 Private slot to handle the code style check context menu action
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
344 of the editors.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
345 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
346 from PyrightChecker.PyrightCheckerDialog import PyrightCheckerDialog
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
347
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
348 editor = ericApp().getObject("ViewManager").activeWindow()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
349 if (
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
350 editor is not None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
351 and editor.checkDirty()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
352 and editor.getFileName() is not None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
353 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
354 self.__editorPyrightCheckerDialog = PyrightCheckerDialog(self)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
355 self.__editorPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
356 self.__editorPyrightCheckerDialog.start([editor.getFileName()], save=True)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
357
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
358
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
359 def installDependencies(pipInstall):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
360 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
361 Function to install dependencies of this plug-in.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
362
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
363 @param pipInstall function to be called with a list of package names.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
364 @type function
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
365 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
366 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
367 import pyright # __IGNORE_WARNING__
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
368 except ImportError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
369 pipInstall(["pyright"])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
370 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
371 import tomlkit # __IGNORE_WARNING__
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
372 except ImportError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
373 pipInstall(["tomlkit"])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
374
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
375
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
376 #
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
377 # eflag: noqa = M801

eric ide

mercurial