Skip to content

Add a nanopy command and make demos importable by name - #20

Open
zamkorus wants to merge 3 commits into
masterfrom
importable-demos
Open

Add a nanopy command and make demos importable by name#20
zamkorus wants to merge 3 commits into
masterfrom
importable-demos

Conversation

@zamkorus

@zamkorus zamkorus commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

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 nanopy command, installed with the package:

nanopy                 # list every demo with a one-line description
nanopy dots            # run one demo
nanopy --version

NaNoPy is installed as a second name for the same command, and
python -m NaNoPy works when the executable is not on PATH.

Every demo is also an importable, documented function:

from NaNoPy.demos import dots

help(dots)   # explains what the demo shows
dots()       # runs it
from NaNoPy.demos import list_demos
list_demos()

Each demo file still runs standalone (python -m NaNoPy.demos.dots).

Changes

  • NaNoPy/cli.py holds the CLI, declared under [project.scripts] as both
    nanopy and NaNoPy. python -m NaNoPy and python -m NaNoPy.demos
    delegate to it. Running it with no demo lists them and exits 0.
  • Module and demo() docstrings on every demo, written for students; help(<demo>)
    is the intended way to find out what a demo does.
  • NaNoPy/demos/__init__.py exports each demo under its own name, plus a DEMOS
    registry, list_demos(), and demo_summary().
  • Demos that executed at import time (mac_arm_ball, multiple_ball,
    warning_deprecated, font_bug_on_graph_window) are wrapped in demo(), so
    importing NaNoPy.demos never opens a window.
  • MP4 export examples are selected with argparse instead of uncommenting code
    (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.
  • The collision __main__ benchmark became collision_benchmark(); the six
    variants are exported as collision_*.
  • input.py's demo is exported as keyboard_input so it does not shadow the
    input builtin.
  • The two demos that end without the window being closed now release their canvas,
    so demos can be called back to back in one session.

Tests

tests/test_demos_package.py covers: every demo is callable and documented, the
registry matches the exported names, importing every demo module creates no canvas
and does not initialize SDL, every demo file keeps its __main__ entry point, and
the CLI lists/selects/rejects demos. tests/test_mp4_export_examples.py covers the
MP4 example CLI.

91 tests pass; ruff check, ruff format --check, and pyright (strict) are clean.
Every demo was smoke-run headless with SDL_VIDEODRIVER=dummy, and the installed
nanopy command was verified end to end.

Note: [project.scripts] only takes effect after a reinstall, so existing
checkouts need uv pip install -e ".[interactive]" (or pip install -e .) once
before nanopy appears on PATH.

@zamkorus zamkorus self-assigned this Jul 27, 2026
@zamkorus zamkorus changed the title Make demos importable by name with student-facing docstrings Add a nanopy command and make demos importable by name Jul 27, 2026
zamkorus and others added 2 commits July 27, 2026 18:59
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
zamkorus requested a review from LeanderLutze July 29, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Having to uncomment is not elegant. Use argparse to handle this instead.

1 participant