jupytext-notebook-helper
Small runtime helpers for teaching notebooks written in the jupytext percent
format and built with jupytext-filter (student/teacher/colab versions).
Extracted from master_mind.teaching.utils so it can be reused across courses
without pulling in the whole master-mind framework.
from jupytext_notebook_helper import * # test_mode, skip_plots, print_header, is_notebook
test_mode/skip_plots— driven by theTESTING_MODEenv var (off|on|full).print_header(title)— formatted header when run as a script; jupytext-filter turns it into a markdown header in notebooks.- On script execution (e.g.
make check),matplotlib.pyplot.show()is patched to render figures inline in the terminal viaimgcat.
Intended to be imported from a teacher-only cell: students never see the test-mode machinery, and the package is not required on Colab.
Imports in the build
The filter (python -m jupytext_notebook_helper.filter) manages imports by
parsing the source — no explicit imports/copy cell tags are needed
anymore (they still work but warn that they are redundant).
Imports can live anywhere; they are gathered automatically. You no longer
have to keep imports in a dedicated cell (the old imports-tagged section):
put each import next to the code that first needs it, in any cell. Every
top-level import across all cells is collected, de-duplicated, and emitted in
one place — the cell containing the # [[imports]] marker if you add one (to
control where the block lands), otherwise a cell inserted just before the first
code cell. The original import lines are removed from wherever they appeared:
# %% [markdown]
# ## Part 1
# %%
import numpy as np # gathered — moved out of this cell
x = np.zeros(3)
# %% [markdown]
# ## Part 2
# %%
from collections import defaultdict # gathered from here too
counts = defaultdict(int)
Both imports end up together in a single imports cell, while the cells above
keep only x = np.zeros(3) and counts = defaultdict(int). Add a
# [[imports]] marker cell if you want to choose exactly where that block goes.
If the same module/symbol is pulled in under more than one alias, the build
logs a warning. Imports inside [[remove]] / [[student]] blocks are left in
place, so teacher-only imports never leak into the shared cell. Imports nested
inside a function or if are also left alone — only module-level (top-level)
imports are gathered.
Internal library imports are inlined (with dependency tracking). An import
whose module resolves to a file under --src-root (default src/) is treated
as internal: instead of importing it, the filter copies the requested symbols
straight into the notebook. Only what you ask for — plus its transitive
dependencies — is copied, so unused and side-effectful top-level code in the
library module is left behind:
# src/mylib.py
import numpy as np
CONST = 3
def _scale(x): return x * CONST
def area(r): return _scale(np.pi) * r
def unused(): ... # never copied
# %% in the notebook
from mylib import area # -> `CONST`, `_scale`, `area` inlined here;
# `import numpy as np` added to the imports cell
Use targeted imports (from mylib import area, plot) instead of
from mylib import *; * still works and inlines every public symbol. Inlined
modules become Makefile build dependencies, so notebooks rebuild when a library
module changes.
Whole-module inclusion for dotted use. When you want to keep interacting
with a module by its dotted name, import mylib.my.module includes the whole
module as a real module object, so mylib.my.module.foo() keeps working exactly
like a normal import (no tree-shaking — the entire module, side effects and all,
travels with the notebook; any internal modules it imports come along too):
# %% in the notebook
import mylib.my.module
mylib.my.module.foo() # dotted access preserved
Use from mylib.my.module import foo when you only want foo (tree-shaken, no
side effects); use import mylib.my.module when you want the full module and
dotted interaction.
Testing: three levels
make check— runs each source as a script, importing internal helpers normally fromsrc/. Fast, but because the whole module is importable it cannot reveal a missing inlined dependency.make check-resolved(python -m jupytext_notebook_helper.run) — runs each source with internal imports resolved to the inlined subset, i.e. exactly the code a student notebook will contain. A tree-shaking bug then surfaces as aNameError— reported at the real source location, because every chunk is compiled against the file it came from (notebook cell →.py; inlined symbol → itssrc/module).- Building the notebook itself is the final level.
Both check and check-resolved accept a single source, e.g.
make check-resolved:tp1-embeddings, and record pass/fail (make show-tests
/ make show-resolved).
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jupytext_notebook_helper-0.3.1.tar.gz.
File metadata
- Download URL: jupytext_notebook_helper-0.3.1.tar.gz
- Upload date:
- Size: 36.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e33ccd7656f58cbd1481345b6a7f1d4928390a1adae57b06aa6fd9170deba875
|
|
| MD5 |
5dc23fddfafb05836def5840aeae4b4c
|
|
| BLAKE2b-256 |
3efbc0f1d811865c9585eb301728a89b0e6a3ddcd44c487d0fd884ff6156bfc8
|
Provenance
The following attestation bundles were made for jupytext_notebook_helper-0.3.1.tar.gz:
Publisher:
python-publish.yml on bpiwowar/jupytext-notebook-helper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jupytext_notebook_helper-0.3.1.tar.gz -
Subject digest:
e33ccd7656f58cbd1481345b6a7f1d4928390a1adae57b06aa6fd9170deba875 - Sigstore transparency entry: 2084719544
- Sigstore integration time:
-
Permalink:
bpiwowar/jupytext-notebook-helper@280d82445d93db71ee25f0ca1173bf69c989ca23 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/bpiwowar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@280d82445d93db71ee25f0ca1173bf69c989ca23 -
Trigger Event:
release
-
Statement type:
File details
Details for the file jupytext_notebook_helper-0.3.1-py3-none-any.whl.
File metadata
- Download URL: jupytext_notebook_helper-0.3.1-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22e77b00d4387fed43fd6e464f983ebede87c0f9151735fd1f2743189ac80f6d
|
|
| MD5 |
88febf1326625af2d184150ec6bdff97
|
|
| BLAKE2b-256 |
e22414840b315bcb70478565678c89bbf14dfb78e8c5f84e2533f3b4afc3cefe
|
Provenance
The following attestation bundles were made for jupytext_notebook_helper-0.3.1-py3-none-any.whl:
Publisher:
python-publish.yml on bpiwowar/jupytext-notebook-helper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jupytext_notebook_helper-0.3.1-py3-none-any.whl -
Subject digest:
22e77b00d4387fed43fd6e464f983ebede87c0f9151735fd1f2743189ac80f6d - Sigstore transparency entry: 2084719581
- Sigstore integration time:
-
Permalink:
bpiwowar/jupytext-notebook-helper@280d82445d93db71ee25f0ca1173bf69c989ca23 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/bpiwowar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@280d82445d93db71ee25f0ca1173bf69c989ca23 -
Trigger Event:
release
-
Statement type: