Skip to content

Commit e18ef73

Browse files
authored
Merge pull request #1409 from jfbercher/code_prettify_no_alert
Code prettify (and all KernelExecOnCells plugins) --> option to disable alert if kernel is unsupported
2 parents 7302b4e + 57ee778 commit e18ef73

File tree

9 files changed

+44
-4
lines changed

9 files changed

+44
-4
lines changed

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/2to3.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Parameters:
3838
input_type: hotkey
3939
default: 'Ctrl-Shift-M'
4040

41+
- name: 2to3.show_alerts_for_not_supported_kernel
42+
description: Show alerts if the kernel is not supported
43+
input_type: checkbox
44+
default: false
45+
4146
- name: 2to3.show_alerts_for_errors
4247
description: Show alerts for errors in the kernel converting calls
4348
input_type: checkbox

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ History
284284
- [@artificialsoph], Jan 2018
285285
- updated documentation
286286
- changed default behavior to load custom yapf styles
287-
287+
- [@jfbercher], April 2019
288+
- corrected an issue in configs merge
289+
- added an option for displaying an alert if kernel is not supported and turned it off by default (instead issue a warning in the js console).
288290

289291
[2to3]: README_2to3.md
290292
[@jcb91]: https://github.com/jcb91

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/README_2to3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ The options are as follows:
5959
Hotkey to use to transform the selected cell(s).
6060
Defaults to `Ctrl-L`.
6161

62+
- `2to3.show_alerts_for_not_supported_kernel`:
63+
Whether to show alerts if the kernel is not supported.
64+
Defaults to `false`.
65+
6266
- `2to3.show_alerts_for_errors`:
6367
Whether to show alerts for errors in the kernel calls.
6468
Defaults to `true`.

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/README_autopep8.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ The options are as follows:
6565
Hotkey to use to transform the selected cell(s).
6666
Defaults to `Alt-A`.
6767

68+
- `autopep8.show_alerts_for_not_supported_kernel`:
69+
Whether to show alerts if the kernel is not supported.
70+
Defaults to `false`.
71+
6872
- `autopep8.show_alerts_for_errors`:
6973
Whether to show alerts for errors in the kernel calls.
7074
Defaults to `true`.

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/README_code_prettify.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ The options are as follows:
114114
Hotkey to use to transform the selected cell(s).
115115
Defaults to `Ctrl-L`.
116116

117+
- `code_prettify.show_alerts_for_not_supported_kernel`:
118+
Whether to show alerts if the kernel is not supported.
119+
Defaults to `false`.
120+
117121
- `code_prettify.show_alerts_for_errors`:
118122
Whether to show alerts for errors in the kernel calls.
119123
Defaults to `true`.

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/README_isort.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ All options are provided by the [KerneExecOnCells library](kernel_exec_on_cell.j
2525
See [fontawesome] for available icon classes.
2626
Defaults to `fa-sort`.
2727

28+
- `isort.show_alerts_for_not_supported_kernel`:
29+
Whether to show alerts if the kernel is not supported.
30+
Defaults to `false`.
31+
2832
- `isort.show_alerts_for_errors`: Whether to show alerts for errors in the kernel calls. Defaults to `false`.
2933

3034
- `isort.button_label`: Toolbar button label text. Also used in the actions' help text. Defaults to `Sort imports with isort`.

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/autopep8.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Parameters:
4141
input_type: hotkey
4242
default: 'Alt-Shift-A'
4343

44+
- name: autopep8.show_alerts_for_not_supported_kernel
45+
description: Show alerts if the kernel is not supported
46+
input_type: checkbox
47+
default: false
48+
4449
- name: autopep8.show_alerts_for_errors
4550
description: Show alerts for errors in the kernel prettifying calls
4651
input_type: checkbox

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/code_prettify.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Parameters:
4141
input_type: hotkey
4242
default: 'Ctrl-Shift-L'
4343

44+
- name: code_prettify.show_alerts_for_not_supported_kernel
45+
description: Show alerts if the kernel is not supported
46+
input_type: checkbox
47+
default: false
48+
4449
- name: code_prettify.show_alerts_for_errors
4550
description: Show alerts for errors in the kernel prettifying calls
4651
input_type: checkbox

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/kernel_exec_on_cell.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ define([
3939
},
4040
register_hotkey: true,
4141
show_alerts_for_errors: true,
42+
show_alerts_for_not_supported_kernel: false,
4243
button_icon: 'fa-legal',
4344
button_label: mod_name,
4445
kbd_shortcut_text: mod_name,
@@ -47,7 +48,7 @@ define([
4748
};
4849
// extend a new object, to avoid interference with other nbextensions
4950
// derived from the same base class
50-
this.cfg = $.extend(true, {}, cfg, default_cfg);
51+
this.cfg = $.extend(true, {}, default_cfg, cfg);
5152
// set default json string, will later be updated from config
5253
// before it is parsed into an object
5354
this.cfg.kernel_config_map_json = JSON.stringify(this.cfg.kernel_config_map);
@@ -258,10 +259,16 @@ define([
258259
var kernel_config = this.cfg.kernel_config_map[kernelLanguage];
259260
if (kernel_config === undefined) {
260261
$('#' + this.mod_name + '_button').remove();
261-
alert(this.mod_log_prefix + " Sorry, can't use kernel language " + kernelLanguage + ".\n" +
262+
var err = this.mod_log_prefix + " Sorry, can't use kernel language " + kernelLanguage + ".\n" +
262263
"Configurations are currently only defined for the following languages:\n" +
263264
Object.keys(this.cfg.kernel_config_map).join(', ') + "\n" +
264-
"See readme for more details.");
265+
"See readme for more details."
266+
if (this.cfg.show_alerts_for_not_supported_kernel) {
267+
alert(err);
268+
}
269+
else {
270+
console.error(err);
271+
}
265272
// also remove keyboard shortcuts
266273
if (this.cfg.register_hotkey) {
267274
try {

0 commit comments

Comments
 (0)