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

Add title option for Streamlit definition #1200

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Deprecations

## New additions
* Added support for `title` field in Streamlit definition in `snowflake.yml` project file.

## Fixes and improvements
* Passing a directory to `snow app deploy` will now deploy any contained file or subfolder specified in the application's artifact rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ class Streamlit(UpdatableModel, ObjectIdentifierModel(object_name="Streamlit")):
title="List of additional files which should be included into deployment artifacts",
default=None,
)
title: Optional[str] = Field(
title="Human-readable title for the Streamlit dashboard", default=None
)
1 change: 1 addition & 0 deletions src/snowflake/cli/plugins/streamlit/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def streamlit_deploy(
replace=replace,
query_warehouse=streamlit.query_warehouse,
additional_source_files=streamlit.additional_source_files,
title=streamlit.title,
**options,
)

Expand Down
6 changes: 6 additions & 0 deletions src/snowflake/cli/plugins/streamlit/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _create_streamlit(
experimental: Optional[bool] = None,
query_warehouse: Optional[str] = None,
from_stage_name: Optional[str] = None,
title: Optional[str] = None,
):
query = []
if replace:
Expand All @@ -98,6 +99,8 @@ def _create_streamlit(

if query_warehouse:
query.append(f"QUERY_WAREHOUSE = {query_warehouse}")
if title:
query.append(f"TITLE = '{title}'")

self._execute_query("\n".join(query))

Expand All @@ -111,6 +114,7 @@ def deploy(
query_warehouse: Optional[str] = None,
replace: Optional[bool] = False,
additional_source_files: Optional[List[str]] = None,
title: Optional[str] = None,
**options,
):
# for backwards compatibility - quoted stage path might be case-sensitive
Expand All @@ -134,6 +138,7 @@ def deploy(
replace=replace,
query_warehouse=query_warehouse,
experimental=True,
title=title,
)
try:
self._execute_query(f"ALTER streamlit {fully_qualified_name} CHECKOUT")
Expand Down Expand Up @@ -187,6 +192,7 @@ def deploy(
query_warehouse=query_warehouse,
from_stage_name=root_location,
experimental=False,
title=title,
)

return self.get_url(fully_qualified_name)
Expand Down
1 change: 1 addition & 0 deletions tests/project/__snapshots__/test_config.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@
'query_warehouse': 'test_warehouse',
'schema_name': None,
'stage': 'streamlit',
'title': None,
}),
})
# ---
8 changes: 8 additions & 0 deletions tests/streamlit/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_deploy_only_streamlit_file(
ROOT_LOCATION = '@MockDatabase.MockSchema.streamlit/{STREAMLIT_NAME}'
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
"select system$get_snowsight_host()",
Expand Down Expand Up @@ -195,6 +196,7 @@ def test_deploy_only_streamlit_file_replace(
ROOT_LOCATION = '@MockDatabase.MockSchema.streamlit/{STREAMLIT_NAME}'
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
"select system$get_snowsight_host()",
Expand Down Expand Up @@ -262,6 +264,7 @@ def test_deploy_streamlit_and_environment_files(
ROOT_LOCATION = '@MockDatabase.MockSchema.streamlit/{STREAMLIT_NAME}'
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
f"select system$get_snowsight_host()",
Expand Down Expand Up @@ -302,6 +305,7 @@ def test_deploy_streamlit_and_pages_files(
ROOT_LOCATION = '@MockDatabase.MockSchema.streamlit/{STREAMLIT_NAME}'
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
f"select system$get_snowsight_host()",
Expand Down Expand Up @@ -387,6 +391,7 @@ def test_deploy_put_files_on_stage(
ROOT_LOCATION = '@MockDatabase.MockSchema.streamlit_stage/{STREAMLIT_NAME}'
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
f"select system$get_snowsight_host()",
Expand Down Expand Up @@ -464,6 +469,7 @@ def test_deploy_streamlit_main_and_pages_files_experimental(
CREATE STREAMLIT IF NOT EXISTS MockDatabase.MockSchema.{STREAMLIT_NAME}
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
f"ALTER streamlit MockDatabase.MockSchema.{STREAMLIT_NAME} CHECKOUT",
Expand Down Expand Up @@ -529,6 +535,7 @@ def test_deploy_streamlit_main_and_pages_files_experimental_double_deploy(
CREATE STREAMLIT IF NOT EXISTS MockDatabase.MockSchema.{STREAMLIT_NAME}
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
_put_query("streamlit_app.py", root_path),
Expand Down Expand Up @@ -610,6 +617,7 @@ def test_deploy_streamlit_main_and_pages_files_experimental_replace(
CREATE OR REPLACE STREAMLIT MockDatabase.MockSchema.{STREAMLIT_NAME}
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = test_warehouse
TITLE = 'My Fancy Streamlit'
"""
).strip(),
f"ALTER streamlit MockDatabase.MockSchema.{STREAMLIT_NAME} CHECKOUT",
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/projects/example_streamlit/snowflake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ streamlit:
stage: streamlit
query_warehouse: test_warehouse
main_file: "streamlit_app.py"
title: "My Fancy Streamlit"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
definition_version: 1
streamlit:
name: test_streamlit_deploy_snowcli
title: "My Fancy Streamlit"
stage: streamlit
query_warehouse: xsmall
main_file: streamlit_app.py
Expand Down
1 change: 1 addition & 0 deletions tests_integration/test_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_streamlit_deploy(
f"describe streamlit {streamlit_name}"
)
assert contains_row_with(result.json, row_from_snowflake_session(expect)[0])
assert contains_row_with(result.json, {"title": "My Fancy Streamlit"})

result = runner.invoke_with_connection_json(
["streamlit", "get-url", streamlit_name]
Expand Down
Loading