35 @signal virtualEnvironmentsListChanged() emitted to indicate a change of |
35 @signal virtualEnvironmentsListChanged() emitted to indicate a change of |
36 the list of virtual environments (may be used to refresh the list) |
36 the list of virtual environments (may be used to refresh the list) |
37 """ |
37 """ |
38 |
38 |
39 DefaultKey = "<default>" |
39 DefaultKey = "<default>" |
|
40 SystemKey = "<system>" |
40 |
41 |
41 virtualEnvironmentAdded = pyqtSignal() |
42 virtualEnvironmentAdded = pyqtSignal() |
42 virtualEnvironmentRemoved = pyqtSignal() |
43 virtualEnvironmentRemoved = pyqtSignal() |
43 virtualEnvironmentChanged = pyqtSignal(str) |
44 virtualEnvironmentChanged = pyqtSignal(str) |
44 |
45 |
109 defaultPy = Globals.getPythonExecutable() |
110 defaultPy = Globals.getPythonExecutable() |
110 if "{0}.venv{0}".format(os.sep) not in defaultPy: |
111 if "{0}.venv{0}".format(os.sep) not in defaultPy: |
111 # only check for a non-embedded environment |
112 # only check for a non-embedded environment |
112 found = False |
113 found = False |
113 for venvName in self.__virtualEnvironments: |
114 for venvName in self.__virtualEnvironments: |
114 if defaultPy == self.__virtualEnvironments[venvName]["interpreter"]: |
115 if os.path.samefile( |
|
116 defaultPy, self.__virtualEnvironments[venvName]["interpreter"] |
|
117 ): |
115 found = True |
118 found = True |
116 break |
119 break |
117 if not found: |
120 if not found: |
118 # add an environment entry for the default interpreter |
121 # add an environment entry for the default interpreter |
119 self.__virtualEnvironments[VirtualenvManager.DefaultKey] = { |
122 self.__virtualEnvironments[VirtualenvManager.DefaultKey] = { |
181 containing a copy of the default virtual environment |
184 containing a copy of the default virtual environment |
182 @rtype tuple of (str, dict) |
185 @rtype tuple of (str, dict) |
183 """ |
186 """ |
184 py = interpreter.replace("w.exe", ".exe") |
187 py = interpreter.replace("w.exe", ".exe") |
185 for venvName in self.__virtualEnvironments: |
188 for venvName in self.__virtualEnvironments: |
186 if py == self.__virtualEnvironments[venvName]["interpreter"]: |
189 if os.path.samefile( |
|
190 py, self.__virtualEnvironments[venvName]["interpreter"] |
|
191 ): |
187 return (venvName, copy.copy(self.__virtualEnvironments[venvName])) |
192 return (venvName, copy.copy(self.__virtualEnvironments[venvName])) |
|
193 |
|
194 if os.path.samefile(interpreter, sys.executable): |
|
195 return (VirtualenvManager.SystemKey, {}) |
188 |
196 |
189 return ("", {}) |
197 return ("", {}) |
190 |
198 |
191 @pyqtSlot() |
199 @pyqtSlot() |
192 def createVirtualEnv(self, baseDir=""): |
200 def createVirtualEnv(self, baseDir=""): |
603 """ |
611 """ |
604 if venvName in self.__virtualEnvironments: |
612 if venvName in self.__virtualEnvironments: |
605 return self.__virtualEnvironments[venvName]["interpreter"].replace( |
613 return self.__virtualEnvironments[venvName]["interpreter"].replace( |
606 "w.exe", ".exe" |
614 "w.exe", ".exe" |
607 ) |
615 ) |
|
616 elif venvName == VirtualenvManager.SystemKey: |
|
617 return sys.executable |
608 else: |
618 else: |
609 return "" |
619 return "" |
610 |
620 |
611 def setVirtualEnvInterpreter(self, venvName, venvInterpreter): |
621 def setVirtualEnvInterpreter(self, venvName, venvInterpreter): |
612 """ |
622 """ |