-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add app templates #10
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
15745f6
update streamlit
sfc-gh-pczajka 5f8667a
update snowpark
sfc-gh-pczajka 87b5779
update tests
sfc-gh-pczajka 2525bbf
update workflows
sfc-gh-pczajka 9f0d3cb
update workflow
sfc-gh-pczajka 551268b
fix workflow
sfc-gh-pczajka 0c22e2d
Merge branch 'main' into update-templates-to-V2
sfc-gh-pczajka d4da38e
Added native app templates
sfc-gh-bdufour 402c193
Fixed validation warnings; ensure unique project names
sfc-gh-bdufour 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
Validating CODEOWNERS rules …
This file contains 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
* @snowflakedb/snowcli | ||
|
||
app_* @snowflakedb/nade |
This file contains 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 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 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,72 @@ | ||
import os | ||
import subprocess | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
from snowflake.cli.__about__ import VERSION | ||
import pytest | ||
from contextlib import contextmanager | ||
|
||
if VERSION < "2.8.0": | ||
pytest.skip("This test requires CLI >= 2.8.0", allow_module_level=True) | ||
|
||
|
||
@pytest.fixture() | ||
def initialize_project(): | ||
@contextmanager | ||
def _initialize_project(template_name): | ||
with TemporaryDirectory() as tmpdir: | ||
project_dir = Path(tmpdir) / "project" | ||
output = subprocess.check_output( | ||
[ | ||
"snow", | ||
"init", | ||
str(project_dir), | ||
"--template", | ||
template_name, | ||
"--no-interactive", | ||
], | ||
encoding="utf-8", | ||
) | ||
assert "Initialized the new project in" in output | ||
|
||
old_cwd = os.getcwd() | ||
os.chdir(project_dir) | ||
yield project_dir | ||
os.chdir(old_cwd) | ||
|
||
return _initialize_project | ||
|
||
|
||
def test_snowpark_examples_functions_work_locally(initialize_project): | ||
with initialize_project("example_snowpark") as snowpark_project: | ||
output = subprocess.check_output( | ||
["python", str(snowpark_project / "app" / "functions.py"), "FooBar"], | ||
encoding="utf-8", | ||
) | ||
assert output.strip() == "Hello FooBar!" | ||
|
||
output = subprocess.check_output( | ||
["python", str(snowpark_project / "app" / "procedures.py"), "BazBar"], | ||
encoding="utf-8", | ||
) | ||
assert output.strip() == "Hello BazBar!" | ||
|
||
|
||
def test_example_snowpark_yml_is_correct(initialize_project): | ||
with initialize_project("example_snowpark") as snowpark_project: | ||
output = subprocess.check_output( | ||
["snow", "snowpark", "build"], | ||
encoding="utf-8", | ||
) | ||
assert "Build done." in output | ||
|
||
|
||
def test_example_streamlit_yml_is_correct(initialize_project): | ||
with initialize_project("example_streamlit") as streamlit_project: | ||
result = subprocess.run( | ||
["snow", "streamlit", "deploy"], | ||
capture_output=True, | ||
text=True, | ||
encoding="utf-8", | ||
) | ||
assert not "During evaluation of " in result.stdout + result.stderr |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,2 @@ | ||
snowflake.local.yml | ||
output/** |
This file contains 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,18 @@ | ||
## Introduction | ||
|
||
This is the basic project template for a Snowflake Native App project. It contains minimal code meant to help you set up your first application object in your account quickly. | ||
|
||
### Project Structure | ||
| File Name | Purpose | | ||
| --------- | ------- | | ||
| README.md | The current file you are looking at, meant to guide you through a Snowflake Native App project. | | ||
| app/setup_script.sql | Contains SQL statements that are run when an account installs or upgrades a Snowflake Native App. | | ||
| app/manifest.yml | Defines properties required by the application package. Find more details at the [Manifest Documentation.](https://docs.snowflake.com/en/developer-guide/native-apps/creating-manifest) | ||
| app/README.md | Exposed to the account installing the Snowflake Native App with details on what it does and how to use it. | | ||
| snowflake.yml | Used by the Snowflake CLI tool to discover your project's code and interact with your Snowflake account with all relevant prvileges and grants. | | ||
<!! if snowflake_cli_version < "3.0.0" !!> | ||
### Adding a snowflake.local.yml file | ||
Though your project directory already comes with a `snowflake.yml` file, an individual developer can choose to customize the behavior of the Snowflake CLI by providing local overrides to `snowflake.yml`, such as a new role to test out your own application package. This is where you can use `snowflake.local.yml`, which is not a version-controlled file. | ||
|
||
For more information, please refer to the Snowflake Documentation on installing and using Snowflake CLI to create a Snowflake Native App. | ||
<!! endif !!> |
This file contains 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,20 @@ | ||
## Welcome to your First Snowflake Native App! | ||
|
||
In this Snowflake Native App, you will be able to explore some basic concepts such as application role, versioned schemas and creating procedures and functions within a setup script. | ||
|
||
For more information about a Snowflake Native App, please read the [official Snowflake documentation](https://docs.snowflake.com/en/developer-guide/native-apps/native-apps-about) which goes in depth about many additional functionalities of this framework. | ||
|
||
## Using the application after installation | ||
To interact with the application after it has successfully installed in your account, switch to the application owner role first. | ||
|
||
### Calling a stored procedure | ||
|
||
``` | ||
CALL <your_application_name>.<schema_name>.<stored_procedure_name_with_args>; | ||
``` | ||
|
||
### Calling a function | ||
|
||
``` | ||
SELECT <your_application_name>.<schema_name>.<udf_with_args>; | ||
``` |
This file contains 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,9 @@ | ||
# This is a manifest.yml file, a required component of creating a Snowflake Native App. | ||
# This file defines properties required by the application package, including the location of the setup script and version definitions. | ||
# Refer to https://docs.snowflake.com/en/developer-guide/native-apps/creating-manifest for a detailed understanding of this file. | ||
|
||
manifest_version: 1 | ||
|
||
artifacts: | ||
setup_script: setup_script.sql | ||
readme: README.md |
This file contains 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,11 @@ | ||
-- This is the setup script that runs while installing a Snowflake Native App in a consumer account. | ||
-- To write this script, you can familiarize yourself with some of the following concepts: | ||
-- Application Roles | ||
-- Versioned Schemas | ||
-- UDFs/Procs | ||
-- Extension Code | ||
-- Refer to https://docs.snowflake.com/en/developer-guide/native-apps/creating-setup-script for a detailed understanding of this file. | ||
|
||
CREATE OR ALTER VERSIONED SCHEMA core; | ||
|
||
-- The rest of this script is left blank for purposes of your learning and exploration. |
This file contains 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,29 @@ | ||
# This is a project definition file, a required component if you intend to use Snowflake CLI in a project directory such as this template. | ||
<!! if snowflake_cli_version < "3.0.0" !!> | ||
definition_version: 1 | ||
native_app: | ||
name: <! project_name | to_snowflake_identifier !> | ||
source_stage: app_src.stage | ||
artifacts: | ||
- src: app/* | ||
dest: ./ | ||
<!! else !!> | ||
definition_version: 2 | ||
entities: | ||
pkg: | ||
type: application package | ||
identifier: <% fn.concat_ids('<! project_name | to_snowflake_identifier !>_pkg', ctx.env.suffix) %> | ||
manifest: app/manifest.yml | ||
artifacts: | ||
- src: app/* | ||
dest: ./ | ||
|
||
app: | ||
type: application | ||
from: | ||
target: pkg | ||
identifier: <% fn.concat_ids('<! project_name | to_snowflake_identifier !>', ctx.env.suffix) %> | ||
|
||
env: | ||
suffix: <% fn.concat_ids('_', fn.sanitize_id(fn.get_username('unknown_user')) | lower) %> | ||
<!! endif !!> |
This file contains 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,9 @@ | ||
minimum_cli_version: "2.8.0" | ||
files_to_render: | ||
- snowflake.yml | ||
- README.md | ||
variables: | ||
- name: project_name | ||
prompt: "Project identifier" | ||
default: my_native_app_project | ||
type: string |
This file contains 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,2 @@ | ||
snowflake.local.yml | ||
output/** |
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.
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.
Is there any strong opinion on using "project" for this variable?
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.
snow init
still says it "creates a project directory", so I figured that was the right term.