192 else: |
193 else: |
193 # It is a local environment; check it is still valid. |
194 # It is a local environment; check it is still valid. |
194 if not os.path.exists(venvPath): |
195 if not os.path.exists(venvPath): |
195 del self.__virtualEnvironments[venvName] |
196 del self.__virtualEnvironments[venvName] |
196 removed = True |
197 removed = True |
|
198 |
197 if removed: |
199 if removed: |
198 self.__saveSettings() |
|
199 self.virtualEnvironmentRemoved.emit() |
200 self.virtualEnvironmentRemoved.emit() |
|
201 self.virtualEnvironmentsListChanged.emit() |
|
202 |
|
203 def __checkEnvironmentInterpretersExist(self): |
|
204 """ |
|
205 Private method to set all environments with non-existent interpreters to |
|
206 the disabled state. |
|
207 """ |
|
208 changed = False |
|
209 |
|
210 for venvName in self.__virtualEnvironments: |
|
211 venvItem = self.__virtualEnvironments[venvName] |
|
212 if venvItem.environment_type != "remote": |
|
213 venvInterpreter = venvItem.interpreter |
|
214 if venvInterpreter: |
|
215 if venvItem.environment_type == "eric_server": |
|
216 with contextlib.suppress(KeyError): |
|
217 # It is an eric-ide server environment; check it has |
|
218 # an existing interpreter. |
|
219 ericServer = ericApp().getObject("EricServer") |
|
220 if ( |
|
221 ericServer.isServerConnected() |
|
222 and ericServer.getHost() == venvItem.eric_server |
|
223 and not ericServer.getServiceInterface( |
|
224 "FileSystem" |
|
225 ).exists(venvInterpreter) |
|
226 ): |
|
227 venvItem.available = False |
|
228 changed = True |
|
229 else: |
|
230 # It is a local environment; check it has an existing |
|
231 # interpreter. |
|
232 if not os.path.exists(venvInterpreter): |
|
233 venvItem.available = False |
|
234 changed = True |
|
235 else: |
|
236 # no interpreter defined |
|
237 venvItem.available = False |
|
238 changed = True |
|
239 |
|
240 if changed: |
200 self.virtualEnvironmentsListChanged.emit() |
241 self.virtualEnvironmentsListChanged.emit() |
201 |
242 |
202 def getDefaultEnvironment(self): |
243 def getDefaultEnvironment(self): |
203 """ |
244 """ |
204 Public method to get the default virtual environment. |
245 Public method to get the default virtual environment. |
230 of the virtual environment the interpreter belongs to |
271 of the virtual environment the interpreter belongs to |
231 @rtype tuple of (str, VirtualenvMetaData) |
272 @rtype tuple of (str, VirtualenvMetaData) |
232 """ |
273 """ |
233 py = FileSystemUtilities.normcaseabspath(interpreter.replace("w.exe", ".exe")) |
274 py = FileSystemUtilities.normcaseabspath(interpreter.replace("w.exe", ".exe")) |
234 for venvName in self.__virtualEnvironments: |
275 for venvName in self.__virtualEnvironments: |
235 if py == FileSystemUtilities.normcaseabspath( |
276 if ( |
236 self.__virtualEnvironments[venvName].interpreter |
277 py |
|
278 == FileSystemUtilities.normcaseabspath( |
|
279 self.__virtualEnvironments[venvName].interpreter |
|
280 ) |
|
281 and self.__virtualEnvironments[venvName].available |
237 ): |
282 ): |
238 return (venvName, copy.copy(self.__virtualEnvironments[venvName])) |
283 return (venvName, copy.copy(self.__virtualEnvironments[venvName])) |
239 |
284 |
240 if os.path.samefile(interpreter, sys.executable): |
285 if os.path.samefile(interpreter, sys.executable): |
241 return (VirtualenvManager.SystemKey, {}) |
286 return (VirtualenvManager.SystemKey, {}) |
604 @param venvName logical name for the virtual environment |
649 @param venvName logical name for the virtual environment |
605 @type str |
650 @type str |
606 @return interpreter path |
651 @return interpreter path |
607 @rtype str |
652 @rtype str |
608 """ |
653 """ |
609 if venvName in self.__virtualEnvironments: |
654 if ( |
|
655 venvName in self.__virtualEnvironments |
|
656 and self.__virtualEnvironments[venvName].available |
|
657 ): |
610 return self.__virtualEnvironments[venvName].interpreter.replace( |
658 return self.__virtualEnvironments[venvName].interpreter.replace( |
611 "w.exe", ".exe" |
659 "w.exe", ".exe" |
612 ) |
660 ) |
613 elif venvName == VirtualenvManager.SystemKey: |
661 elif venvName == VirtualenvManager.SystemKey: |
614 return sys.executable.replace("w.exe", ".exe") |
662 return sys.executable.replace("w.exe", ".exe") |
624 @param venvInterpreter interpreter path to be set |
672 @param venvInterpreter interpreter path to be set |
625 @type str |
673 @type str |
626 """ |
674 """ |
627 if venvName in self.__virtualEnvironments: |
675 if venvName in self.__virtualEnvironments: |
628 self.__virtualEnvironments[venvName].interpreter = venvInterpreter |
676 self.__virtualEnvironments[venvName].interpreter = venvInterpreter |
|
677 self.__virtualEnvironments[venvName].available = os.path.exists( |
|
678 venvInterpreter |
|
679 ) |
629 self.__saveSettings() |
680 self.__saveSettings() |
630 |
681 |
631 self.virtualEnvironmentChanged.emit(venvName) |
682 self.virtualEnvironmentChanged.emit(venvName) |
632 self.virtualEnvironmentsListChanged.emit() |
683 self.virtualEnvironmentsListChanged.emit() |
633 |
684 |
657 ("all",) ) |
708 ("all",) ) |
658 @type tuple of str ((optional) |
709 @type tuple of str ((optional) |
659 @return list of defined virtual environments |
710 @return list of defined virtual environments |
660 @rtype list of str |
711 @rtype list of str |
661 """ |
712 """ |
662 environments = list(self.__virtualEnvironments) |
713 environments = [ |
|
714 name |
|
715 for name in self.__virtualEnvironments |
|
716 if self.isAvailableEnvironment(name) |
|
717 ] |
663 if noGlobals: |
718 if noGlobals: |
664 environments = [ |
719 environments = [ |
665 name for name in environments if not self.isGlobalEnvironment(name) |
720 name for name in environments if not self.isGlobalEnvironment(name) |
666 ] |
721 ] |
667 if filterList != ("all",): |
722 if filterList != ("all",): |
682 not in excludeFilter |
737 not in excludeFilter |
683 ] |
738 ] |
684 |
739 |
685 return environments |
740 return environments |
686 |
741 |
|
742 def isAvailableEnvironment(self, venvName): |
|
743 """ |
|
744 Public method to test, if a given environment is available. |
|
745 |
|
746 @param venvName logical name of the virtual environment |
|
747 @type str |
|
748 @return flag indicating an available environment |
|
749 @rtype bool |
|
750 """ |
|
751 try: |
|
752 return self.__virtualEnvironments[venvName].available |
|
753 except KeyError: |
|
754 return False |
|
755 |
687 def isGlobalEnvironment(self, venvName): |
756 def isGlobalEnvironment(self, venvName): |
688 """ |
757 """ |
689 Public method to test, if a given environment is a global one. |
758 Public method to test, if a given environment is a global one. |
690 |
759 |
691 @param venvName logical name of the virtual environment |
760 @param venvName logical name of the virtual environment |