Skip to content

Commit 937257c

Browse files
authored
Merge pull request #2 from glue-viz/fully-automated
Add ability to run in fully automated mode
2 parents 824358b + 0e40a53 commit 937257c

File tree

19 files changed

+556
-112
lines changed

19 files changed

+556
-112
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions" # See documentation for possible values
9+
directory: ".github/workflows" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
groups:
13+
actions:
14+
patterns:
15+
- "*"

.github/workflows/main.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Automated test
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
8+
jobs:
9+
test:
10+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
11+
with:
12+
envs: |
13+
- linux: py310-test
14+
- linux: py311-test
15+
- linux: py312-test
16+
- linux: py313-test
17+
- macos: py310-test
18+
- macos: py311-test
19+
- macos: py312-test
20+
- macos: py313-test
21+
- windows: py312-test
22+
- windows: py313-test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ __pycache__
44
dist
55
build
66
.ipynb_checkpoints
7+
__pycache__

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
ci:
2+
autofix_prs: false
3+
autoupdate_schedule: 'monthly'
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.5.0
8+
hooks:
9+
- id: check-added-large-files
10+
args: ["--enforce-all", "--maxkb=300"]
11+
- id: check-case-conflict
12+
- id: check-json
13+
- id: check-merge-conflict
14+
- id: check-symlinks
15+
- id: check-toml
16+
- id: check-xml
17+
- id: check-yaml
18+
exclude: ".*(.github.*)$"
19+
- id: detect-private-key
20+
- id: end-of-file-fixer
21+
exclude: ".*(data.*|extern.*|licenses.*|_static.*|_parsetab.py)$"
22+
- id: trailing-whitespace
23+
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
rev: "v0.3.4"
26+
hooks:
27+
- id: ruff
28+
args: ["--fix", "--show-fixes"]
29+
- id: ruff-format

README.md

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
11
This repository contains an experimental utility to monitor the visual output of
22
cells from Jupyter notebooks.
33

4-
## Requirements
5-
6-
On the machine being used to run the ``monitor_cells.py``:
4+
## Installing
75

8-
* [numpy](https://numpy.org)
9-
* [click](https://click.palletsprojects.com/en/stable/)
10-
* [pillow](https://python-pillow.org/)
11-
* [playwright](https://pypi.org/project/playwright/)
6+
To install, check out this repository and:
127

13-
On the Jupyter Lab server, optionally (but recommended):
8+
pip install -e .
149

15-
* [jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration)
10+
Python 3.10 or later is supported (Python 3.12 or later on Windows).
1611

17-
If this is the first time using playwright, you will need to run::
12+
If this is the first time using playwright, you will also need to run:
1813

1914
playwright install firefox
2015

21-
## Installing
16+
## Quick start
2217

23-
To install, check out this repository and:
18+
First, write one or more blocks of code you want to benchmark each in a cell. In
19+
addition, as early as possible in the notebook, make sure you set the border
20+
color on any ipywidget layout you want to record:
2421

25-
pip install -e .
22+
widget.layout.border = '1px solid rgb(143, 56, 3)'
23+
24+
The R and G values should be kept as (143, 56), and the B color should be unique for each widget and be a value between 0 and 255 (inclusive).
25+
26+
Then, to run the notebook and monitor the changes in widget output, run:
27+
28+
jupyter-output-monitor --notebook mynotebook.ipynb
29+
30+
Where ``mynotebook.ipynb`` is the name of your notebook. By default, this will
31+
open a window showing you what is happening, but you can also pass ``--headless``
32+
to run in headless mode.
33+
34+
## Using this on a remote Jupyter Lab instance
35+
36+
If you want to test this on an existing Jupyter Lab instance, including
37+
remote ones, you can use ``--url`` instead of ``--notebook``:
38+
39+
jupyter-output-monitor http://localhost:8987/lab/tree/notebook.ipynb?token=7bb9a...
40+
41+
Note that the URL should include the path to the notebook, and will likely
42+
require the token too.
43+
44+
You should make sure that all output cells in the notebook have been cleared
45+
before running the above command, and that the widget border color has been
46+
set as mention in the **Quick start** guide above.
47+
48+
If you make use of the [jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration) plugin on the Jupyter Lab server, you will be able to
49+
more easily e.g. clear the output between runs and edit the notebook in
50+
between runs of ``jupyter-output-monitor``.
2651

2752
## How this works
2853

@@ -83,46 +108,8 @@ and if using jdaviz:
83108
To stop recording output for a given cell, you can set the border attribute to
84109
``''``.
85110

86-
## Headless vs non-headless mode
87-
88-
By default, the script will open up a window and show what it is doing. It will
89-
also wait until it detects any input cells before proceeding. This then gives
90-
you the opportunity to enter any required passwords, and open the correct
91-
notebook. However, note that if Jupyter Lab opens up with a different notebook
92-
to the one you want by default, it will start executing that one! It's also
93-
better if the notebook starts off with output cells cleared, otherwise the script
94-
may start taking screenshots straight away.
95-
96-
The easiest way to ensure that the correct notebook gets executed and that it
97-
has had its output cells cleared is to make use of the
98-
[jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration)
99-
plugin. With this plugin installed, you can open Jupyter Lab in a regular browser window,
100-
and set it up so that the correct notebook is open by default and has its cells cleared,
101-
and you can then launch the monitoring script. In fact, if you do this you can then
102-
also run the script in headless mode since you know it should be doing the right thing.
103-
104-
One final note is that to avoid any jumping up and down of the notebook during
105-
execution, the window opened by the script has a very large height so that the
106-
full notebook fits inside the window without scrolling.
107-
108-
## How to use
109-
110-
* Assuming you have installed
111-
[jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration),
112-
start up Jupyter Lab instance on a regular browser and go to the notebook you
113-
want to profile.
114-
* If not already done, write one or more blocks of code you want to benchmark
115-
each in a cell. In addition, as early as possible in the notebook, make sure
116-
you set the border color on any ipywidget layout you want to record.
117-
* Make sure the notebook you want to profile is the main one opened and that
118-
you have cleared any output cells.
119-
* Run the main command in this package, specifying the URL to connect to for Jupyter Lab, e.g.:
120-
121-
jupyter-output-monitor http://localhost:8987
122-
123111
## Settings
124112

125-
126113
### Headless
127114

128115
To run in headless mode, include ``--headless``

jupyter_output_monitor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from ._monitor import monitor
22
from ._version import __version__
3+
4+
__all__ = ["monitor", "__version__"]

jupyter_output_monitor/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from ._monitor import monitor
2+
3+
if __name__ == "__main__":
4+
monitor()
-303 Bytes
Binary file not shown.
-7.62 KB
Binary file not shown.
-690 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)