Skip to content

runnable: runnable.args, sys.argv from the title, a quiet sys.exit() and COLUMNS from the panel width - #43

Merged
ewels merged 5 commits into
mainfrom
run-code-cli
Nov 18, 2026
Merged

ewels merged 5 commits into
mainfrom
run-code-cli

Conversation

@ewels

@ewels ewels commented Nov 18, 2026

Copy link
Copy Markdown
Owner

A Click or Typer command in a runnable block now runs with the code of a real file. Authors no longer add standalone_mode=False, prog_name or os.environ["COLUMNS"] to their examples. This replaces the workarounds that #40 documented.

The Click example after Run code

  • runnable.args
    • A new fence attribute: runnable.args="--count 2 'Ada Lovelace'". It splits as a shell splits words, so quotes keep spaces in an argument. A quote that does not close gives a build warning.
    • The Python runtime sets sys.argv to the title of the block and the arguments, as python hello.py --count 2 does. A block with no title runs as main.py. So the usage line of Click, Typer and argparse names the program, with no prog_name.
    • The JavaScript and TypeScript runtimes ignore the arguments.
  • sys.exit()
    • A Python run handles SystemExit as CPython does: no traceback, and only an exit message that is not a number shows, on standard error. --help in a Click command no longer shows a SystemExit: 0 traceback.
    • A session block (>>>) stops at sys.exit(), as the REPL does.
    • Normal runs now go through eval_code_async in a Python helper, in place of runPythonAsync. The helper has the file name <scb>, so the existing traceback trimming drops its frames.
  • COLUMNS
    • The client measures the width of the output panel in characters before each run: 70 on a desktop and 38 on a phone in the docs.
    • The Python runtime sets COLUMNS to it, so help text from argparse, Click and Rich fits the panel. Click still uses at least 50 columns.
  • The Runtime interface
    • run() gets args, file and columns in its options, so custom runtimes can use them. The runtime guide describes them.
  • Docs
    • The Run code page has a "Command line arguments" section, a Syntax row and an example with a Click command and runnable.args="--help". The Typer note (runnable.packages="markdown-it-py pygments") moved here from docs: PyPI reads _, - and . in package names as the same character #40.
    • The reference, the skill, DECISIONS.md and the changelog have entries too.

Tests

  • I ran these in the browser on astro dev, against the Pyodide runtime:
    • sys.argv and COLUMNS get the values that were passed, and main.py and no COLUMNS when nothing was passed.
    • sys.exit("bad input") prints the message on standard error, and sys.exit(2) prints nothing.
    • A ZeroDivisionError traceback still starts at the reader's line, and top-level await still works.
    • A session block stops at sys.exit(0).
    • The argparse help wraps at 40 columns.
  • New unit test: runnable.args splitting, the data-scb-runnable-file attribute and the warning for a quote that does not close.
  • New Playwright test: the Click example prints Usage: hello.py [OPTIONS] NAME and has no standard error. The example indexes in runnable.test.ts move up by one.
  • pnpm lint, pnpm lint:docs, pnpm test and pnpm docs:build pass. The runnable, compat and carousel Playwright specs pass in all projects.

🤖 Generated with Claude Code

…it()` and `COLUMNS` from the panel width

A Click or Typer command in a block now runs with the code of a real file, with no `standalone_mode=False` or `prog_name`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ewels added a commit that referenced this pull request Nov 18, 2026
…dd PyPI spellings to the skill

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ewels added a commit that referenced this pull request Nov 18, 2026
* docs: run a Click or Typer command line tool, and PyPI name spellings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: remove the command line tool example, which #43 replaces, and add PyPI spellings to the skill

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
ewels and others added 4 commits November 18, 2026 09:21
# Conflicts:
#	skills/starlight-codeblocks/references/copy-and-run.md
…ads it, and a transform-proof `COLUMNS`

- `runnable.args` takes backslash escapes as a shell does.
- A bad `runnable.args` or `runnable.packages` no longer warns about a site setting that does not exist.
- `runnable.args` warns on scripted output and on the built-in JavaScript and TypeScript runtimes.
- The panel width ignores CSS transforms, and its probe is hidden from screen readers.
- The docs say that Click help is at least 50 characters wide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rich keeps the console that it makes on the first run, with the `COLUMNS` of that run, and the worker keeps Rich between runs. A run in a wider or narrower panel then wrapped at the old width.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	packages/starlight-codeblocks/CHANGELOG.md
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.

1 participant