def find_julia_version(self): julia_path = self._toolbox.qsettings().value("appSettings/juliaPath", defaultValue="") if julia_path != "": self.julia_exe = julia_path else: self.julia_exe = JULIA_EXECUTABLE self.julia_project_path = self._toolbox.qsettings().value( "appSettings/juliaProjectPath", defaultValue="") if self.julia_project_path == "": self.julia_project_path = "@." args = list() args.append("-e") args.append("println(VERSION)") exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, silent=True) exec_mngr.start_execution() if exec_mngr.wait_for_process_finished(msecs=5000): self._julia_version = exec_mngr.process_output args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append("println(Base.active_project())") exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, silent=True) exec_mngr.start_execution() if exec_mngr.wait_for_process_finished(msecs=5000): self._julia_active_project = exec_mngr.process_output
def execute(self, **kwargs): """Executes a prepared instance.""" self.exec_mngr = QProcessExecutionManager(self._logger, self.program, self.args, **kwargs) self.exec_mngr.execution_finished.connect( self.handle_execution_finished) self.exec_mngr.start_execution(workdir=self.basedir)
def execute(self, **kwargs): """Executes a prepared instance.""" self.exec_mngr = QProcessExecutionManager(self._logger, self.program, self.args, **kwargs) self.exec_mngr.execution_finished.connect( self.handle_execution_finished) # TODO: Check if this sets the curDir argument. Is the curDir arg now useless? self.exec_mngr.start_execution(workdir=self.basedir)
def test_execute_python_interpreter(self): program = sys.executable logger = MagicMock() manager = QProcessExecutionManager(logger, program, args=["--version"]) manager.start_execution() self.assertTrue(manager.wait_for_process_finished()) self.assertFalse(manager.process_failed_to_start) self.assertFalse(manager.process_failed)
def check_py_call_program(self): args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append("using PyCall; println(PyCall.pyprogramname);") self.exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, silent=True) self.exec_mngr.execution_finished.connect( self._handle_check_py_call_program_finished) self.exec_mngr.start_execution()
def update_spine_opt(self): args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append("using Pkg; Pkg.update(ARGS[1]);") args.append("SpineOpt") self.exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, semisilent=True) self.exec_mngr.execution_finished.connect( self._handle_spine_opt_process_finished) self.exec_mngr.start_execution()
def find_julia_version(self): args = list() args.append("-e") args.append("println(VERSION)") exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, silent=True) exec_mngr.start_execution() if exec_mngr.wait_for_process_finished(msecs=5000): self._julia_version = exec_mngr.process_output args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append("println(Base.active_project())") exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, silent=True) exec_mngr.start_execution() if exec_mngr.wait_for_process_finished(msecs=5000): self._julia_active_project = exec_mngr.process_output
def install_py_call(self): """Starts process that installs PyCall in current julia version. """ args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append("using Pkg; Pkg.add(ARGS[1]);") args.append("PyCall") self.exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, semisilent=True) self.exec_mngr.execution_finished.connect( self._handle_install_py_call_finished) self.exec_mngr.start_execution()
def install_spine_opt(self): args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append( "using Pkg; Pkg.Registry.add(RegistrySpec(url=ARGS[1])); Pkg.add(ARGS[2]);" ) args.append("https://github.com/Spine-project/SpineJuliaRegistry.git") args.append("SpineOpt") self.exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, semisilent=True) self.exec_mngr.execution_finished.connect( self._handle_spine_opt_process_finished) self.exec_mngr.start_execution()
def install_spine_model(self): args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append( "using Pkg; Pkg.add(PackageSpec(url=ARGS[1])); Pkg.add(PackageSpec(url=ARGS[2]));" ) args.append("https://github.com/Spine-project/SpineInterface.jl.git") args.append("https://github.com/Spine-project/Spine-Model.git") self.exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, semisilent=True) self.exec_mngr.execution_finished.connect( self._handle_spine_model_process_finished) self.exec_mngr.start_execution()
def reconfigure_py_call(self): """Starts process that reconfigures PyCall to use selected Python interpreter.""" args = list() args.append(f"--project={self.julia_project_path}") args.append("-e") args.append( "using PyCall; ENV[ARGS[1]] = ARGS[2]; using Pkg; Pkg.build(ARGS[3]);" ) args.append("PYTHON") args.append(self.python) args.append("PyCall") self.exec_mngr = QProcessExecutionManager(self._toolbox, self.julia_exe, args, semisilent=True) self.exec_mngr.execution_finished.connect( self._handle_reconfigure_py_call_finished) self.exec_mngr.start_execution()
def execute(self, **kwargs): """Executes a prepared instance.""" if (self._settings.value("appSettings/useEmbeddedPython", defaultValue="0") == "2" and self._embedded_console is not None): self.exec_mngr = ConsoleExecutionManager(self._embedded_console, self.ipython_command_list, self._logger) self.exec_mngr.execution_finished.connect( self.handle_console_execution_finished) self.exec_mngr.start_execution() else: self.exec_mngr = QProcessExecutionManager(self._logger, self.program, self.args, **kwargs) self.exec_mngr.execution_finished.connect( self.handle_execution_finished) self.exec_mngr.start_execution(workdir=self.basedir)
def make_python_process(program, args, python_path, logger): """Returns an execution manager instance for running the given program in a QProcess. Args: program (str): Path to the program file importer_args (list): Arguments for the program python_path (str): Python executable to check logger (LoggerInterface) Returns: QProcessExecutionManager """ program_path = os.path.abspath(program) python_cmd = python_path if python_path else PYTHON_EXECUTABLE if not python_exists(python_cmd, logger): return None process = QProcessExecutionManager(logger, python_cmd, [program_path]) process.data_to_inject = args return process
def execute(self, **kwargs): """Executes a prepared instance.""" if (self._settings.value("appSettings/useEmbeddedJulia", defaultValue="2") == "2" and self._embedded_console is not None): self.exec_mngr = ConsoleExecutionManager(self._embedded_console, self.ijulia_command_list, self._logger) self.exec_mngr.execution_finished.connect( self.handle_repl_execution_finished) self.exec_mngr.start_execution() else: self.exec_mngr = QProcessExecutionManager(self._logger, self.program, self.args, **kwargs) self.exec_mngr.execution_finished.connect( self.handle_execution_finished) # On Julia the Qprocess workdir must be set to the path where the main script is # Otherwise it doesn't find input files in subdirectories self.exec_mngr.start_execution(workdir=self.basedir)
def python_exists(program, logger): """Checks that Python is set up correctly in Settings. This executes 'python -V' in a QProcess and if the process finishes successfully, the python is ready to be used. Args: program (str): Python executable to check logger (LoggerInterface) Returns: bool: True if Python is found, False otherwise """ args = ["-V"] python_check_process = QProcessExecutionManager(logger, program, args, silent=True) python_check_process.start_execution() if not python_check_process.wait_for_process_finished(msecs=3000): logger.msg_error.emit( "Couldn't execute Python. Please check the <b>Python interpreter</b> option in Settings." ) return False return True
def test_execute_nothing(self): logger = MagicMock() manager = QProcessExecutionManager(logger) manager.start_execution() self.assertFalse(manager.wait_for_process_finished()) self.assertTrue(manager.process_failed_to_start)