-
Notifications
You must be signed in to change notification settings - Fork 57
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
[SNOW-1039218] feat: add hidden app list-templates command #887
Conversation
with SecurePath.temporary_directory() as temp_path: | ||
from git import Repo | ||
|
||
repo = Repo.clone_from( | ||
url=OFFICIAL_TEMPLATES_GITHUB_URL, | ||
to_path=temp_path.path, | ||
filter=["tree:0"], | ||
depth=1, | ||
) |
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.
IMHO we should reuse the logic from the init command instead of reimplementing it here. You'll probably have to factor it out first though.
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.
Good callout, I extracted a function to src/snowflake/cli/plugins/nativeapp/utils.py
, let me know if that works for you!
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.
A few notes!
tests/nativeapp/test_utils.py
Outdated
"file_content, expected_paragraph", | ||
[ | ||
( | ||
""" |
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.
Suggest using dedent
here
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 tried and wasn't able to make it work smoothly since some of the whitespace is crucial in how the function works (e.g. first paragraph needs to have no whitespace in between), but I turned the multiline strings into multi line-strings to have a similar effect where the file isn't as long, let me know if that works for you or if I massively misunderstood the assignment 😅
EDIT: Scratch that, pretty sure I misunderstood, I changed it to use dedent now, thank you!
# get the template descriptions from the README.md in its directory | ||
template_descriptions = [ | ||
get_first_paragraph_from_markdown_file( | ||
(temp_path / directory / "README.md").path |
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.
Right now, this will fail if any templates are created that don't have top-level README.md
files. I suggest we provide a fallback to None
both in this case and when there is no paragraph text in the readme
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.
Good callout - added a test for it as well, thanks!
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'd like to see the helper method throw an exception rather than silently returning None
if the file doesn't exist, and then split out the negative test cases in two:
- file actually doesn't exist
- file doesn't have a non-empty regular paragraph line
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.
LGTM!
@app.command("list-templates", hidden=True) | ||
def app_list_templates(**options) -> CommandResult: | ||
""" | ||
Prints information regarding templates that can be used with snow app init. |
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.
Nit: "... regarding the official templates ...", so it is clear that only our Github templates are listed in this command.
] | ||
|
||
result = ( | ||
{"template": directory, "description": description} |
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 really like the idea of a little description along with template names!
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.
LGTM once the small change can be made to the description.
34f4126
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.
lgtm, thank you!
@@ -69,6 +81,39 @@ def app_init( | |||
) | |||
|
|||
|
|||
@app.command("list-templates", hidden=True) |
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.
Today we have feature flags. Have you consider using them?
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 believe this was clarified offline, please see the slack thread of the PR for the full discussion, but to summarize:
- For now, we intend to make it available for our IDE plugin, but not expose directly it to users
- We don't want users to have to enable a feature flag before the IDE plugin can work
- It doesn't fit the use case of an experimental flag since this command doesn't change the behaviour of any existing commands nor is it interacting with Snowflake
Please let me know if this works for you :)
* [SNOW-1039218] feat: add hidden app list-templates command * [SNOW-1039218] feat: factor out shallow clone and add None fallback to markdown util * [SNOW-1039218] refactor: change union typing for version support * [SNOW-1039218] test: adjust test parameters with dedent * [SNOW-1039218] fix: only import git locally * [SNOW-1039218] fix: PathLike not subscriptable * [SNOW-1039218] feat: raise Exception when file not found * [SNOW-1039218] docs: clarify only official templates for command * [SNOW-1039218] test: update snapshot for new help message
Pre-review checklist
Changes description
Added a
snow app list-templates
hidden command to support dynamic fetching of official Native App templates inside our PyCharm pluginFor more information please see: https://snowflakecomputing.atlassian.net/browse/SNOW-1039218