spinetoolbox.widgets.kernel_editor¶
Dialog for selecting a kernel or creating a new Julia or Python kernel.
| author: |
|
|---|---|
| date: | 7.10.2020 |
Module Contents¶
Classes¶
KernelEditor |
Class for a Python and Julia kernel editor. |
Functions¶
find_kernels() |
Returns a dictionary mapping kernel names to kernel paths. |
find_python_kernels() |
Returns a dictionary of Python kernels. Keys are kernel_names, values are kernel paths. |
find_julia_kernels() |
Returns a dictionary of Julia kernels. Keys are kernel_names, values are kernel paths. |
find_unknown_kernels() |
Returns a dictionary of kernels that are neither Python nor Julia kernels. |
format_log_message(msg_type, message, show_datetime=True) |
Formats message for the kernel editor text browser. |
format_process_message(msg_type, message) |
Formats message for the kernel editor text browser. |
-
class
spinetoolbox.widgets.kernel_editor.KernelEditor(parent, python, julia, python_or_julia, current_kernel)[source]¶ Bases:
PySide2.QtWidgets.QDialogClass for a Python and Julia kernel editor.
Parameters: - parent (QWidget) – Parent widget (Settings widget)
- python (str) – Python interpreter, may be empty string
- julia (str) – Julia executable, may be empty string
- python_or_julia (str) – Setup KernelEditor according to selected mode
- current_kernel (str) – Current selected Python or Julia kernel name
-
setup_dialog_style(self)[source]¶ Sets windows icon and stylesheet. This can be removed when SettingsWidget inherits stylesheet from ToolboxUI.
-
python_kernel_name_edited(self, txt)[source]¶ Updates the display name place holder text and the command QCustomLabel tool tip.
-
select_julia_clicked(self, checked=False)[source]¶ Opens file browser where user can select a Julia executable for the new kernel.
-
select_julia_project_clicked(self, checked=False)[source]¶ Opens file browser where user can select a Julia project path for the new kernel.
-
select_python_clicked(self, checked=False)[source]¶ Opens file browser where user can select the python interpreter for the new kernel.
-
update_python_cmd_tooltip(self)[source]¶ Updates Python command (CustomQLabel) tooltip according to selections.
-
update_julia_cmd_tooltip(self)[source]¶ Updates Julia command (CustomQLabel) tooltip according to selections.
-
set_kernel_selected(self, k_name)[source]¶ Finds row index of given kernel name from the model, sets it selected and scrolls the view so that it’s visible.
Parameters: k_name (str) – Kernel name to find and select
-
_check_kernel_is_ok(self, current, previous)[source]¶ Shows a notification if there are any known problems with selected kernel.
Parameters: - current (QModelIndex) – Currently selected index
- previous (QModelIndex) – Previously selected index
-
find_column(self, label)[source]¶ Returns the column number from the kernel model with the given label.
Parameters: label (str) – Header column label Returns: Column number or -1 if label not found Return type: int
-
make_python_kernel(self, 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.
-
start_kernelspec_install_process(self, 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(self, retval)[source]¶ Handles case when the process for installing the kernel has finished.
Parameters: retval (int) – Process return value. 0: success, !0: failure
-
check_options(self, 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
-
populate_kernel_model(self)[source]¶ Populates the kernel model with kernels found in user’s system either with Python or Julia kernels. Unknows, invalid, and unsupported kernels are appended to the end.
-
static
get_kernel_deats(kernel_path)[source]¶ Reads kernel.json from given kernel path and returns the details in a dictionary.
Parameters: kernel_path (str) – Full path to kernel directory Returns: language (str), path to interpreter (str), display name (str), project (str) (NA for Python kernels) Return type: dict
Shows the context-menu in the kernel list table view.
-
_open_kernel_json(self, checked=False)[source]¶ Opens kernel.json file using the default application for .json files.
-
_remove_kernel(self, checked=False)[source]¶ Removes selected kernel by deleting the kernel directory.
-
mousePressEvent(self, e)[source]¶ Saves mouse position at the start of dragging.
Parameters: e (QMouseEvent) – Mouse event
-
mouseReleaseEvent(self, e)[source]¶ Saves mouse position at the end of dragging.
Parameters: e (QMouseEvent) – Mouse event
-
mouseMoveEvent(self, e)[source]¶ Moves the window when mouse button is pressed and mouse cursor is moved.
Parameters: e (QMouseEvent) – Mouse event
-
is_package_installed(self, 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(self, 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(self, retval)[source]¶ Handles installing package finished.
Parameters: retval (int) – Process return value. 0: success, !0: failure
-
make_julia_kernel(self, 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_ijulia_installed(self, 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(self, 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(self, ret)[source]¶ Runs when IJulia install process finishes.
Parameters: ret (int) – Process return value. 0: success, !0: failure
-
handle_ijulia_rebuild_finished(self, ret)[source]¶ Runs when IJulia rebuild process finishes.
Parameters: ret (int) – Process return value. 0: success, !0: failure
-
start_ijulia_installkernel_process(self, program, project, kernel_name)[source]¶ Installs the kernel using IJulia.installkernel function. Given kernel_name is actually the new kernel DISPLAY name. IJulia strips the whitespace and uncapitalizes this to make the kernel name automatically. Julia version is concatenated to both names automatically (This cannot be changed).
-
handle_installkernel_process_finished(self, retval)[source]¶ Checks whether or not the IJulia.installkernel process finished successfully.
Parameters: retval (int) – Process return value. 0: success, !0: failure
-
restore_dialog_dimensions(self)[source]¶ Restore widget location, dimensions, and state from previous session.
-
add_message(self, msg)[source]¶ Append regular message to kernel editor text browser.
Parameters: msg (str) – String written to QTextBrowser
-
add_success_message(self, msg)[source]¶ Append message with green text color to kernel editor text browser.
Parameters: msg (str) – String written to QTextBrowser
-
add_error_message(self, msg)[source]¶ Append message with red color to kernel editor text browser.
Parameters: msg (str) – String written to QTextBrowser
-
add_warning_message(self, msg)[source]¶ Append message with yellow (golden) color to kernel editor text browser.
Parameters: msg (str) – String written to QTextBrowser
-
add_process_message(self, msg)[source]¶ Writes message from stdout to kernel editor text browser.
Parameters: msg (str) – String written to QTextBrowser
-
add_process_error_message(self, msg)[source]¶ Writes message from stderr to kernel editor text browser.
Parameters: msg (str) – String written to QTextBrowser
-
spinetoolbox.widgets.kernel_editor.find_kernels()[source]¶ Returns a dictionary mapping kernel names to kernel paths.
-
spinetoolbox.widgets.kernel_editor.find_python_kernels()[source]¶ Returns a dictionary of Python kernels. Keys are kernel_names, values are kernel paths.
-
spinetoolbox.widgets.kernel_editor.find_julia_kernels()[source]¶ Returns a dictionary of Julia kernels. Keys are kernel_names, values are kernel paths.
-
spinetoolbox.widgets.kernel_editor.find_unknown_kernels()[source]¶ Returns a dictionary of kernels that are neither Python nor Julia kernels.