Sun, 21 Jan 2018 14:37:36 +0100
Improved executable and Python version determination and merged with remote changes.
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
68
35b46e640d6d
Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
64
diff
changeset
|
3 | # Copyright (c) 2007 - 2018 Detlev Offenbach <detlev@die-offenbachs.de> |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the PyLint plug-in. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
32
b0a6368042b9
python2Compatible flag added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
31
diff
changeset
|
10 | from __future__ import unicode_literals |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
11 | try: |
32
b0a6368042b9
python2Compatible flag added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
31
diff
changeset
|
12 | str = unicode |
b0a6368042b9
python2Compatible flag added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
31
diff
changeset
|
13 | except NameError: |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
14 | pass |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
15 | |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
16 | import re |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | import os |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | import copy |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
19 | import platform |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
21 | from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QProcess |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
22 | from PyQt5.QtWidgets import QDialog |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
24 | from E5Gui.E5Application import e5App |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
25 | from E5Gui.E5Action import E5Action |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
26 | from E5Gui import E5MessageBox |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | |
31
d8e6de5a0cb7
Adjusted the plug-in to latest eric5 versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
30
diff
changeset
|
28 | from Project.ProjectBrowserModel import ProjectBrowserFileItem |
d8e6de5a0cb7
Adjusted the plug-in to latest eric5 versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
30
diff
changeset
|
29 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
30 | import Preferences |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | import Utilities |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | # Start-of-Header |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | name = "PyLint Plugin" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | autoactivate = True |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | deactivateable = True |
72
d864ddf21044
Improved executable and Python version determination and merged with remote changes.
Detlev Offenbach <detlev@die-offenbachs.de>
diff
changeset
|
38 | version = "6.1.9" |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | className = "PyLintPlugin" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | packageName = "PyLint" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | shortDescription = "Show the PyLint dialogs." |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | longDescription = """This plug-in implements the PyLint dialogs.""" \ |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
43 | """ PyLint is used to check Python source files according to various""" \ |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
44 | """ rules.""" |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | needsRestart = False |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | pyqtApi = 2 |
32
b0a6368042b9
python2Compatible flag added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
31
diff
changeset
|
47 | python2Compatible = True |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | # End-of-Header |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
50 | error = "" |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
51 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
52 | exePy2 = [] |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
53 | exePy3 = [] |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
55 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
56 | def exeDisplayDataList(): |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | Public method to support the display of some executable info. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | @return dictionary containing the data to query the presence of |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | the executable |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | """ |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
63 | dataList = [] |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | data = { |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | "programEntry": True, |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
66 | "header": QCoreApplication.translate( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
67 | "PyLintPlugin", "Checkers - Pylint"), |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | "exe": 'dummypylint', |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | "versionCommand": '--version', |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | "versionStartsWith": 'dummypylint', |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | "versionPosition": -1, |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | "version": "", |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | "versionCleanup": (0, -1), |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | } |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
75 | if _checkProgram(): |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
76 | for exePath in (exePy2[0], exePy3[0]): |
35
c3ca6d580760
Fixed an issue reporting the pylint versions installed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
32
diff
changeset
|
77 | if exePath: |
c3ca6d580760
Fixed an issue reporting the pylint versions installed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
32
diff
changeset
|
78 | data["exe"] = exePath |
c3ca6d580760
Fixed an issue reporting the pylint versions installed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
32
diff
changeset
|
79 | data["versionStartsWith"] = "pylint" |
c3ca6d580760
Fixed an issue reporting the pylint versions installed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
32
diff
changeset
|
80 | dataList.append(data.copy()) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
81 | else: |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
82 | dataList.append(data) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
83 | return dataList |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
84 | |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
85 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
86 | def __getProgramVersion(exe): |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
87 | """ |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
88 | Private method to generate a program entry. |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
90 | @param exe name of the executable program (string) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
91 | @return version string of detected version (string) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
92 | """ |
52
2ffa0ba6917c
Fixed a little issue in the __getProgramVersion() function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
50
diff
changeset
|
93 | version = '0.0.0' |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
94 | proc = QProcess() |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
95 | proc.setProcessChannelMode(QProcess.MergedChannels) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
96 | proc.start(exe, ['--version']) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
97 | finished = proc.waitForFinished(10000) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
98 | if finished: |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
99 | output = str(proc.readAllStandardOutput(), |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
100 | Preferences.getSystem("IOEncoding"), |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
101 | 'replace') |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
102 | versionRe = re.compile('^pylint', re.UNICODE) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
103 | for line in output.splitlines(): |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
104 | if versionRe.search(line): |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
105 | version = line.split()[-1] |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
106 | version = version[:-1] |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
107 | break |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
108 | return version |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
110 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
111 | def _findExecutable(majorVersion): |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | Restricted function to determine the name and path of the executable. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
115 | @param majorVersion major python version of the executables (int) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | @return path name of the executable (string) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | """ |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
118 | # Determine Python Version |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
119 | if majorVersion == 3: |
64
7c2867ac2ee8
Fixed an issue preventing the activation of the plug-in with Python 3 >= 3.5.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
62
diff
changeset
|
120 | minorVersions = range(10) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
121 | elif majorVersion == 2: |
64
7c2867ac2ee8
Fixed an issue preventing the activation of the plug-in with Python 3 >= 3.5.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
62
diff
changeset
|
122 | minorVersions = range(6, 8) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
123 | else: |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
124 | return [] |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
125 | |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
126 | executables = set() |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | if Utilities.isWindowsPlatform(): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | # |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | # Windows |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | # |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | try: |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
132 | import winreg |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | except ImportError: |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
134 | import _winreg as winreg # __IGNORE_WARNING__ |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
135 | |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
136 | def getExePath(branch, access, versionStr): |
46
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
137 | exes = [] |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | try: |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
139 | software = winreg.OpenKey(branch, 'Software', 0, access) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
140 | python = winreg.OpenKey(software, 'Python', 0, access) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
141 | pcore = winreg.OpenKey(python, 'PythonCore', 0, access) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
142 | version = winreg.OpenKey(pcore, versionStr, 0, access) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
143 | installpath = winreg.QueryValue(version, 'InstallPath') |
46
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
144 | # Look for the batch script variant |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
145 | exe = os.path.join(installpath, 'Scripts', 'pylint.bat') |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
146 | if os.access(exe, os.X_OK): |
46
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
147 | exes.append(exe) |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
148 | # Look for the executable variant |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
149 | exe = os.path.join(installpath, 'Scripts', 'pylint.exe') |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
150 | if os.access(exe, os.X_OK): |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
151 | exes.append(exe) |
48
69c4c0e04bf6
Fixed a bug in the plug-in script.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
46
diff
changeset
|
152 | except (WindowsError, OSError): # __IGNORE_WARNING__ |
46
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
153 | pass |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
154 | return exes |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
155 | |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
156 | versionSuffixes = ["", "-32", "-64"] |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
157 | for minorVersion in minorVersions: |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
158 | for versionSuffix in versionSuffixes: |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
159 | versionStr = '{0}.{1}{2}'.format(majorVersion, minorVersion, |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
160 | versionSuffix) |
46
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
161 | exePaths = getExePath( |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
162 | winreg.HKEY_CURRENT_USER, |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
163 | winreg.KEY_WOW64_32KEY | winreg.KEY_READ, versionStr) |
46
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
164 | if exePaths: |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
165 | for exePath in exePaths: |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
166 | executables.add(exePath) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
167 | |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
168 | exePaths = getExePath( |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
169 | winreg.HKEY_LOCAL_MACHINE, |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
170 | winreg.KEY_WOW64_32KEY | winreg.KEY_READ, versionStr) |
46
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
171 | if exePaths: |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
172 | for exePath in exePaths: |
a781953e3703
Compatibility to newer pylint versions for Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
44
diff
changeset
|
173 | executables.add(exePath) |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
174 | |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
175 | # Even on Intel 64-bit machines it's 'AMD64' |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
176 | if platform.machine() == 'AMD64': |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
177 | exePaths = getExePath( |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
178 | winreg.HKEY_CURRENT_USER, |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
179 | winreg.KEY_WOW64_64KEY | winreg.KEY_READ, versionStr) |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
180 | if exePaths: |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
181 | for exePath in exePaths: |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
182 | executables.add(exePath) |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
183 | |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
184 | exePath = getExePath( |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
185 | winreg.HKEY_LOCAL_MACHINE, |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
186 | winreg.KEY_WOW64_64KEY | winreg.KEY_READ, versionStr) |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
187 | if exePaths: |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
188 | for exePath in exePaths: |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
189 | executables.add(exePath) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | else: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | # |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | # Linux, Unix ... |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | pylintScript = 'pylint' |
8
b126b60ac32a
Enhanced the algorithm to determine the pylint executable on non-Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7
diff
changeset
|
194 | scriptSuffixes = ["", |
66
0ed7d5364b48
Extended the executable search algorithm to handle more Linux distribution variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
64
diff
changeset
|
195 | "-python{0}".format(majorVersion), |
0ed7d5364b48
Extended the executable search algorithm to handle more Linux distribution variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
64
diff
changeset
|
196 | "{0}".format(majorVersion),] |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
197 | for minorVersion in minorVersions: |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
198 | scriptSuffixes.append( |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
199 | "-python{0}.{1}".format(majorVersion, minorVersion)) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | # There could be multiple pylint executables in the path |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | # e.g. for different python variants |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | path = Utilities.getEnvironmentEntry('PATH') |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | # environment variable not defined |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | if path is None: |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
205 | return [] |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | # step 1: determine possible candidates |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | exes = [] |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | dirs = path.split(os.pathsep) |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
210 | for directory in dirs: |
8
b126b60ac32a
Enhanced the algorithm to determine the pylint executable on non-Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7
diff
changeset
|
211 | for suffix in scriptSuffixes: |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
212 | exe = os.path.join(directory, pylintScript + suffix) |
8
b126b60ac32a
Enhanced the algorithm to determine the pylint executable on non-Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7
diff
changeset
|
213 | if os.access(exe, os.X_OK): |
b126b60ac32a
Enhanced the algorithm to determine the pylint executable on non-Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7
diff
changeset
|
214 | exes.append(exe) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
216 | # step 2: determine the Python variant |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
217 | _exePy2 = set() |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
218 | _exePy3 = set() |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
219 | versionArgs = ["-c", "import sys; print(sys.version_info[0])"] |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | for exe in exes: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | try: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | f = open(exe, "r") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | line0 = f.readline() |
69
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
224 | program = line0.replace("#!", "").strip() |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
225 | process = QProcess() |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
226 | process.start(program, versionArgs) |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
227 | process.waitForFinished(5000) |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
228 | # get a QByteArray of the output |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
229 | versionBytes = process.readAllStandardOutput() |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
230 | versionStr = str(versionBytes, encoding='utf-8').strip() |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
231 | if versionStr == "3": |
2de720476713
Improved executable and Python version determination.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
68
diff
changeset
|
232 | _exePy3.add(exe) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
233 | else: |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
234 | _exePy2.add(exe) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | finally: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | f.close() |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
237 | |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
238 | executables = _exePy3 if majorVersion == 3 else _exePy2 |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
240 | # Find the executable with the highest version number |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
241 | maxVersion = '0.0.0' |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
242 | maxExe = '' |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
243 | for executable in list(executables): |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
244 | version = __getProgramVersion(executable) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
245 | if version > maxVersion: |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
246 | maxVersion = version |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
247 | maxExe = executable |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
249 | return maxExe, maxVersion |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
251 | |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | def _checkProgram(): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | Restricted function to check the availability of pylint. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | @return flag indicating availability (boolean) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | """ |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
258 | global error, exePy2, exePy3 |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
260 | exePy2 = _findExecutable(2) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
261 | exePy3 = _findExecutable(3) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
262 | if exePy2[0] == '' and exePy3[0] == '': |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
263 | error = QCoreApplication.translate( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
264 | "PyLintPlugin", "The pylint executable could not be found.") |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | return False |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
266 | elif exePy2[1] < '0.23.0' and exePy3[1] < '0.23.0': |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
267 | error = QCoreApplication.translate( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
268 | "PyLintPlugin", "PyLint version < 0.23.0.") |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
269 | return False |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | else: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | return True |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | class PyLintPlugin(QObject): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | Class implementing the PyLint plug-in. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | def __init__(self, ui): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | Constructor |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | @param ui reference to the user interface object (UI.UserInterface) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | QObject.__init__(self, ui) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | self.__ui = ui |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | self.__initialize() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | self.__translator = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | self.__loadTranslator() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | def __initialize(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | Private slot to (re)initialize the plugin. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | self.__projectAct = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | self.__projectShowAct = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | self.__pylintPDialog = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | self.__projectBrowserAct = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | self.__projectBrowserShowAct = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | self.__projectBrowserMenu = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | self.__pylintPsbDialog = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | self.__editors = [] |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | self.__editorAct = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | self.__editorPylintDialog = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | self.__editorParms = None |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | def activate(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | Public method to activate this plugin. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | @return tuple of None and activation status (boolean) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | global error |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
317 | # There is already an error, don't activate |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
318 | if error: |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
319 | return None, False |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | # pylint is only activated if it is available |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | if not _checkProgram(): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | return None, False |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | menu = e5App().getObject("Project").getMenu("Checks") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | if menu: |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
326 | self.__projectAct = E5Action( |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
327 | self.tr('Run PyLint'), |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
328 | self.tr('Run &PyLint...'), 0, 0, |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
329 | self, 'project_check_pylint') |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | self.__projectAct.setStatusTip( |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
331 | self.tr('Check project, packages or modules with pylint.')) |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
332 | self.__projectAct.setWhatsThis(self.tr( |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | """<b>Run PyLint...</b>""" |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
334 | """<p>This checks the project, packages or modules using""" |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
335 | """ pylint.</p>""" |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | )) |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
337 | self.__projectAct.triggered.connect(self.__projectPylint) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | e5App().getObject("Project").addE5Actions([self.__projectAct]) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | menu.addAction(self.__projectAct) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
341 | self.__projectShowAct = E5Action( |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
342 | self.tr('Show PyLint Dialog'), |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
343 | self.tr('Show Py&Lint Dialog...'), 0, 0, |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
344 | self, 'project_check_pylintshow') |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
345 | self.__projectShowAct.setStatusTip(self.tr( |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
346 | 'Show the PyLint dialog with the results of the last run.')) |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
347 | self.__projectShowAct.setWhatsThis(self.tr( |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | """<b>Show PyLint Dialog...</b>""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | """<p>This shows the PyLint dialog with the results""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | """ of the last run.</p>""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | )) |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
352 | self.__projectShowAct.triggered.connect( |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
353 | self.__projectPylintShow) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | e5App().getObject("Project").addE5Actions([self.__projectShowAct]) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | menu.addAction(self.__projectShowAct) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
357 | self.__editorAct = E5Action( |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
358 | self.tr('Run PyLint'), |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
359 | self.tr('Run &PyLint...'), 0, 0, |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
360 | self, "") |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
361 | self.__editorAct.setWhatsThis(self.tr( |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
362 | """<b>Run PyLint...</b>""" |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
363 | """<p>This checks the loaded module using pylint.</p>""" |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
364 | )) |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
365 | self.__editorAct.triggered.connect(self.__editorPylint) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
366 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
368 | e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | .showMenu.connect(self.__projectBrowserShowMenu) |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
370 | e5App().getObject("ViewManager").editorOpenedEd.connect( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
371 | self.__editorOpened) |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
372 | e5App().getObject("ViewManager").editorClosedEd.connect( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
373 | self.__editorClosed) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | for editor in e5App().getObject("ViewManager").getOpenEditors(): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | self.__editorOpened(editor) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | error = "" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | return None, True |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | def deactivate(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | Public method to deactivate this plugin. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | """ |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
385 | e5App().getObject("Project").showMenu.disconnect( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
386 | self.__projectShowMenu) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | .showMenu.disconnect(self.__projectBrowserShowMenu) |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
389 | e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
390 | self.__editorOpened) |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
391 | e5App().getObject("ViewManager").editorClosedEd.disconnect( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
392 | self.__editorClosed) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | menu = e5App().getObject("Project").getMenu("Checks") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | if menu: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | if self.__projectAct: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | menu.removeAction(self.__projectAct) |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
398 | e5App().getObject("Project").removeE5Actions( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
399 | [self.__projectAct]) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | if self.__projectShowAct: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
401 | menu.removeAction(self.__projectShowAct) |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
402 | e5App().getObject("Project").removeE5Actions( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
403 | [self.__projectShowAct]) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | if self.__projectBrowserMenu: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | if self.__projectBrowserAct: |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
407 | self.__projectBrowserMenu.removeAction( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
408 | self.__projectBrowserAct) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | if self.__projectBrowserShowAct: |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
410 | self.__projectBrowserMenu.removeAction( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
411 | self.__projectBrowserShowAct) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | for editor in self.__editors: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | editor.showMenu.disconnect(self.__editorShowMenu) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | menu = editor.getMenu("Checks") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | if menu is not None: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
417 | menu.removeAction(self.__editorAct) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
418 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
419 | self.__initialize() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | def __loadTranslator(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | Private method to load the translation file. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | if self.__ui is not None: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | loc = self.__ui.getLocale() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | if loc and loc != "C": |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
428 | locale_dir = \ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | os.path.join(os.path.dirname(__file__), "PyLint", "i18n") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | translation = "pylint_{0}".format(loc) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | translator = QTranslator(None) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | loaded = translator.load(translation, locale_dir) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | if loaded: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | self.__translator = translator |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | e5App().installTranslator(self.__translator) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | else: |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
437 | print("Warning: translation file '{0}' could not be" |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
438 | " loaded.".format(translation)) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | print("Using default.") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
441 | def __projectShowMenu(self, menuName, menu): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | Private slot called, when the the project menu or a submenu is |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | about to be shown. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | @param menuName name of the menu to be shown (string) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | @param menu reference to the menu (QMenu) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | if menuName == "Checks": |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
450 | lang = e5App().getObject("Project").getProjectLanguage() |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | if self.__projectAct is not None: |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
452 | self.__projectAct.setEnabled(lang.startswith("Python")) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | if self.__projectShowAct is not None: |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
454 | self.__projectShowAct.setEnabled(lang.startswith("Python")) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
455 | self.__projectShowAct.setEnabled(self.__pylintPDialog is not None) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
457 | def __projectBrowserShowMenu(self, menuName, menu): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
458 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
459 | Private slot called, when the the project browser menu or a submenu is |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | about to be shown. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | @param menuName name of the menu to be shown (string) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
463 | @param menu reference to the menu (QMenu) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
464 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | if menuName == "Checks" and \ |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
466 | e5App().getObject("Project").getProjectLanguage()\ |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
467 | .startswith("Python"): |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | self.__projectBrowserMenu = menu |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | if self.__projectBrowserAct is None: |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
470 | self.__projectBrowserAct = E5Action( |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
471 | self.tr('Run PyLint'), |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
472 | self.tr('Run &PyLint...'), 0, 0, |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
473 | self, '') |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
474 | self.__projectBrowserAct.setWhatsThis(self.tr( |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
475 | """<b>Run PyLint...</b>""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
476 | """<p>This checks the project, packages or modules""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
477 | """ using pylint.</p>""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
478 | )) |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
479 | self.__projectBrowserAct.triggered.connect( |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
480 | self.__projectBrowserPylint) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
482 | if self.__projectBrowserShowAct is None: |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
483 | self.__projectBrowserShowAct = E5Action( |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
484 | self.tr('Show PyLint Dialog'), |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
485 | self.tr('Show Py&Lint Dialog...'), 0, 0, |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
486 | self, '') |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
487 | self.__projectBrowserShowAct.setWhatsThis(self.tr( |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | """<b>Show PyLint Dialog...</b>""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
489 | """<p>This shows the PyLint dialog with the results""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | """ of the last run.</p>""" |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | )) |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
492 | self.__projectBrowserShowAct.triggered.connect( |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
493 | self.__projectBrowserPylintShow) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
495 | if self.__projectBrowserAct not in menu.actions(): |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | menu.addAction(self.__projectBrowserAct) |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
497 | if self.__projectBrowserShowAct not in menu.actions(): |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
498 | menu.addAction(self.__projectBrowserShowAct) |
31
d8e6de5a0cb7
Adjusted the plug-in to latest eric5 versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
30
diff
changeset
|
499 | |
d8e6de5a0cb7
Adjusted the plug-in to latest eric5 versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
30
diff
changeset
|
500 | enable = e5App().getObject("ProjectBrowser")\ |
d8e6de5a0cb7
Adjusted the plug-in to latest eric5 versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
30
diff
changeset
|
501 | .getProjectBrowser("sources")\ |
d8e6de5a0cb7
Adjusted the plug-in to latest eric5 versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
30
diff
changeset
|
502 | .getSelectedItemsCount([ProjectBrowserFileItem]) == 1 |
d8e6de5a0cb7
Adjusted the plug-in to latest eric5 versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
30
diff
changeset
|
503 | self.__projectBrowserAct.setEnabled(enable) |
32
b0a6368042b9
python2Compatible flag added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
31
diff
changeset
|
504 | self.__projectBrowserShowAct.setEnabled( |
b0a6368042b9
python2Compatible flag added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
31
diff
changeset
|
505 | enable and self.__pylintPsbDialog is not None) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
506 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | def __pyLint(self, project, mpName, forProject, forEditor=False): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | Private method used to perform a PyLint run. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
510 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | @param project reference to the Project object |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
512 | @param mpName name of module or package to be checked (string) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
513 | @param forProject flag indicating a run for the project (boolean) |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
514 | @param forEditor flag indicating a run for an editor (boolean) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
515 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
516 | if forEditor: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
517 | parms = copy.deepcopy(self.__editorParms) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
518 | editor = e5App().getObject("ViewManager").getOpenEditor(mpName) |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
519 | majorVersionStr = editor.getLanguage() |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
520 | else: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
521 | parms = project.getData('CHECKERSPARMS', "PYLINT") |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
522 | majorVersionStr = project.getProjectLanguage() |
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
523 | exe, version = {"Python": exePy2, "Python2": exePy2, |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
524 | "Python3": exePy3}.get(majorVersionStr) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
525 | if exe == '': |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
526 | E5MessageBox.critical( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
527 | None, |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
528 | self.tr("pylint"), |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
529 | self.tr("""The pylint executable could not be found.""")) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
530 | return |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
531 | elif version < '0.23.0': |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
532 | E5MessageBox.critical( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
533 | None, |
38
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
534 | self.tr("pylint"), |
bf234b8941d9
Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
35
diff
changeset
|
535 | self.tr("PyLint version < 0.23.0.")) |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
536 | return |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
537 | |
18
ae62d56e345d
Modified the code to do lazy import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
16
diff
changeset
|
538 | from PyLint.PyLintConfigDialog import PyLintConfigDialog |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
539 | dlg = PyLintConfigDialog(project.getProjectPath(), exe, parms, version) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | if dlg.exec_() == QDialog.Accepted: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
541 | args, parms = dlg.generateParameters() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | self.__editorParms = copy.deepcopy(parms) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
543 | if not forEditor: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
544 | project.setData('CHECKERSPARMS', "PYLINT", parms) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
545 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
546 | # now do the call |
18
ae62d56e345d
Modified the code to do lazy import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
16
diff
changeset
|
547 | from PyLint.PyLintExecDialog import PyLintExecDialog |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
548 | dlg2 = PyLintExecDialog() |
22
68beeb22dade
Py2 compatibility, pylint script based on project language.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
20
diff
changeset
|
549 | reportFile = parms.get('reportFile', None) |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
550 | res = dlg2.start(args, mpName, reportFile, |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
551 | project.getProjectPath()) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
552 | if res: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
553 | dlg2.show() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
554 | if forProject: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
555 | self.__pylintPDialog = dlg2 |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
556 | elif forEditor: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
557 | self.__editorPylintDialog = dlg2 |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
558 | else: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
559 | self.__pylintPsbDialog = dlg2 |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
560 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
561 | def __projectPylint(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
562 | """ |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
563 | Private slot used to check the project files with Pylint. |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
564 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
565 | project = e5App().getObject("Project") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
566 | project.saveAllScripts() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
567 | self.__pyLint(project, project.getProjectPath(), True) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
568 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
569 | def __projectPylintShow(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | """ |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
571 | Private slot to show the PyLint dialog with the results of the last |
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
572 | run. |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
573 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
574 | if self.__pylintPDialog is not None: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
575 | self.__pylintPDialog.show() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
576 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
577 | def __projectBrowserPylint(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
578 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
579 | Private method to handle the Pylint context menu action of the project |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
580 | sources browser. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
581 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
582 | project = e5App().getObject("Project") |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
583 | browser = e5App().getObject("ProjectBrowser")\ |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
584 | .getProjectBrowser("sources") |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | itm = browser.model().item(browser.currentIndex()) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
586 | try: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
587 | fn = itm.fileName() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
588 | except AttributeError: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
589 | fn = itm.dirName() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
590 | self.__pyLint(project, fn, False) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
591 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
592 | def __projectBrowserPylintShow(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
593 | """ |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
594 | Private slot to show the PyLint dialog with the results of the last |
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
595 | run. |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
596 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
597 | if self.__pylintPsbDialog is not None: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
598 | self.__pylintPsbDialog.show() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
599 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
600 | def __editorOpened(self, editor): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
601 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
602 | Private slot called, when a new editor was opened. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
603 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
604 | @param editor reference to the new editor (QScintilla.Editor) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
605 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
606 | menu = editor.getMenu("Checks") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
607 | if menu is not None: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
608 | menu.addAction(self.__editorAct) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
609 | editor.showMenu.connect(self.__editorShowMenu) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
610 | self.__editors.append(editor) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
611 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
612 | def __editorClosed(self, editor): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
613 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
614 | Private slot called, when an editor was closed. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
615 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
616 | @param editor reference to the editor (QScintilla.Editor) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
617 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
618 | try: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
619 | self.__editors.remove(editor) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
620 | except ValueError: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
621 | pass |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
622 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
623 | def __editorShowMenu(self, menuName, menu, editor): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
624 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
625 | Private slot called, when the the editor context menu or a submenu is |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
626 | about to be shown. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
627 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
628 | @param menuName name of the menu to be shown (string) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
629 | @param menu reference to the menu (QMenu) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
630 | @param editor reference to the editor (QScintilla.Editor) |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
631 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
632 | if menuName == "Checks": |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
633 | if self.__editorAct not in menu.actions(): |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
634 | menu.addAction(self.__editorAct) |
28
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
635 | self.__editorAct.setEnabled( |
1dae294006e8
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
24
diff
changeset
|
636 | editor.isPy3File() or editor.isPy2File()) |
0
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
637 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
638 | def __editorPylint(self): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
639 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
640 | Private slot to handle the Pylint context menu action of the editors. |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
641 | """ |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
642 | editor = e5App().getObject("ViewManager").activeWindow() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
643 | if editor is not None: |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
644 | if not editor.checkDirty(): |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
645 | return |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
646 | |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
647 | fn = editor.getFileName() |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
648 | project = e5App().getObject("Project") |
1c1ac27f3cf1
Added first set of sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
649 | self.__pyLint(project, fn, False, True) |
60
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
650 | |
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
651 | # |
971dd1b69f5b
Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
59
diff
changeset
|
652 | # eflag: noqa = M801 |