-
Notifications
You must be signed in to change notification settings - Fork 116
Use a renderer generator to create sync/async render methods with full typing #621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
f802db2
First pass at creating a renderer generator to handle boilerplate and…
schloerke 7ee4db0
Create test_renderer_gen.py
schloerke 52b77bd
Create e2e test app that tests renderer_gen in sync/async and with/wi…
schloerke c0264ca
Add missing return statement
schloerke 40a18f1
Ignore duckdb data files
schloerke db57352
Update TODOs
schloerke 40b6421
Naturally export RenderFunctionMeta
schloerke 4a82f0f
Reduce number of Render classes. Have `RendererMeta` class be supplie…
schloerke 8834255
Require users to use `None` when describing `IT` and `OT`
schloerke 7b8abf7
Do not allow args to be named `_render_fn`. Break up test into many t…
schloerke 87fc09f
Get ParamSpec and Concatenate from typing extensions
schloerke 4f69268
Legacy typing lints
schloerke be7d0b5
Add TODOs
schloerke 5add579
Merge branch 'main' into renderer_gen
schloerke b36c893
Rework names; Have the handler function receive the render function f…
schloerke b45880b
Minimize the number of generic variables in the classes. Add helper c…
schloerke d3a3b20
temp commit to save thoughts before destroying them. Could not get ov…
schloerke 46c1cc9
Another temp commit in messy state. Using classes as return type to hide
schloerke 7bf7267
Using helper method approach to function and types for the user to ma…
schloerke 3179506
Save state again before we start dropping code in favor of using over…
schloerke 0ab8d4a
Save state again. Lots of code as been chopped and it is a good break…
schloerke ad1d285
Clean up renderer components. Add some docs (needs more)
schloerke 5c7c418
Rename files
schloerke 4444e71
Docs. Still more docs to come
schloerke daae487
More docs and an example app
schloerke d900a17
Add comment about `RendererParams`'s `args` field
schloerke aa5b897
Add comments explaining `RenderFn` and `HandlerFn`
schloerke 64f8f02
Remove comment
schloerke e7b64e4
Remove `__doc__` param
schloerke 7a7da17
Make `.meta` property into `._meta()` method
schloerke b5ecaf3
Drop unnecessary `*_` arg
schloerke ba43bcf
Make `_is_async` property into `_is_async()` method
schloerke ff81342
Remove newline escape
schloerke a2a8c28
Remove unnecessary async wrap
schloerke df843d0
Update comment about async render_fn function in RendererRun
schloerke 05e93e7
Merger `RendererRun` into `Renderer`. Use ABC to mark some methods as…
schloerke 649ab43
Merge branch 'main' into renderer_gen
schloerke 913b403
better comment about which variables are found during imports
schloerke c71c530
typing lints
schloerke ae5c1b7
Implement methods for `RenderFunction` and `RenderFunctionAsync`
schloerke 6fc0980
Docs / comments
schloerke 22ed3bf
Add changelog entry
schloerke 322bb0e
Bump to dev version: 0.5.0.9000
schloerke 4e568a9
Partial code review changes
wch f5cda40
Add test for having an async handler?
schloerke cffeafb
Merge branch 'renderer_gen' of https://github.com/rstudio/py-shiny in…
schloerke 5ee0500
Make transformer methods consistent. Make `.impl` into `.__call__`
schloerke 1c2a451
Skip impossible test
schloerke db66eee
Hide test so that pylance doesn't get confused
schloerke fc02a24
parentheses and type comment
schloerke 99bf57e
Move transformer methods to `shiny.render.transformer` folder
schloerke 8bb6aa6
Restore `shiny.render.__init__` import structure and import transform…
schloerke de0f5de
Fix broken imports
schloerke 228650b
Test truely async transformer functions
schloerke d4015b6
Documentation; Partial: Remove `is_async` from meta info. Supply unca…
schloerke 39afa5c
Mark random port test as flaky
schloerke caa861e
Cleanup files. Implement `_fn` as `ValueFn[IT]` (not `ValueFnAsync[IT…
schloerke 296e8ff
Add output transformer docs
schloerke 34fb8a8
Merge branch 'main' into renderer_gen
schloerke 0213e98
More documentation. More to go
schloerke 2e7fcb8
doc tweaks
schloerke 9c532d6
Update app.py
schloerke eb1d454
Update test_output_transformer.py
schloerke cd939a0
Expose `ValueFn`
schloerke 57afd26
Remove comment about `from __future__ import annotations`
schloerke 4f4ee56
spelling
schloerke 88a75c0
Speed up tests
schloerke f9486c5
Apply suggestions from code review
schloerke 0505dcd
Merge branch 'renderer_gen' of https://github.com/rstudio/py-shiny in…
schloerke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional, overload | ||
|
|
||
| from shiny import App, Inputs, Outputs, Session, ui | ||
| from shiny.render.transformer import ( | ||
| TransformerMetadata, | ||
| ValueFn, | ||
| is_async_callable, | ||
| output_transformer, | ||
| resolve_value_fn, | ||
| ) | ||
|
|
||
|
|
||
| @output_transformer | ||
| async def TestTextTransformer( | ||
| _meta: TransformerMetadata, | ||
| _fn: ValueFn[str | None], | ||
| *, | ||
| extra_txt: Optional[str] = None, | ||
| ) -> str | None: | ||
| value = await resolve_value_fn(_fn) | ||
| value = str(value) | ||
| value += "; " | ||
| value += "async" if is_async_callable(_fn) else "sync" | ||
| if extra_txt: | ||
| value = value + "; " + str(extra_txt) | ||
| return value | ||
|
|
||
|
|
||
| @overload | ||
| def render_test_text( | ||
| *, extra_txt: Optional[str] = None | ||
| ) -> TestTextTransformer.OutputRendererDecorator: | ||
| ... | ||
|
|
||
|
|
||
| @overload | ||
| def render_test_text( | ||
| _fn: TestTextTransformer.ValueFn, | ||
| ) -> TestTextTransformer.OutputRenderer: | ||
| ... | ||
|
|
||
|
|
||
| def render_test_text( | ||
| _fn: TestTextTransformer.ValueFn | None = None, | ||
| *, | ||
| extra_txt: Optional[str] = None, | ||
| ) -> TestTextTransformer.OutputRenderer | TestTextTransformer.OutputRendererDecorator: | ||
| return TestTextTransformer( | ||
| _fn, | ||
| TestTextTransformer.params(extra_txt=extra_txt), | ||
| ) | ||
|
|
||
|
|
||
| app_ui = ui.page_fluid( | ||
| ui.code("t1:"), | ||
| ui.output_text_verbatim("t1"), | ||
| ui.code("t2:"), | ||
| ui.output_text_verbatim("t2"), | ||
| ui.code("t3:"), | ||
| ui.output_text_verbatim("t3"), | ||
| ui.code("t4:"), | ||
| ui.output_text_verbatim("t4"), | ||
| ui.code("t5:"), | ||
| ui.output_text_verbatim("t5"), | ||
| ui.code("t6:"), | ||
| ui.output_text_verbatim("t6"), | ||
| ) | ||
|
|
||
|
|
||
| def server(input: Inputs, output: Outputs, session: Session): | ||
| @output | ||
| @render_test_text | ||
| def t1(): | ||
| return "t1; no call" | ||
| # return "hello" | ||
|
|
||
| @output | ||
| @render_test_text | ||
| async def t2(): | ||
| return "t2; no call" | ||
|
|
||
| @output | ||
| @render_test_text() | ||
| def t3(): | ||
| return "t3; call" | ||
|
|
||
| @output | ||
| @render_test_text() | ||
| async def t4(): | ||
| return "t4; call" | ||
|
|
||
| @output | ||
| @render_test_text(extra_txt="w/ extra_txt") | ||
| def t5(): | ||
| return "t5; call" | ||
|
|
||
| @output | ||
| @render_test_text(extra_txt="w/ extra_txt") | ||
| async def t6(): | ||
| return "t6; call" | ||
|
|
||
|
|
||
| app = App(app_ui, server) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from conftest import ShinyAppProc | ||
| from controls import OutputTextVerbatim | ||
| from playwright.sync_api import Page | ||
|
|
||
|
|
||
| def test_output_image_kitchen(page: Page, local_app: ShinyAppProc) -> None: | ||
| page.goto(local_app.url) | ||
|
|
||
| OutputTextVerbatim(page, "t1").expect_value("t1; no call; sync") | ||
| OutputTextVerbatim(page, "t2").expect_value("t2; no call; async") | ||
| OutputTextVerbatim(page, "t3").expect_value("t3; call; sync") | ||
| OutputTextVerbatim(page, "t4").expect_value("t4; call; async") | ||
| OutputTextVerbatim(page, "t5").expect_value("t5; call; sync; w/ extra_txt") | ||
| OutputTextVerbatim(page, "t6").expect_value("t6; call; async; w/ extra_txt") |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.