spinetoolbox.widgets.kernel_editor

Widget for showing the progress of making a Julia or Python kernel.

Module Contents

Classes

KernelEditorBase

Base class for kernel editors.

MiniPythonKernelEditor

A Simple Python kernel maker. The Python executable path is passed in

MiniJuliaKernelEditor

A Simple Julia Kernel maker. The julia exe and project are passed in

Functions

format_event_message(msg_type, message[, show_datetime])

Formats message for the kernel editor text browser.

format_process_message(msg_type, message)

Formats process message for the kernel editor text browser.

class spinetoolbox.widgets.kernel_editor.KernelEditorBase(parent, python_or_julia)[source]

Bases: PySide6.QtWidgets.QDialog

Base class for kernel editors.

Parameters
  • parent (SettingsWidget) – Parent widget

  • python_or_julia (str) – kernel type; valid values: “julia”, “python”

connect_signals()[source]

Connects signals to slots.

_show_close_button(failed=False)[source]
make_kernel()[source]
abstract _do_make_kernel()[source]
new_kernel_name()[source]

Returns the new kernel name after it’s been created.

_solve_new_kernel_name()[source]

Finds out the new kernel name after a new kernel has been created.

check_options(prgm, kernel_name, display_name, python_or_julia)[source]

Checks that user options are valid before advancing with kernel making.

Parameters
  • prgm (str) – Full path to Python or Julia program

  • kernel_name (str) – Kernel name

  • display_name (str) – Kernel display name

  • python_or_julia (str) – Either ‘python’ or ‘julia’

Returns

True if all user input is valid for making a new kernel, False otherwise

Return type

bool

abstract _python_kernel_name()[source]
abstract _python_kernel_display_name()[source]
_python_interpreter_name()[source]
make_python_kernel(checked=False)[source]

Makes a new Python kernel. Offers to install ipykernel package if it is missing from the selected Python environment. Overwrites existing kernel with the same name if this is ok by user.

static is_package_installed(python_path, package_name)[source]

Checks if given package is installed to given Python environment.

Parameters
  • python_path (str) – Full path to selected Python interpreter

  • package_name (str) – Package name

Returns

True if installed, False if not

Return type

(bool)

start_package_install_process(python_path, package_name)[source]

Starts installing the given package using pip.

Parameters
  • python_path (str) – Full path to selected Python interpreter

  • package_name (str) – Package name to install using pip

handle_package_install_process_finished(retval)[source]

Handles installing package finished.

Parameters

retval (int) – Process return value. 0: success, !0: failure

start_kernelspec_install_process(prgm, k_name, d_name)[source]

Installs kernel specifications for the given Python environment. Runs e.g. this command in QProcess

python -m ipykernel install –user –name python-X.Y –display-name PythonX.Y

Creates new kernel specs into %APPDATA%jupyterkernels. Existing directory will be overwritten.

Note: We cannot use –sys.prefix here because if we have selected to create a kernel for some other python that was used in launching the app, the kernel will be created into a location that is not discoverable by jupyter and hence not by Spine Toolbox. E.g. when sys.executable is C:Python36python.exe, and we have selected that as the python for Spine Toolbox (Settings->Tools->Python interpreter is empty), creating a kernel with –sys-prefix creates kernel specs into C:Python36sharejupyterkernelspython-3.6. This is ok and the kernel spec is discoverable by jupyter and Spine Toolbox.

BUT when sys.executable is C:Python36python.exe, and we have selected another python for Spine Toolbox (Settings->Tools->Python interpreter is C:Python38python.exe), creating a kernel with –sys-prefix creates a kernel into C:Python38sharejupyterkernelspython-3.8-sys-prefix. This is not discoverable by jupyter nor Spine Toolbox. You would need to start the app using C:Python38python.exe to see and use that kernel spec.

Using –user option instead, creates kernel specs that are discoverable by any python that was used in starting Spine Toolbox.

Parameters
  • prgm (str) – Full path to Python interpreter for which the kernel is created

  • k_name (str) – Kernel name

  • d_name (str) – Kernel display name

handle_kernelspec_install_process_finished(retval)[source]

Handles case when the process for installing the kernel has finished.

Parameters

retval (int) – Process return value. 0: success, !0: failure

abstract _julia_kernel_name()[source]
_julia_executable()[source]
_julia_project()[source]
make_julia_kernel(checked=False)[source]

Makes a new Julia kernel. Offers to install IJulia package if it is missing from the selected Julia project. Overwrites existing kernel with the same name if this is ok by user.

_is_rebuild_ijulia_needed()[source]
is_ijulia_installed(program, project)[source]

Checks if IJulia is installed for the given project. Note: Trying command ‘using IJulia’ does not work since it automatically tries loading it from the LOAD_PATH if not it’s not found in the active project.

Returns

0 when process failed to start, 1 when IJulia is installed, 2 when IJulia is not installed.

Return type

int

start_ijulia_install_process(julia, project)[source]

Starts installing IJulia package to given Julia project.

Parameters
  • julia (str) – Full path to selected Julia executable

  • project (str) – Julia project (e.g. dir path or ‘@.’, or ‘.’)

handle_ijulia_install_finished(ret)[source]

Runs when IJulia install process finishes.

Parameters

ret (int) – Process return value. 0: success, !0: failure

start_ijulia_rebuild_process(program, project)[source]

Starts rebuilding IJulia.

handle_ijulia_rebuild_finished(ret)[source]

Runs when IJulia rebuild process finishes.

Parameters

ret (int) – Process return value. 0: success, !0: failure

start_ijulia_installkernel_process(program, project, kernel_name)[source]

Installs the kernel using IJulia.installkernel function. Given kernel_name is the new kernel DISPLAY name prefix. IJulia strips the whitespace and uncapitalizes this to make the kernel name automatically. Julia version is concatenated to both kernel and display names automatically (This cannot be changed).

handle_installkernel_process_finished(retval)[source]

Checks whether the IJulia.installkernel process finished successfully.

Parameters

retval (int) – Process return value. 0: success, !0: failure

restore_dialog_dimensions()[source]

Restore widget location, dimensions, and state from previous session.

add_message(msg)[source]

Append regular message to kernel editor text browser.

Parameters

msg (str) – String written to QTextBrowser

add_success_message(msg)[source]

Append message with green text color to kernel editor text browser.

Parameters

msg (str) – String written to QTextBrowser

add_error_message(msg)[source]

Append message with red color to kernel editor text browser.

Parameters

msg (str) – String written to QTextBrowser

add_warning_message(msg)[source]

Append message with yellow (golden) color to kernel editor text browser.

Parameters

msg (str) – String written to QTextBrowser

add_process_message(msg)[source]

Writes message from stdout to kernel editor text browser.

Parameters

msg (str) – String written to QTextBrowser

add_process_error_message(msg)[source]

Writes message from stderr to kernel editor text browser.

Parameters

msg (str) – String written to QTextBrowser

_save_ui()[source]
class spinetoolbox.widgets.kernel_editor.MiniPythonKernelEditor(parent, python_exe)[source]

Bases: KernelEditorBase

A Simple Python kernel maker. The Python executable path is passed in the constructor, then calling make_kernel starts the process.

Parameters
  • parent (SettingsWidget) – Parent widget

  • python_or_julia (str) – kernel type; valid values: “julia”, “python”

abstract _julia_kernel_name()[source]
_python_kernel_name()[source]
_python_kernel_display_name()[source]
_do_make_kernel()[source]
handle_kernelspec_install_process_finished(retval)[source]

Handles case when the process for installing the kernel has finished.

Parameters

retval (int) – Process return value. 0: success, !0: failure

set_kernel_name()[source]

Retrieves Python version in a subprocess and makes a kernel name based on it.

class spinetoolbox.widgets.kernel_editor.MiniJuliaKernelEditor(parent, julia_exe, julia_project)[source]

Bases: KernelEditorBase

A Simple Julia Kernel maker. The julia exe and project are passed in the constructor, then calling make_kernel starts the process.

Parameters
  • parent (SettingsWidget) – Parent widget

  • python_or_julia (str) – kernel type; valid values: “julia”, “python”

_julia_kernel_name()[source]
abstract _python_kernel_name()[source]
abstract _python_kernel_display_name()[source]
_do_make_kernel()[source]
handle_installkernel_process_finished(retval)[source]

Checks whether the IJulia.installkernel process finished successfully.

Parameters

retval (int) – Process return value. 0: success, !0: failure

spinetoolbox.widgets.kernel_editor.format_event_message(msg_type, message, show_datetime=True)[source]

Formats message for the kernel editor text browser. This is a copy of helpers.format_event_message() but the colors have been edited for a text browser with a white background.

spinetoolbox.widgets.kernel_editor.format_process_message(msg_type, message)[source]

Formats process message for the kernel editor text browser.