Add a nanopy command and make demos importable by name - #20
Open
zamkorus wants to merge 3 commits into
Open
Conversation
zamkorus
force-pushed
the
importable-demos
branch
from
July 27, 2026 16:43
20551b8 to
b9a12dd
Compare
Demos could only be run as scripts, and picking an MP4 export example
meant uncommenting a call at the bottom of the file.
Every demo is now a documented function exported from NaNoPy.demos:
from NaNoPy.demos import dots
help(dots) # explains what the demo shows
dots() # runs it
- Add module and demo() docstrings to every demo, written for students.
- Wrap the demos that ran at import time (mac_arm_ball, multiple_ball,
warning_deprecated, font_bug_on_graph_window) in demo(), so importing
NaNoPy.demos never opens a window. All demos stay runnable standalone.
- Select MP4 export examples with argparse instead of uncommenting code,
and expose them as mp4_bouncing_ball, mp4_rotating_square,
mp4_advanced_recording and mp4_with_audio.
- Turn the collision benchmark __main__ block into collision_benchmark()
and export the six variants as collision_*.
- Add a DEMOS registry, list_demos(), and a python -m NaNoPy.demos CLI.
- Release the canvas in the two demos that end without the window being
closed, so calling demos back to back works in one session.
Closes #19
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
zamkorus
force-pushed
the
importable-demos
branch
from
July 27, 2026 16:59
b9a12dd to
f8d8016
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #19.
Why
Demos could only be run as scripts, and picking one of the MP4 export examples
meant uncommenting a call at the bottom of the file (#19).
What students get
A
nanopycommand, installed with the package:NaNoPyis installed as a second name for the same command, andpython -m NaNoPyworks when the executable is not onPATH.Every demo is also an importable, documented function:
Each demo file still runs standalone (
python -m NaNoPy.demos.dots).Changes
NaNoPy/cli.pyholds the CLI, declared under[project.scripts]as bothnanopyandNaNoPy.python -m NaNoPyandpython -m NaNoPy.demosdelegate to it. Running it with no demo lists them and exits 0.
demo()docstrings on every demo, written for students;help(<demo>)is the intended way to find out what a demo does.
NaNoPy/demos/__init__.pyexports each demo under its own name, plus aDEMOSregistry,
list_demos(), anddemo_summary().mac_arm_ball,multiple_ball,warning_deprecated,font_bug_on_graph_window) are wrapped indemo(), soimporting
NaNoPy.demosnever opens a window.(Having to uncomment is not elegant. Use argparse to handle this instead. #19), and exported as
mp4_bouncing_ball,mp4_rotating_square,mp4_advanced_recording,mp4_with_audio.__main__benchmark becamecollision_benchmark(); the sixvariants are exported as
collision_*.input.py's demo is exported askeyboard_inputso it does not shadow theinputbuiltin.so demos can be called back to back in one session.
Tests
tests/test_demos_package.pycovers: every demo is callable and documented, theregistry matches the exported names, importing every demo module creates no canvas
and does not initialize SDL, every demo file keeps its
__main__entry point, andthe CLI lists/selects/rejects demos.
tests/test_mp4_export_examples.pycovers theMP4 example CLI.
91 tests pass;
ruff check,ruff format --check, andpyright(strict) are clean.Every demo was smoke-run headless with
SDL_VIDEODRIVER=dummy, and the installednanopycommand was verified end to end.Note:
[project.scripts]only takes effect after a reinstall, so existingcheckouts need
uv pip install -e ".[interactive]"(orpip install -e .) oncebefore
nanopyappears onPATH.