503 "Traceback: {2}\n").format( |
503 "Traceback: {2}\n").format( |
504 params["ExceptionType"], |
504 params["ExceptionType"], |
505 params["ExceptionValue"], |
505 params["ExceptionValue"], |
506 params["Traceback"])) |
506 params["Traceback"])) |
507 |
507 |
508 def __startCodeAssistClient(self, interpreter, idString): |
508 def __startCodeAssistClient(self, interpreter, idString, clientEnv): |
509 """ |
509 """ |
510 Private method to start the code assist client with the given |
510 Private method to start the code assist client with the given |
511 interpreter. |
511 interpreter. |
512 |
512 |
513 @param interpreter interpreter to be used for the code assist client |
513 @param interpreter interpreter to be used for the code assist client |
514 @type str |
514 @type str |
515 @param idString id of the client to be started |
515 @param idString id of the client to be started |
516 @type str |
516 @type str |
|
517 @param clientEnv dictionary with environment variables to run the |
|
518 interpreter with |
|
519 @type dict |
517 @return flag indicating a successful start of the client |
520 @return flag indicating a successful start of the client |
518 @rtype bool |
521 @rtype bool |
519 """ |
522 """ |
520 ok = False |
523 ok = False |
521 |
524 |
529 os.makedirs(configDir) |
532 os.makedirs(configDir) |
530 |
533 |
531 client = os.path.join(os.path.dirname(__file__), |
534 client = os.path.join(os.path.dirname(__file__), |
532 "CodeAssistClient.py") |
535 "CodeAssistClient.py") |
533 ok = self.startClient(interpreter, client, [configDir], |
536 ok = self.startClient(interpreter, client, [configDir], |
534 idString=idString) |
537 idString=idString, environment=clientEnv) |
535 if not ok: |
538 if not ok: |
536 self.__ui.appendToStderr(self.tr( |
539 self.__ui.appendToStderr(self.tr( |
537 "'{0}' is not supported because the configured interpreter" |
540 "'{0}' is not supported because the configured interpreter" |
538 " could not be started.\n" |
541 " could not be started.\n" |
539 ).format(idString)) |
542 ).format(idString)) |
558 """ |
561 """ |
559 ok = idString in self.connectionNames() |
562 ok = idString in self.connectionNames() |
560 if not ok: |
563 if not ok: |
561 # client is not running |
564 # client is not running |
562 if idString == CodeAssistServer.IdProject: |
565 if idString == CodeAssistServer.IdProject: |
563 interpreter = self.__interpreterForProject() |
566 interpreter, clientEnv = self.__interpreterForProject() |
564 else: |
567 else: |
565 interpreter = "" |
568 interpreter = "" |
566 venvName = "" |
569 venvName = "" |
|
570 clientEnv = os.environ.copy() |
567 try: |
571 try: |
568 # new code using virtual environments |
572 # new code using virtual environments |
569 venvManager = e5App().getObject("VirtualEnvManager") |
573 venvManager = e5App().getObject("VirtualEnvManager") |
570 if idString == "Python2": |
574 if idString == "Python2": |
571 # Python 2 |
575 # Python 2 |
588 # ignore for eric6 < 18.10 |
592 # ignore for eric6 < 18.10 |
589 pass |
593 pass |
590 if venvName: |
594 if venvName: |
591 interpreter = \ |
595 interpreter = \ |
592 venvManager.getVirtualenvInterpreter(venvName) |
596 venvManager.getVirtualenvInterpreter(venvName) |
|
597 |
|
598 try: |
|
599 execPath = \ |
|
600 venvManager.getVirtualenvExecPath(venvName) |
|
601 except AttributeError: |
|
602 # eric6 < 18.12 |
|
603 execPath = "" |
|
604 |
|
605 # build a suitable environment |
|
606 if execPath: |
|
607 if "PATH" in clientEnv: |
|
608 clientEnv["PATH"] = os.pathsep.join( |
|
609 [execPath, clientEnv["PATH"]]) |
|
610 else: |
|
611 clientEnv["PATH"] = execPath |
593 except KeyError: |
612 except KeyError: |
594 # backward compatibility (eric <18.07) |
613 # backward compatibility (eric <18.07) |
595 if idString == "Python2": |
614 if idString == "Python2": |
596 # Python 2 |
615 # Python 2 |
597 interpreter = \ |
616 interpreter = \ |
599 elif idString == "Python3": |
618 elif idString == "Python3": |
600 # Python 3 |
619 # Python 3 |
601 interpreter = \ |
620 interpreter = \ |
602 Preferences.getDebugger("Python3Interpreter") |
621 Preferences.getDebugger("Python3Interpreter") |
603 if interpreter: |
622 if interpreter: |
604 ok = self.__startCodeAssistClient(interpreter, idString) |
623 ok = self.__startCodeAssistClient(interpreter, idString, |
|
624 clientEnv) |
605 else: |
625 else: |
606 ok = False |
626 ok = False |
607 return ok |
627 return ok |
608 |
628 |
609 def __interpreterForProject(self): |
629 def __interpreterForProject(self): |
610 """ |
630 """ |
611 Private method to determine the interpreter for the current project. |
631 Private method to determine the interpreter for the current project and |
612 |
632 the environment to run it. |
613 @return interpreter of the current project |
633 |
614 @rtype str |
634 @return tuple containing the interpreter of the current project and the |
|
635 environment variables |
|
636 @rtype tuple of (str, dict) |
615 """ |
637 """ |
616 interpreter = "" |
638 interpreter = "" |
|
639 clientEnv = os.environ.copy() |
617 projectLanguage = self.__e5project.getProjectLanguage() |
640 projectLanguage = self.__e5project.getProjectLanguage() |
618 |
641 |
619 if projectLanguage.startswith("Python"): |
642 if projectLanguage.startswith("Python"): |
620 try: |
643 try: |
621 # new code using virtual environments |
644 # new code using virtual environments |
648 else: |
671 else: |
649 venvName = "" |
672 venvName = "" |
650 if venvName: |
673 if venvName: |
651 interpreter = \ |
674 interpreter = \ |
652 venvManager.getVirtualenvInterpreter(venvName) |
675 venvManager.getVirtualenvInterpreter(venvName) |
|
676 |
|
677 try: |
|
678 execPath = venvManager.getVirtualenvExecPath(venvName) |
|
679 except AttributeError: |
|
680 # eric6 < 18.12 |
|
681 execPath = "" |
|
682 |
|
683 # build a suitable environment |
|
684 if execPath: |
|
685 if "PATH" in clientEnv: |
|
686 clientEnv["PATH"] = os.pathsep.join( |
|
687 [execPath, clientEnv["PATH"]]) |
|
688 else: |
|
689 clientEnv["PATH"] = execPath |
653 except KeyError: |
690 except KeyError: |
654 # backward compatibility (eric < 18.07) |
691 # backward compatibility (eric < 18.07) |
655 # get interpreter from project first |
692 # get interpreter from project first |
656 interpreter = self.__e5project.getDebugProperty("INTERPRETER") |
693 interpreter = self.__e5project.getDebugProperty("INTERPRETER") |
657 if not interpreter or not Utilities.isinpath(interpreter): |
694 if not interpreter or not Utilities.isinpath(interpreter): |
661 "PythonInterpreter") |
698 "PythonInterpreter") |
662 elif projectLanguage == "Python3": |
699 elif projectLanguage == "Python3": |
663 interpreter = Preferences.getDebugger( |
700 interpreter = Preferences.getDebugger( |
664 "Python3Interpreter") |
701 "Python3Interpreter") |
665 |
702 |
666 return interpreter |
703 return interpreter, clientEnv |
667 |
704 |
668 @pyqtSlot() |
705 @pyqtSlot() |
669 def handleNewConnection(self): |
706 def handleNewConnection(self): |
670 """ |
707 """ |
671 Public slot for new incoming connections from a client. |
708 Public slot for new incoming connections from a client. |