Skip to content

Commit

Permalink
Activate Julia environment in Basic Console if available
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavol committed Jan 16, 2025
1 parent d7ab408 commit b2dd294
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions spinetoolbox/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
)
from spine_engine.spine_engine import _set_resource_limits
from spine_engine.load_project_items import load_item_specification_factories
from spine_engine.utils.helpers import resolve_python_interpreter, resolve_julia_executable
from spine_engine.utils.helpers import resolve_python_interpreter, resolve_julia_executable, resolve_julia_project
from spinetoolbox.server.engine_client import ClientSecurityModel, EngineClient, RemoteEngineInitFailed
from .config import DEFAULT_WORK_DIR, MAINWINDOW_SS, ONLINE_DOCUMENTATION_URL, SPINE_TOOLBOX_REPO_URL
from .helpers import (
Expand Down Expand Up @@ -2347,20 +2347,22 @@ def start_detached_python_basic_console(self):
def start_detached_julia_basic_console(self):
"""Starts basic console with the default Julia executable."""
julia = resolve_julia_executable(self.qsettings())
project = resolve_julia_project(self.qsettings())

Check warning on line 2350 in spinetoolbox/ui_main.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/ui_main.py#L2349-L2350

Added lines #L2349 - L2350 were not covered by tests
if not julia:
self.msg_warning.emit("No Julia installation found. Add path to a Julia executable in Spine "

Check warning on line 2352 in spinetoolbox/ui_main.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/ui_main.py#L2352

Added line #L2352 was not covered by tests
"Toolbox Settings [<b>File->Settings->Tools</b>]")
return
_set_resource_limits(self.qsettings(), threading.Lock())
self.start_detached_basic_console("julia", julia)
self.start_detached_basic_console("julia", julia, project)

Check warning on line 2356 in spinetoolbox/ui_main.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/ui_main.py#L2354-L2356

Added lines #L2354 - L2356 were not covered by tests

def start_detached_basic_console(self, language, executable):
def start_detached_basic_console(self, language, executable, julia_project=None):
"""Launches a new detached basic console with the given executable
or activates an existing Console if the kernel is already running.
Args:
language (str): Console kernel language
executable (str): Abs. path to kernel file
julia_project (str): Path to Julia environment
"""
for pcw in self._persistent_consoles.values():
if pcw.detached_console_id is not None:
Expand All @@ -2373,7 +2375,7 @@ def start_detached_basic_console(self, language, executable):
icon = basic_console_icon(language)
console_window = ConsoleWindow(icon, language)
c = PersistentConsoleWidget(self, None, language, None, console_window)
key = c.request_start_kernel(executable)
key = c.request_start_kernel(executable, julia_project)

Check warning on line 2378 in spinetoolbox/ui_main.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/ui_main.py#L2372-L2378

Added lines #L2372 - L2378 were not covered by tests
if not key:
self.msg_error.emit(f"Starting Basic Console for {executable} failed")
return
Expand Down
8 changes: 6 additions & 2 deletions spinetoolbox/widgets/persistent_console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,24 +788,28 @@ def contextMenuEvent(self, ev):
self._extend_menu(menu)
menu.exec(ev.globalPos())

def request_start_kernel(self, exec_path):
def request_start_kernel(self, exec_path, julia_project=None):
"""Requests Spine Engine to launch a persistent kernel manager for the given Python.
Args:
exec_path (str): Abs. path to kernel file (e.g. ../../julia.exe or ../../python.exe)
julia_project (str): Path to Julia environment
Returns:
str or None: Kernel manager key if kernel manager was launched successfully, None otherwise
"""
args = [exec_path]

Check warning on line 801 in spinetoolbox/widgets/persistent_console_widget.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/widgets/persistent_console_widget.py#L801

Added line #L801 was not covered by tests
if self._language == "python":
manager_class = PythonPersistentExecutionManager

Check warning on line 803 in spinetoolbox/widgets/persistent_console_widget.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/widgets/persistent_console_widget.py#L803

Added line #L803 was not covered by tests
elif self._language == "julia":
manager_class = JuliaPersistentExecutionManager

Check warning on line 805 in spinetoolbox/widgets/persistent_console_widget.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/widgets/persistent_console_widget.py#L805

Added line #L805 was not covered by tests
if julia_project:
args += ["--project=" + julia_project]

Check warning on line 807 in spinetoolbox/widgets/persistent_console_widget.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/widgets/persistent_console_widget.py#L807

Added line #L807 was not covered by tests
else:
self._logger.msg_error.emit(f"Unsupported console language '{self._language}'")
return None
self._execution_manager = manager_class(

Check warning on line 811 in spinetoolbox/widgets/persistent_console_widget.py

View check run for this annotation

Codecov / codecov/patch

spinetoolbox/widgets/persistent_console_widget.py#L809-L811

Added lines #L809 - L811 were not covered by tests
self._logger, [exec_path], [], f"Detached Basic {self._language.capitalize()} Console", False, None
self._logger, args, [], f"Detached Basic {self._language.capitalize()} Console", False, None
)
try:
msg_type, msg = self._q.get(timeout=20) # Blocks until msg (tuple(str, dict) is received, or timeout.
Expand Down

0 comments on commit b2dd294

Please sign in to comment.