Skip to content

Commit 1ea8135

Browse files
committed
update installation to use jupyter-packaging
should install/enable all extensions at install time no longer need `ipcluster nbextension` entrypoint, but it's still there
1 parent acd0cd8 commit 1ea8135

File tree

15 files changed

+9065
-100
lines changed

15 files changed

+9065
-100
lines changed

CONTRIBUTING.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
# Contributing
22

3-
We follow the [IPython Contributing Guide](https://github.com/ipython/ipython/blob/master/CONTRIBUTING.md).
3+
We follow the [Jupyter Contributing Guide](https://jupyter.readthedocs.io/en/latest/contributing/content-contributor.html).
4+
5+
Make sure to follow the [Jupyter Code of Conduct](https://jupyter.org/conduct/).
6+
7+
## Development install
8+
9+
A basic development install of IPython parallel
10+
is the same as almost all Python packages:
11+
12+
```bash
13+
pip install -e .
14+
```
15+
16+
To enable the server extension from a development install:
17+
18+
```bash
19+
# for jupyterlab
20+
jupyter server extension enable --sys-prefix ipyparallel
21+
# for classic notebook
22+
jupyter serverextension enable --sys-prefix ipyparallel
23+
```
24+
25+
As described in the [JupyterLab documentation](https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#developing-a-prebuilt-extension)
26+
for a development install of the jupyterlab extension you can run the following in this directory:
27+
28+
```bash
29+
jlpm # Install npm package dependencies
30+
jlpm build # Compile the TypeScript sources to Javascript
31+
jupyter labextension develop . --overwrite # Install the current directory as an extension
32+
```
33+
34+
If you are working on the lab extension,
35+
you can run jupyterlab in dev mode to always rebuild and reload your extensions.
36+
In two terminals, run:
37+
38+
```bash
39+
[term 1] $ jlpm watch
40+
[term 2] $ jupyter lab --extensions-in-dev-mode
41+
```
42+
43+
You should then be able to refresh the JupyterLab page
44+
and it will pick up the changes to the extension as you work.

MANIFEST.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ include COPYING.md
22
include CONTRIBUTING.md
33
include README.md
44

5+
# enable-at-install config
56
graft etc
67

8+
# lab extension
9+
graft lab
10+
prune lab/lib
11+
include install.json
12+
include package*.json
13+
include tsconfig*.json
14+
graft ipyparallel/labextension
15+
16+
717
# Documentation
818
graft docs
919

@@ -19,3 +29,4 @@ global-exclude *.pyc
1929
global-exclude *.pyo
2030
global-exclude .git
2131
global-exclude .ipynb_checkpoints
32+
global-exclude .DS_Store

README.md

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
11
# Interactive Parallel Computing with IPython
22

3-
ipyparallel is the new home of IPython.parallel. ipyparallel is a Python package and collection of CLI scripts for controlling clusters for Jupyter.
3+
IPython Parallel (`ipyparallel`) is a Python package and collection of CLI scripts for controlling clusters of IPython processes, built on the Jupyter protocol.
44

5-
ipyparallel contains the following CLI scripts:
5+
IPython Parallel provides the following commands:
66

7-
- ipcluster - start/stop a cluster
8-
- ipcontroller - start a scheduler
7+
- ipcluster - start/stop/list clusters
8+
- ipcontroller - start a controller
99
- ipengine - start an engine
1010

1111
## Install
1212

13-
Install ipyparallel:
13+
Install IPython Parallel:
1414

1515
pip install ipyparallel
1616

17-
To enable the `IPython Clusters` tab in Jupyter Notebook:
18-
19-
ipcluster nbextension enable
20-
21-
To disable it again:
22-
23-
ipcluster nbextension disable
24-
25-
See the [documentation on configuring the notebook server](https://jupyter-notebook.readthedocs.io/en/latest/public_server.html)
26-
to find your config or setup your initial `jupyter_notebook_config.py`.
27-
28-
### JupyterHub Install
29-
30-
To install for all users on JupyterHub, as root:
31-
32-
jupyter nbextension install --sys-prefix --py ipyparallel
33-
jupyter nbextension enable --sys-prefix --py ipyparallel
34-
jupyter serverextension enable --sys-prefix --py ipyparallel
17+
This will install and enable the IPython Parallel extensions
18+
for Jupyter Notebook and (as of 7.0) Jupyter Lab 3.0.
3519

3620
## Run
3721

@@ -45,9 +29,10 @@ Use it from Python:
4529
import os
4630
import ipyparallel as ipp
4731

48-
rc = ipp.Client()
49-
ar = rc[:].apply_async(os.getpid)
50-
pid_map = ar.get_dict()
32+
cluster = ipp.Cluster(n=4)
33+
with cluster as rc:
34+
ar = rc[:].apply_async(os.getpid)
35+
pid_map = ar.get_dict()
5136
```
5237

5338
See [the docs](https://ipyparallel.readthedocs.io) for more info.

etc/ipyparallel-serverextension.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"NotebookApp": {
33
"nbserver_extensions": {
4-
"ipyparallel.nbextension": true
4+
"ipyparallel": true
55
}
66
}
77
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ServerApp": {
33
"jpserver_extensions": {
4-
"ipyparallel.nbextension": true
4+
"ipyparallel": true
55
}
66
}
77
}

ipyparallel/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def bind_kernel(**kwargs):
5050
else:
5151
return app.bind_kernel(**kwargs)
5252

53-
raise RuntimeError("bind_kernel be called from an IPEngine instance")
53+
raise RuntimeError("bind_kernel must be called from an IPEngine instance")
5454

5555

5656
def register_joblib_backend(name='ipyparallel', make_default=False):
@@ -62,7 +62,7 @@ def register_joblib_backend(name='ipyparallel', make_default=False):
6262

6363
# nbextension installation (requires notebook ≥ 4.2)
6464
def _jupyter_server_extension_paths():
65-
return [{'module': 'ipyparallel.nbextension'}]
65+
return [{'module': 'ipyparallel'}]
6666

6767

6868
def _jupyter_nbextension_paths():
@@ -83,3 +83,19 @@ def _jupyter_labextension_paths():
8383
"dest": "ipyparallel-labextension",
8484
}
8585
]
86+
87+
88+
def _load_jupyter_server_extension(app):
89+
"""Load the server extension"""
90+
# localte the appropriate APIHandler base class before importing our handler classes
91+
from .nbextension.base import get_api_handler
92+
93+
get_api_handler(app)
94+
95+
from .nbextension.handlers import load_jupyter_server_extension
96+
97+
return load_jupyter_server_extension(app)
98+
99+
100+
# backward-compat
101+
load_jupyter_server_extension = _load_jupyter_server_extension

ipyparallel/nbextension/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
from .handlers import load_jupyter_server_extension
1+
"""Jupyter server extension(s)"""
2+
import warnings
3+
4+
5+
def load_jupyter_server_extension(app):
6+
warnings.warn(
7+
"Using ipyparallel.nbextension as server extension is deprecated in IPython Parallel 7.0. Use top-level ipyparallel.",
8+
DeprecationWarning,
9+
)
10+
from ipyparallel import _load_jupyter_server_extension
11+
12+
return _load_jupyter_server_extension(app)

ipyparallel/nbextension/base.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Place to put the base Handler"""
2+
import warnings
3+
from functools import lru_cache
4+
5+
_APIHandler = None
6+
7+
8+
@lru_cache()
9+
def _guess_api_handler():
10+
"""Fallback to guess API handler by availability"""
11+
try:
12+
from notebook.base.handlers import APIHandler
13+
except ImportError:
14+
from jupyter_server.base.handlers import APIHandler
15+
global _APIHandler
16+
_APIHandler = APIHandler
17+
return _APIHandler
18+
19+
20+
def get_api_handler(app=None):
21+
"""Get the base APIHandler class to use
22+
23+
Inferred from app class (either jupyter_server or notebook app)
24+
"""
25+
global _APIHandler
26+
if _APIHandler is not None:
27+
return _APIHandler
28+
if app is None:
29+
warnings.warn(
30+
"Guessing base APIHandler class. Specify an app to ensure the right APIHandler is used.",
31+
stacklevel=2,
32+
)
33+
return _guess_api_handler()
34+
35+
top_modules = {cls.__module__.split(".", 1)[0] for cls in app.__class__.mro()}
36+
if "jupyter_server" in top_modules:
37+
from jupyter_server.base.handlers import APIHandler
38+
39+
_APIHandler = APIHandler
40+
return APIHandler
41+
if "notebook" in top_modules:
42+
from notebook.base.handlers import APIHandler
43+
44+
_APIHandler = APIHandler
45+
return APIHandler
46+
47+
warnings.warn(f"Failed to detect base APIHandler class for {app}.", stacklevel=2)
48+
return _guess_api_handler()

0 commit comments

Comments
 (0)