Tue, 09 Jul 2024 14:08:06 +0200
Fixed some issues in the Mercurial Histedit extension interface.
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10431
diff
changeset
|
3 | # Copyright (c) 2022 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing Python related utility functions. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
10 | import contextlib |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | import os |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
12 | import platform |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | import sys |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | import sysconfig |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
16 | from .OSUtilities import isWindowsPlatform |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
17 | |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | def getPythonExecutable(): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | Function to determine the path of the (non-windowed) Python executable. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | @return path of the Python executable |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | @rtype str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | """ |
10334 | 26 | if sys.platform.startswith(("linux", "freebsd")): |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | return sys.executable |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | elif sys.platform == "darwin": |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | return sys.executable.replace("pythonw", "python") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | return sys.executable.replace("pythonw.exe", "python.exe") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | def getPythonLibraryDirectory(): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | Function to determine the path to Python's library directory. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | @return path to the Python library directory |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @rtype str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | return sysconfig.get_path("platlib") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | def getPythonScriptsDirectory(): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | Function to determine the path to Python's scripts directory. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | @return path to the Python scripts directory |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | @rtype str |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | return sysconfig.get_path("scripts") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | def getPythonLibPath(): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | Function to determine the path to Python's library. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
10431
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
58 | @return path to the Python library |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
59 | @rtype str |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | return sysconfig.get_path("platstdlib") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | def getPythonVersion(): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | Function to get the Python version (major, minor) as an integer value. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | |
10431
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
68 | @return integer representing major and minor version number |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
69 | @rtype int |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | return sys.hexversion >> 16 |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | |
10834
6f5cb518cf13
Fixed some issues in the Mercurial Histedit extension interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
74 | # TODO: change this to a dummy function that always return the int value 3. |
6f5cb518cf13
Fixed some issues in the Mercurial Histedit extension interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
75 | # TODO: change eric-ide sources to not use this function anymore. |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | def determinePythonVersion(filename, source, editor=None): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | Function to determine the python version of a given file. |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | |
10431
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
80 | @param filename name of the file with extension |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
81 | @type str |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
82 | @param source of the file |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
83 | @type str |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
84 | @param editor reference to the editor, if the file is opened already |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
85 | @type Editor |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
86 | @return Python version if file is Python3 |
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10359
diff
changeset
|
87 | @rtype int |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | """ |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | from eric7 import Preferences, Utilities |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | from eric7.EricWidgets.EricApplication import ericApp |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | pyAssignment = { |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | "Python3": 3, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | "MicroPython": 3, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | "Cython": 3, |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | } |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | if not editor: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | viewManager = ericApp().getObject("ViewManager") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | editor = viewManager.getOpenEditor(filename) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | # Maybe the user has changed the language |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | if editor and editor.getFileType() in pyAssignment: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | return pyAssignment[editor.getFileType()] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | pyVer = 0 |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | if filename: |
9905
189b7a23c3c6
Changed some code to let the editor determine the highlighter language for files loaded from a connected µPy device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
108 | if not source and os.path.exists(filename): |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | source = Utilities.readEncodedFile(filename)[0] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | flags = Utilities.extractFlags(source) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | ext = os.path.splitext(filename)[1] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | py3Ext = Preferences.getPython("Python3Extensions") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | project = ericApp().getObject("Project") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | basename = os.path.basename(filename) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | if "FileType" in flags: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | pyVer = pyAssignment.get(flags["FileType"], 0) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | elif project.isOpen() and project.isProjectFile(filename): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | language = project.getEditorLexerAssoc(basename) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | if not language: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | language = Preferences.getEditorLexerAssoc(basename) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | if language == "Python3": |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | pyVer = pyAssignment[language] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | if pyVer: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | # Skip the next tests |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | pass |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | elif ( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | Preferences.getProject("DeterminePyFromProject") |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | and project.isOpen() |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | and project.isProjectFile(filename) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | and ext in py3Ext |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | ): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | pyVer = pyAssignment.get(project.getProjectLanguage(), 0) |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | elif ext in py3Ext: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | pyVer = 3 |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | elif source: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | if isinstance(source, str): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | line0 = source.splitlines()[0] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | else: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | line0 = source[0] |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | if line0.startswith("#!") and (("python3" in line0) or ("python" in line0)): |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | pyVer = 3 |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | if pyVer == 0 and ext in py3Ext: |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | pyVer = 3 |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | return pyVer |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
149 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
150 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
151 | def searchInterpreters(environments=None): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
152 | """ |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
153 | Function to determine a list of all Python interpreters available via the |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
154 | executable search path (i.e. PATH) (Windows variant). |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
155 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
156 | @param environments list of environment directories to scan for Python interpreters |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
157 | (defaults to None) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
158 | @type list of str (optional) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
159 | @return list of found interpreter executables |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
160 | @rtype list of str |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
161 | """ |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
162 | if isWindowsPlatform(): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
163 | return __searchInterpreters_Windows(environments=environments) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
164 | else: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
165 | return __searchInterpreters_Linux(environments=environments) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
166 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
167 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
168 | def __searchInterpreters_Windows(environments=None): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
169 | """ |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
170 | Function to determine a list of all Python interpreters available via the |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
171 | executable search path (i.e. PATH) (Windows variant). |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
172 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
173 | @param environments list of environment directories to scan for Python interpreters |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
174 | (defaults to None) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
175 | @type list of str (optional) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
176 | @return list of found interpreter executables |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
177 | @rtype list of str |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
178 | """ |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
179 | try: |
10359
de0420dac60e
Corrected some code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10351
diff
changeset
|
180 | import winreg # noqa: I101, I103 |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
181 | except ImportError: |
10359
de0420dac60e
Corrected some code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10351
diff
changeset
|
182 | import _winreg as winreg # noqa: I101, I102 |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
183 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
184 | def getExePath(branch, access, versionStr): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
185 | with contextlib.suppress(WindowsError, OSError): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
186 | software = winreg.OpenKey(branch, "Software", 0, access) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
187 | python = winreg.OpenKey(software, "Python", 0, access) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
188 | pcore = winreg.OpenKey(python, "PythonCore", 0, access) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
189 | version = winreg.OpenKey(pcore, versionStr, 0, access) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
190 | installpath = winreg.QueryValue(version, "InstallPath") |
10359
de0420dac60e
Corrected some code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10351
diff
changeset
|
191 | exe = os.path.join(installpath, "python.exe") |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
192 | if os.access(exe, os.X_OK): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
193 | return exe |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
194 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
195 | return None |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
196 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
197 | minorVersions = range(8, 16) # Py 3.8 until Py 3.15 |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
198 | interpreters = set() |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
199 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
200 | if environments: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
201 | for directory in [os.path.join(d, "Scripts") for d in environments]: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
202 | exe = os.path.join(directory, "python.exe") |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
203 | if os.access(exe, os.X_OK): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
204 | interpreters.add(exe) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
205 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
206 | else: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
207 | versionSuffixes = ["", "-32", "-64"] |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
208 | for minorVersion in minorVersions: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
209 | for versionSuffix in versionSuffixes: |
10359
de0420dac60e
Corrected some code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10351
diff
changeset
|
210 | versionStr = "{0}.{1}{2}".format("3", minorVersion, versionSuffix) |
10351
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
211 | exePath = getExePath( |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
212 | winreg.HKEY_CURRENT_USER, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
213 | winreg.KEY_WOW64_32KEY | winreg.KEY_READ, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
214 | versionStr, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
215 | ) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
216 | if exePath: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
217 | interpreters.add(exePath) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
218 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
219 | exePath = getExePath( |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
220 | winreg.HKEY_LOCAL_MACHINE, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
221 | winreg.KEY_WOW64_32KEY | winreg.KEY_READ, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
222 | versionStr, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
223 | ) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
224 | if exePath: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
225 | interpreters.add(exePath) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
226 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
227 | # Even on Intel 64-bit machines it's 'AMD64' |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
228 | if platform.machine() == "AMD64": |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
229 | exePath = getExePath( |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
230 | winreg.HKEY_CURRENT_USER, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
231 | winreg.KEY_WOW64_64KEY | winreg.KEY_READ, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
232 | versionStr, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
233 | ) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
234 | if exePath: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
235 | interpreters.add(exePath) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
236 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
237 | exePath = getExePath( |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
238 | winreg.HKEY_LOCAL_MACHINE, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
239 | winreg.KEY_WOW64_64KEY | winreg.KEY_READ, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
240 | versionStr, |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
241 | ) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
242 | if exePath: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
243 | interpreters.add(exePath) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
244 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
245 | return list(interpreters) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
246 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
247 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
248 | def __searchInterpreters_Linux(environments=None): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
249 | """ |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
250 | Function to determine a list of all Python interpreters available via the |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
251 | executable search path (i.e. PATH) (non Windows variant). |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
252 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
253 | @param environments list of environment directories to scan for Python interpreters |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
254 | (defaults to None) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
255 | @type list of str (optional) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
256 | @return list of found interpreter executables |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
257 | @rtype list of str |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
258 | """ |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
259 | from eric7.SystemUtilities import OSUtilities |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
260 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
261 | minorVersions = range(8, 16) # Py 3.8 until Py 3.15 |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
262 | interpreters = [] |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
263 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
264 | if environments: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
265 | directories = [os.path.join(d, "bin") for d in environments] |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
266 | else: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
267 | searchpath = OSUtilities.getEnvironmentEntry("PATH") |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
268 | directories = searchpath.split(os.pathsep) if searchpath else [] |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
269 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
270 | if directories: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
271 | pythonNames = ["python3.{0}".format(v) for v in minorVersions] |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
272 | for directory in directories: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
273 | for interpreter in pythonNames: |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
274 | exe = os.path.join(directory, interpreter) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
275 | if os.access(exe, os.X_OK): |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
276 | interpreters.append(exe) |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
277 | |
1f9bafeff96c
Virtual Environments
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10334
diff
changeset
|
278 | return interpreters |