Skip to content
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

Merged
merged 17 commits into from
Mar 14, 2024

Conversation

sfc-gh-mchok
Copy link
Collaborator

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

Added a snow app list-templates hidden command to support dynamic fetching of official Native App templates inside our PyCharm plugin

For more information please see: https://snowflakecomputing.atlassian.net/browse/SNOW-1039218

@sfc-gh-mchok sfc-gh-mchok self-assigned this Mar 8, 2024
@sfc-gh-mchok sfc-gh-mchok requested review from sfc-gh-bgoel and a team as code owners March 8, 2024 22:02
Comment on lines 88 to 96
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,
)
Copy link
Contributor

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.

Copy link
Collaborator Author

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!

Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes!

"file_content, expected_paragraph",
[
(
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest using dedent here

Copy link
Collaborator Author

@sfc-gh-mchok sfc-gh-mchok Mar 8, 2024

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!

tests/nativeapp/test_utils.py Show resolved Hide resolved
# 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
Copy link
Contributor

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

Copy link
Collaborator Author

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!

Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie left a 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

sfc-gh-cgorrie
sfc-gh-cgorrie previously approved these changes Mar 12, 2024
Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie left a 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.
Copy link
Contributor

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}
Copy link
Contributor

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!

sfc-gh-bgoel
sfc-gh-bgoel previously approved these changes Mar 12, 2024
Copy link
Contributor

@sfc-gh-bgoel sfc-gh-bgoel left a 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.

sfc-gh-bgoel
sfc-gh-bgoel previously approved these changes Mar 12, 2024
Copy link
Contributor

@sfc-gh-bgoel sfc-gh-bgoel left a 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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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 :)

@sfc-gh-mchok sfc-gh-mchok merged commit ab351f5 into main Mar 14, 2024
10 checks passed
@sfc-gh-mchok sfc-gh-mchok deleted the mchok-SNOW-1039218-app-list-templates branch March 14, 2024 13:40
sfc-gh-sichen pushed a commit that referenced this pull request Oct 17, 2024
* [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
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.

5 participants