Skip to content

Commit

Permalink
jupyter explicit kernel selection: slow but steady progress, fixing i…
Browse files Browse the repository at this point in the history
…nitial loading, better layout, ...
  • Loading branch information
haraldschilly committed Nov 8, 2018
1 parent fa962ac commit af10762
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 92 deletions.
1 change: 1 addition & 0 deletions src/smc-util/misc.js
Expand Up @@ -3165,6 +3165,7 @@ exports.jupyter_language_to_name = function(lang) {
// Find the kernel whose name is closest to the given name.
exports.closest_kernel_match = function(name, kernel_list) {
name = name.toLowerCase().replace("matlab", "octave");
name = name === "python" ? "python3" : name;
let bestValue = -1;
let bestMatch = null;
for (
Expand Down
42 changes: 27 additions & 15 deletions src/smc-webapp/jupyter/actions.ts
Expand Up @@ -381,13 +381,14 @@ export class JupyterActions extends Actions<JupyterStoreState> {
this.setState({ kernel_info });
};

set_jupyter_kernels = () => {
set_jupyter_kernels = async () => {
const kernels = jupyter_kernels.get(this.store.jupyter_kernel_key());
if (kernels != null) {
this.setState({ kernels });
} else {
this.fetch_jupyter_kernels();
await this.fetch_jupyter_kernels();
}
this.update_select_kernel_data();
};

set_error = (err: any): void => {
Expand Down Expand Up @@ -888,10 +889,6 @@ export class JupyterActions extends Actions<JupyterStoreState> {
this.set_cm_options();
}

// unkown kernel name
if (!this._is_project && obj.kernel_info == null) {
this.show_select_kernel();
}
break;
}
});
Expand All @@ -917,13 +914,14 @@ export class JupyterActions extends Actions<JupyterStoreState> {
this._state = "ready";
}

if (this.store.get("kernel") == null) {
const kernel = this.store.get("kernel");
const no_kernel: boolean = kernel == null;
const unknown_kernel: boolean = !no_kernel
? this.store.get_kernel_info(kernel) == null
: false;
if (no_kernel || unknown_kernel) {
this.show_select_kernel();
} else {
// we have a kernel
this.hide_select_kernel();
}

if (this.store.get("view_mode") === "raw") {
this.set_raw_ipynb();
}
Expand Down Expand Up @@ -3178,28 +3176,42 @@ export class JupyterActions extends Actions<JupyterStoreState> {
this.file_action("close_file");
};

show_select_kernel = (): void => {
update_select_kernel_data = (): void => {
const kernels = jupyter_kernels.get(this.store.jupyter_kernel_key());
if (kernels == null) return;
const kernel_selection = this.store.get_kernel_selection(kernels);
const kernels_by_name = this.store.get_kernels_by_name(kernels);
const [
kernels_by_name,
kernels_by_language
] = this.store.get_kernels_by_name_or_language(kernels);
const default_kernel = this.store.get_default_kernel();
// do we have a similar kernel?
let closestKernel: TKernel | undefined = undefined;
const kernel = this.store.get("kernel");
const kernel_info = this.store.get_kernel_info(kernel);
// unknown kernel, we try to find a close match
if (kernel_info == null) {
if (kernel_info == null && kernel != null && kernels != null) {
// kernel & kernels must be defined
closestKernel = misc.closest_kernel_match(kernel, kernels);
}
this.setState({
show_kernel_selector: true,
kernel_selection,
kernels_by_name,
kernels_by_language,
default_kernel,
closestKernel
});
};

show_select_kernel = (): void => {
this.update_select_kernel_data();
// we might not have the "kernels" data yet (but we will, once fetching it is complete)
// the select dialog will show a loading spinner
this.setState({
show_kernel_selector: true
});
};

hide_select_kernel = (): void => {
this.setState({
show_kernel_selector: false,
Expand Down
3 changes: 3 additions & 0 deletions src/smc-webapp/jupyter/main.tsx
Expand Up @@ -80,6 +80,7 @@ interface JupyterEditorProps {
show_kernel_selector?: boolean;
kernel_selection?: immutable.Map<string, any>;
kernels_by_name?: immutable.OrderedMap<string, immutable.Map<string, string>>;
kernels_by_language?: immutable.OrderedMap<string, immutable.List<string>>;
default_kernel?: string;
closestKernel?: TKernel;
}
Expand Down Expand Up @@ -130,6 +131,7 @@ class JupyterEditor0 extends Component<JupyterEditorProps> {
show_kernel_selector: rtypes.bool,
kernel_selection: rtypes.immutable.Map,
kernels_by_name: rtypes.immutable.Map,
kernels_by_language: rtypes.immutable.Map,
default_kernel: rtypes.string,
closestKernel: rtypes.immutable.Map
}
Expand Down Expand Up @@ -349,6 +351,7 @@ class JupyterEditor0 extends Component<JupyterEditorProps> {
kernel_info={this.props.kernel_info}
kernel_selection={this.props.kernel_selection}
kernels_by_name={this.props.kernels_by_name}
kernels_by_language = {this.props.kernels_by_language}
default_kernel={this.props.default_kernel}
closestKernel={this.props.closestKernel}
/>
Expand Down

0 comments on commit af10762

Please sign in to comment.