-
Notifications
You must be signed in to change notification settings - Fork 26
Add support for shiny mode magic comment #549
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
10 commits
Select commit
Hold shift + click to select a range
a95eed0
Add support for shiny mode magic comment
wch b5004f1
Update changelog
wch 0e34810
Fix docstring and work around mypy inference limitation
wch 61bfd1f
Add comment
wch f51c91f
Don't test on Python 3.7 in CI
wch 6f77b24
Merge branch 'master' into shiny-is-express
wch cc3766e
Add tests for Shiny Express app detection
wch 3369910
Merge remote-tracking branch 'origin/master' into shiny-is-express
wch 90d9ab4
Merge branch 'master' into shiny-is-express
wch 3126880
Add typing-extensions dependency
wch 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,52 @@ | ||
from pathlib import Path | ||
|
||
from rsconnect import shiny_express as express | ||
|
||
def test_is_express_app(tmp_path: Path): | ||
tmp_file = str(tmp_path / "app.py") | ||
|
||
def write_tmp_file(s: str): | ||
with open(tmp_file, "w") as f: | ||
f.write(s) | ||
|
||
write_tmp_file("import shiny.express") | ||
assert express.is_express_app(tmp_file, None) | ||
# Check that it works when passing in app_path | ||
assert express.is_express_app("app.py", str(tmp_path)) | ||
|
||
write_tmp_file("# comment\nimport sys\n\nimport shiny.express") | ||
assert express.is_express_app(tmp_file, None) | ||
|
||
write_tmp_file("import sys\n\nfrom shiny import App, express") | ||
assert express.is_express_app(tmp_file, None) | ||
|
||
write_tmp_file("import sys\n\nfrom shiny.express import layout, input") | ||
assert express.is_express_app(tmp_file, None) | ||
|
||
# Shouldn't find in comment | ||
write_tmp_file("# import shiny.express") | ||
assert not express.is_express_app(tmp_file, None) | ||
|
||
# Shouldn't find in a string, even if it looks like an import | ||
write_tmp_file('"""\nimport shiny.express\n"""') | ||
assert not express.is_express_app(tmp_file, None) | ||
|
||
# Shouldn't recurse into with, if, for, def, etc. | ||
write_tmp_file("with f:\n from shiny import express") | ||
assert not express.is_express_app(tmp_file, None) | ||
|
||
write_tmp_file("if True:\n import shiny.express") | ||
assert not express.is_express_app(tmp_file, None) | ||
|
||
write_tmp_file("for i in range(2):\n import shiny.express") | ||
assert not express.is_express_app(tmp_file, None) | ||
|
||
write_tmp_file("def f():\n import shiny.express") | ||
assert not express.is_express_app(tmp_file, None) | ||
|
||
# Look for magic comment - should override import detection | ||
write_tmp_file("\n#shiny_mode: core\nfrom shiny.express import ui") | ||
assert not express.is_express_app(tmp_file, None) | ||
|
||
write_tmp_file("#shiny_mode: express\nfrom shiny import ui") | ||
assert express.is_express_app(tmp_file, None) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth adding a test for this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added tests for Shiny Express app detection in general in cc3766e.