PluginPyright.py

Sat, 26 Oct 2024 12:03:42 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 26 Oct 2024 12:03:42 +0200
branch
eric7
changeset 17
cef8a080b1f2
parent 15
e01d64ca960f
child 19
cdde4379ce03
permissions
-rw-r--r--

Included the compiled forms into the archive.

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
11
55bc88e0aea0 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
3 # Copyright (c) 2023 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
1
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,
17
cef8a080b1f2 Included the compiled forms into the archive.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
27 "version": "10.1.2",
1
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,
17
cef8a080b1f2 Included the compiled forms into the archive.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
33 "hasCompiledForms": True,
1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
34 "pyqtApi": 2,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
35 }
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
36 # End-Of-Header
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
37
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
38 error = "" # noqa: U200
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
39
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
40
3
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
41 def exeDisplayData():
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
42 """
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
43 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
44
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
45 @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
46 the executable
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
47 @rtype dict
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
48 """
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
49 data = {
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
50 "programEntry": True,
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
51 "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
52 "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
53 ),
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
54 "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
55 "versionCommand": "--version",
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
56 "versionStartsWith": "pyright",
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
57 "versionPosition": -1,
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
58 "version": "",
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
59 "versionCleanup": None,
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
60 "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
61 }
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
62
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
63 return data
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
64
109b8e5513d8 Added the plugin function to determine the interfaced executable version information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
65
1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
66 def prepareUninstall():
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
67 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
68 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
69 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
70 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
71
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
72
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
73 class PyrightPlugin(QObject):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
74 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
75 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
76 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
77
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
78 PreferencesKey = "Pyright"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
79
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
80 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
81 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
82 Constructor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
83
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
84 @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
85 @type UI.UserInterface
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
86 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
87 super().__init__(ui)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
88 self.__ui = ui
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
89 self.__initialize()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
90
9
1ef1797f5f58 Added some forgotten code causing translations not to be loaded.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3
diff changeset
91 self.__translator = None
1ef1797f5f58 Added some forgotten code causing translations not to be loaded.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3
diff changeset
92 self.__loadTranslator()
1ef1797f5f58 Added some forgotten code causing translations not to be loaded.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3
diff changeset
93
1
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
94 def __initialize(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
95 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
96 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
97 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
98 self.__projectAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
99 self.__projectPyrightCheckerDialog = 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.__projectBrowserAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
102 self.__projectBrowserMenu = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
103 self.__projectBrowserPyrightCheckerDialog = 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 self.__editors = []
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
106 self.__editorAct = None
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
107 self.__editorPyrightCheckerDialog = None
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 def activate(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
110 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
111 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
112
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
113 @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
114 @rtype bool
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
115 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
116 global error
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
117 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
118
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
119 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
120 if menu:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
121 self.__projectAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
122 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
123 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
124 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
125 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
126 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
127 "project_check_pyright",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
128 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
129 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
130 self.__projectAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
131 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
132 """<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
133 """<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
134 )
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.__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
137 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
138 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
139
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
140 self.__editorAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
141 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
142 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
143 self.__editorAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
144 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
145 """<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
146 """<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
147 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
148 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
149 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
150
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
151 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
152 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
153 "sources"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
154 ).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
155 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
156 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
157
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
158 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
159 self.__editorOpened(editor)
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 return None, True
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 def deactivate(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
164 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
165 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
166 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
167 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
168 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
169 "sources"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
170 ).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
171
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
172 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
173 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
174 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
175 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
176
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
177 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
178 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
179
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
180 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
181 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
182 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
183 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
184 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
185
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
186 self.__initialize()
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 def __loadTranslator(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
189 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
190 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
191 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
192 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
193 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
194 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
195 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
196 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
197 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
198 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
199 translator = QTranslator(None)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
200 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
201 if loaded:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
202 self.__translator = translator
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
203 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
204 else:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
205 print(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
206 "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
207 " loaded.".format(translation)
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
208 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
209 print("Using default.")
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
210
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
211 def __projectShowMenu(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
212 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
213 menuName,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
214 menu, # noqa: U100
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 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
217 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
218 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
219
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
220 @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
221 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
222 @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
223 @type QMenu
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 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
226 self.__projectAct.setEnabled(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
227 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
228 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
229
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
230 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
231 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
232 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
233 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
234
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
235 @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
236 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
237 @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
238 @type QMenu
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 if (
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
241 menuName == "Checks"
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
242 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
243 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
244 self.__projectBrowserMenu = menu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
245 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
246 self.__projectBrowserAct = EricAction(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
247 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
248 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
249 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
250 0,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
251 self,
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
252 "",
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
253 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
254 self.__projectBrowserAct.setWhatsThis(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
255 self.tr(
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
256 """<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
257 """<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
258 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
259 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
260 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
261 self.__projectBrowserPyrightCheck
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
262 )
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
263 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
264 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
265
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
266 @pyqtSlot()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
267 def __projectPyrightCheck(self):
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 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
270 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
271 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
272
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
273 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
274 project.saveAllScripts()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
275
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
276 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
277 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
278 self.__projectPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
279 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
280
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
281 @pyqtSlot()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
282 def __projectBrowserPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
283 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
284 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
285 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
286 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
287 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
288
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
289 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
290 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
291 fn = []
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
292 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
293 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
294 else:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
295 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
296 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
297 fn = [itm.fileName()]
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
298 except AttributeError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
299 fn = [itm.dirName()]
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 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
302 self.__projectBrowserPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
303 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
304
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
305 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
306 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
307 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
308
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
309 @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
310 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
311 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
312 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
313 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
314 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
315 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
316 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
317
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
318 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
319 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
320 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
321
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
322 @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
323 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
324 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
325 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
326 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
327
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
328 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
329 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
330 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
331 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
332
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
333 @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
334 @type str
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
335 @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
336 @type QMenu
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
337 @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
338 @type QScintilla.Editor
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
339 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
340 if menuName == "Checks":
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
341 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
342 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
343 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
344
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
345 def __editorPyrightCheck(self):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
346 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
347 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
348 of the editors.
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
349 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
350 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
351
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
352 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
353 if (
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
354 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
355 and editor.checkDirty()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
356 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
357 ):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
358 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
359 self.__editorPyrightCheckerDialog.show()
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
360 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
361
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 def installDependencies(pipInstall):
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
364 """
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
365 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
366
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
367 @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
368 @type function
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
369 """
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 pyright # __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(["pyright"])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
374 try:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
375 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
376 except ImportError:
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
377 pipInstall(["tomlkit"])
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
378
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
379
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
380 #
191e9ec72893 Implemented the first iteration of the pyright typing checker interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
381 # eflag: noqa = M801

eric ide

mercurial