Skip to content

refactor: Migrate remaining ex_dir= call sites to add_example(example_name=)#2329

Merged
schloerke merged 2 commits into
mainfrom
schloerke/fix-issue-2328
Jul 6, 2026
Merged

refactor: Migrate remaining ex_dir= call sites to add_example(example_name=)#2329
schloerke merged 2 commits into
mainfrom
schloerke/fix-issue-2328

Conversation

@schloerke

Copy link
Copy Markdown
Collaborator

Closes #2328

Summary

Adds an example_name= parameter to the internal @add_example() decorator (shiny/_docstring.py) and migrates all 37 ex_dir= call sites that pointed inside an api-examples/ tree. example_name="foo" finds the nearest api-examples/ directory by walking up from the decorated object's source file (the same mechanism as the no-argument form) and looks up the foo subdirectory, replacing fragile hardcoded relative paths like ex_dir="../../api-examples/foo". A missing example_name directory raises FileNotFoundError during docs builds instead of resolving to a wrong path.

The parameter is implemented with the same signature and semantics as the one proposed in #2278 (*-keyword-only args, mutual exclusivity with ex_dir=), so the two changes should merge cleanly whichever lands first. This PR intentionally does not include #2278's warn-to-raise behavior change for missing example app files, nor its new example apps.

This also fixes nine call sites in shiny/session/_session.py and shiny/bookmark/_bookmark.py that passed the example name positionally (e.g. @add_example("session_close")), where it was silently consumed as app_file=; those examples were being dropped from the generated docs with only a ::warning in the build log. With add_example() now keyword-only, such mistakes are a TypeError at import time (when SHINY_ADD_EXAMPLES=true).

ex_dir= is retained (its docstring now says to prefer example_name=) for the case where an example lives outside the nearest api-examples/ tree; no call sites currently need it.

Verification

  • SHINY_ADD_EXAMPLES=true SHINY_MODE=core python -c "import shiny, shiny.express" and the same with SHINY_MODE=express both succeed. Comparing ::warning output against main: no new warnings, and the nine warnings from the broken positional call sites are gone (their examples now resolve). The two remaining bookmark_callbacks express warnings are pre-existing (no app-express.py yet; docs: fail on missing API examples #2278 adds one).
  • make docs-quartodoc builds cleanly (exit 0).
  • grep -rn 'ex_dir=' shiny/ matches only the parameter definition in _docstring.py.
  • Unit tests: 861 passed. Pyright on touched files: no new errors vs main.

Adds an example_name= parameter to @add_example() that looks up the
example in the nearest api-examples/ directory (same walk-up mechanism
as the no-argument form), and migrates all 37 ex_dir= call sites that
pointed inside an api-examples/ tree.

Also fixes nine call sites in shiny/session/_session.py and
shiny/bookmark/_bookmark.py that passed the example name positionally,
where it was silently consumed as app_file= and the example was omitted
from the generated docs with only a build warning.

The example_name= parameter matches the semantics of the one proposed
in #2278 so the two changes merge cleanly.

Fixes #2328
@schloerke schloerke marked this pull request as ready for review July 6, 2026 16:35
Resolves conflicts with #2278, which merged first and added the same
example_name= parameter to @add_example():

- shiny/_docstring.py: keep main's version plus the docstring note to
  prefer example_name= over ex_dir=.
- shiny/render/_render.py: keep main's removal of @no_example("express")
  on render.text and render.plot (express examples now exist), with the
  example_name= spelling.
- shiny/ui/_bootstrap.py: keep main's added @no_example("express") on
  column(), with the example_name= spelling.
@schloerke schloerke merged commit 411aaa3 into main Jul 6, 2026
172 checks passed
@schloerke schloerke deleted the schloerke/fix-issue-2328 branch July 6, 2026 16: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.

refactor: Migrate remaining ex_dir= call sites to add_example(example_name=)

1 participant