Skip to content

Commit

Permalink
Add support for newer versions of Jupyter ecosystem (#4)
Browse files Browse the repository at this point in the history
- Add support for nbconvert >= 6.0.0, including support for the new default template lab, the new light/dark themes (for lab-based templates), and the legacy template classic (both for nbconvert>=5.6.1,<6.0.0 and explicit template_name = 'classic' in nbconvert>=6.0.0)
- Add new template option: lab_narrow, which is based on the lab template but retains the centered, narrow body of the classic template (also supports light/dark themes)
- Add systematic testing of different (and newer) bundles of packages
- Fix when images are base64-encoded (instead of raw bytes)
- Fix inline mode when using static_ipywidgets
- Enable all linters
- Add py.typed
- Clean up demo notebooks and set up static demo page
- Simplify CI by switching from tox-gh-actions to tox labels (available in tox >= 4.0.0)
  • Loading branch information
yanovs authored Dec 22, 2022
1 parent 22aa127 commit 42313d7
Show file tree
Hide file tree
Showing 70 changed files with 449,655 additions and 499 deletions.
29 changes: 24 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# See:
# - https://github.com/ymyzk/tox-gh-actions/tree/master/.github/workflows
name: Test

on:
Expand All @@ -12,10 +10,13 @@ permissions:
contents: read

jobs:
# Run pytest and linters
# Run pytest, integration tests, and linters
test:
runs-on: ${{ matrix.platform }}

env:
LEDA_TEST_OUTPUT_DIR: ~/leda_outputs/

strategy:
fail-fast: false
matrix:
Expand All @@ -40,9 +41,27 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade setuptools pip wheel
python -m pip install tox-gh-actions
python -m pip install tox
- name: Test with tox
run: tox
run: tox -m ${{ matrix.python-version }}
if: ${{ ! (matrix.platform == 'windows-latest' && matrix.python-version == '3.8') && (matrix.python-version != 'pypy-3.8') }}
- name: Test with tox (Windows, py3.8)
# Skip integration tests on Windows/py3.8 because
# there are no pre-built Windows/py3.8/numpy1.6.6 wheels.
# TODO: Also skip pyright on Windows for now, but investigate later.
run: tox -e black,docformatter,flake8,isort,mypy,py38
if: ${{ matrix.platform == 'windows-latest' && matrix.python-version == '3.8' }}
- name: Test with tox (pypy3.8)
# TODO: Skip integration tests on pypy; investigate issues
run: tox -e pypy3
if: ${{ matrix.python-version == 'pypy-3.8' }}
- name: Upload failed outputs
uses: actions/upload-artifact@v3
with:
name: leda-outputs-${{ matrix.platform }}-${{ matrix.python-version}}
path: ~/leda_outputs/
retention-days: 1
if: ${{ failure() }}

# Test building and publishing
# See:
Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ python -m leda /path/to/nb.ipynb --output-dir ./outputs/ \

This will automatically include formatting tweaks, including, e.g., hiding all input code.

`-i` (`--inject`) is used to inject user code via a new cell prepended to the notebook during generation.
See the [**static demos** being served by GitHub Pages](leda/tests/integration/refs).

Think of it like [`voila`](https://voila.readthedocs.io/en/stable/using.html)
or [nbviewer](https://nbviewer.org/) but with widgets.
Think of it like:
- [`voila`](https://voila.readthedocs.io/en/stable/using.html) but static, with no need for live kernels
- [nbconvert](https://github.com/jupyter/nbconvert)/[nbviewer](https://nbviewer.org/) but with interactive widgets
- [pretty-jupyter](https://github.com/JanPalasek/pretty-jupyter) but with interactive widgets

`-i` (`--inject`) arg is used to inject user code (and set report params) via a new cell prepended to the notebook during generation.
And `--template_name`/`--theme` args allow you to choose between `classic`, `lab` (`light`/`dark`), and `lab_narrow` (`light`/`dark`).

**Note**: `leda` assumes that all code is run in a trusted environment, so please be careful.

Expand All @@ -33,9 +38,9 @@ or [nbviewer](https://nbviewer.org/) but with widgets.
that makes it easy to create outputs based on widgets, like:

```python
%%interact mult0=[1,2,3],mult1=[10,100,1000]
df = pd.DataFrame({"a": [1, 2, 3]}) * mult0 * mult1
df.plot(title=f"Foo: {mult0}, {mult1}")
%%interact column=list("abcdefghij");mult=[1, 2, 3]
df = pd.DataFrame(np.random.RandomState(42).rand(100, 10), columns=list("abcdefghij"))
(df[[column]] * mult).plot(figsize=(15, 8), lw=2, title=f\"column={column!r}, mult={mult}\")
```

There are two types of interact modes: dynamic and static. Dynamic mode is when you're running the Jupyter notebook
Expand All @@ -62,6 +67,8 @@ you could alternatively implement your own `leda.gen.base.ReportPublisher` and c

Another example is you can simply host a static S3 bucket, enable website hosting and then either use S3 as a web server publically or via locked down S3 endpoint.

You could also use [GitHub Pages](https://pages.github.com), much like the [static demos page](leda/tests/integration/refs).

### Params

Reports can be parametrized so that the user can set different values for each report run.
Expand Down Expand Up @@ -95,14 +102,10 @@ And with these static widget libraries:

## Testing

See the `requirements-bundle*.txt` for version bundles that we currently test manually.

The most important next task for leda development would be to
(1) automate testing generating reports (reports may contain many random strs that don't affect the output but make it impossible to do a simple `diff`),
and (2) expand the number of bundles being tested (especially to the newer versions).

(All of these bundles will be tested against Linux/macOS/Windows and various python versions.)
See the `requirements-bundle*.txt` for version bundles that we currently test systematically.

## Known Issues

- Not all widget states of `matplotlib` update when using `panel` static interact mode: https://github.com/holoviz/panel/issues/1222
- There are multiple issues using `matplotlib` with `panel`, including:
- The last widget output is not different from the penultimate one: https://github.com/holoviz/panel/issues/1222
- All the widget outputs show up sequentially, instead of being hidden until chosen. This seems to be a known issue per the [`panel` FAQ](https://panel.holoviz.org/FAQ.html); however, using the example fix provided does not work.
166 changes: 0 additions & 166 deletions demos/matplotlib_demo.ipynb

This file was deleted.

119 changes: 0 additions & 119 deletions demos/plotly_demo.ipynb

This file was deleted.

Loading

0 comments on commit 42313d7

Please sign in to comment.