Skip to content

Commit 223cfbf

Browse files
authored
Merge pull request #1180 from jcb91/install
[install] don't check for running notebook servers when installing
2 parents dc55437 + aefff02 commit 223cfbf

File tree

5 files changed

+40
-29
lines changed

5 files changed

+40
-29
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ config-editing operations, or only the file-copy operations:
167167
- `jupyter_notebook_config.json` to enable the serverextension
168168
`jupyter_nbextensions_configurator`.
169169

170-
Finally, the `--skip-running-check` option flag is provided in order to allow
171-
the installation to proceed even if a notebook server appears to be currently
172-
running (by default, the install will not be performed if a notebook server
170+
Finally, the `--perform-running-check` option flag is provided in order to
171+
prevent the installation from proceeding if a notebook server appears to be
172+
currently running
173+
(by default, the install will still be performed, even if a notebook server
173174
appears to be running).
174175

175176
An analogous `uninstall` command is also provided, to remove all of the

docs/source/install.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ config-editing operations, or only the file-copy operations:
9999
- `jupyter_notebook_config.json` to enable the serverextension
100100
`jupyter_nbextensions_configurator`.
101101

102-
Finally, the `--skip-running-check` option flag is provided in order to allow
103-
the installation to proceed even if a notebook server appears to be currently
104-
running (by default, the install will not be performed if a notebook server
102+
Finally, the `--perform-running-check` option flag is provided in order to
103+
prevent the installation from proceeding if a notebook server appears to be
104+
currently running
105+
(by default, the install will still be performed, even if a notebook server
105106
appears to be running).
106107

107108
An analogous `uninstall` command is also provided, to remove all of the

docs/source/troubleshooting.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ repository, some old files might be left on your system. This can lead, for
66
example, to having all the nbextensions listed twice on the configurator page.
77

88

9-
Cannot configure while the Jupyter notebook server is running
10-
-------------------------------------------------------------
11-
If you get this error message during installation, a running instance of the
12-
Jupyter notebook server has been detected. You can check this by running
13-
14-
jupyter notebook list
15-
16-
Sometimes the result can be incorrect. So if you are sure you have no notebook
17-
servers running, you can force the notebook extension installation step using the
18-
`--skip-running-check` prefix. For example:
19-
20-
jupyter contrib nbextensions install --sys-prefix --skip-running-check
21-
229
Removing Double Entries
2310
-----------------------
2411
The nbextensions from older versions will be located in the `nbextensions`

src/jupyter_contrib_nbextensions/application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class BaseContribNbextensionsInstallApp(BaseContribNbextensionsApp):
7777
{'skip_running_check': True}},
7878
'Perform actions even if notebook server(s) are already running'
7979
),
80+
'perform-running-check': (
81+
{'BaseContribNbextensionsInstallApp':
82+
{'skip_running_check': False}},
83+
'Only perform actions if no notebook server(s) are running'
84+
),
8085
}
8186

8287
_conflicting_flagsets = [['--user', '--system', '--sys-prefix'], ]
@@ -98,7 +103,7 @@ class BaseContribNbextensionsInstallApp(BaseContribNbextensionsApp):
98103
help='Full path to nbextensions dir '
99104
'(consider instead using system, sys_prefix, prefix or user option)')
100105
skip_running_check = Bool(
101-
False, config=True,
106+
True, config=True,
102107
help='Perform actions even if notebook server(s) are already running')
103108

104109
def parse_command_line(self, argv=None):

src/jupyter_contrib_nbextensions/install.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def toggle_install(install, user=False, sys_prefix=False, overwrite=False,
3737
symlink=False, prefix=None, nbextensions_dir=None,
3838
logger=None, skip_running_check=False):
3939
"""Install or remove all jupyter_contrib_nbextensions files & config."""
40-
if not skip_running_check and notebook_is_running():
41-
raise NotebookRunningError(
42-
'Cannot configure while the Jupyter notebook server is running')
40+
_err_on_running(skip_running_check=skip_running_check)
4341
_check_conflicting_kwargs(user=user, sys_prefix=sys_prefix, prefix=prefix,
4442
nbextensions_dir=nbextensions_dir)
4543
toggle_install_files(
@@ -55,9 +53,7 @@ def toggle_install_files(install, user=False, sys_prefix=False, logger=None,
5553
overwrite=False, symlink=False, prefix=None,
5654
nbextensions_dir=None, skip_running_check=False):
5755
"""Install/remove jupyter_contrib_nbextensions files."""
58-
if not skip_running_check and notebook_is_running():
59-
raise NotebookRunningError(
60-
'Cannot configure while the Jupyter notebook server is running')
56+
_err_on_running(skip_running_check=skip_running_check)
6157
kwargs = dict(user=user, sys_prefix=sys_prefix, prefix=prefix,
6258
nbextensions_dir=nbextensions_dir)
6359
_check_conflicting_kwargs(**kwargs)
@@ -84,9 +80,7 @@ def toggle_install_files(install, user=False, sys_prefix=False, logger=None,
8480
def toggle_install_config(install, user=False, sys_prefix=False,
8581
skip_running_check=False, logger=None):
8682
"""Install/remove contrib nbextensions to/from jupyter_nbconvert_config."""
87-
if not skip_running_check and notebook_is_running():
88-
raise NotebookRunningError(
89-
'Cannot configure while the Jupyter notebook server is running')
83+
_err_on_running(skip_running_check=skip_running_check)
9084
_check_conflicting_kwargs(user=user, sys_prefix=sys_prefix)
9185
config_dir = nbextensions._get_config_dir(user=user, sys_prefix=sys_prefix)
9286
if logger:
@@ -172,6 +166,29 @@ def uninstall(user=False, sys_prefix=False, prefix=None, nbextensions_dir=None,
172166
# -----------------------------------------------------------------------------
173167

174168

169+
def _err_on_running(skip_running_check=False, runtime_dir=None):
170+
if skip_running_check:
171+
return
172+
try:
173+
srv = next(list_running_servers(runtime_dir=runtime_dir))
174+
except StopIteration:
175+
return
176+
177+
raise NotebookRunningError("""
178+
Will not configure while a Jupyter notebook server appears to be running.
179+
At least this server appears to be running:
180+
181+
{}
182+
183+
Note that the json file indicating that this server is running may
184+
be stale, see
185+
186+
https://github.com/jupyter/notebook/issues/2829
187+
188+
for further details.
189+
""".format(srv))
190+
191+
175192
def _check_conflicting_kwargs(**kwargs):
176193
if sum(map(bool, kwargs.values())) > 1:
177194
raise nbextensions.ArgumentConflict(

0 commit comments

Comments
 (0)