From 660edb0fbe863ff3c14a0f264266caf2239f72e4 Mon Sep 17 00:00:00 2001 From: Tomasz Urbaszek Date: Thu, 13 Jun 2024 16:20:06 +0200 Subject: [PATCH 1/3] Add title option for Streamlit definition --- .../cli/api/project/schemas/streamlit/streamlit.py | 3 +++ src/snowflake/cli/plugins/streamlit/commands.py | 1 + src/snowflake/cli/plugins/streamlit/manager.py | 6 ++++++ tests/streamlit/test_commands.py | 1 + tests/test_data/projects/example_streamlit/snowflake.yml | 1 + .../test_data/projects/streamlit/snowflake.yml | 1 + tests_integration/test_streamlit.py | 1 + 7 files changed, 14 insertions(+) diff --git a/src/snowflake/cli/api/project/schemas/streamlit/streamlit.py b/src/snowflake/cli/api/project/schemas/streamlit/streamlit.py index 5997ee0e7..ea9727070 100644 --- a/src/snowflake/cli/api/project/schemas/streamlit/streamlit.py +++ b/src/snowflake/cli/api/project/schemas/streamlit/streamlit.py @@ -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 + ) diff --git a/src/snowflake/cli/plugins/streamlit/commands.py b/src/snowflake/cli/plugins/streamlit/commands.py index 89c614a9e..2734c73ae 100644 --- a/src/snowflake/cli/plugins/streamlit/commands.py +++ b/src/snowflake/cli/plugins/streamlit/commands.py @@ -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, ) diff --git a/src/snowflake/cli/plugins/streamlit/manager.py b/src/snowflake/cli/plugins/streamlit/manager.py index 6c91660d4..0fb22291b 100644 --- a/src/snowflake/cli/plugins/streamlit/manager.py +++ b/src/snowflake/cli/plugins/streamlit/manager.py @@ -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: @@ -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)) @@ -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 @@ -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") @@ -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) diff --git a/tests/streamlit/test_commands.py b/tests/streamlit/test_commands.py index c780a608c..21a80de44 100644 --- a/tests/streamlit/test_commands.py +++ b/tests/streamlit/test_commands.py @@ -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()", diff --git a/tests/test_data/projects/example_streamlit/snowflake.yml b/tests/test_data/projects/example_streamlit/snowflake.yml index 1a44643f9..8196be580 100644 --- a/tests/test_data/projects/example_streamlit/snowflake.yml +++ b/tests/test_data/projects/example_streamlit/snowflake.yml @@ -4,3 +4,4 @@ streamlit: stage: streamlit query_warehouse: test_warehouse main_file: "streamlit_app.py" + title: "My Fancy Streamlit" diff --git a/tests_integration/test_data/projects/streamlit/snowflake.yml b/tests_integration/test_data/projects/streamlit/snowflake.yml index 0eae4c072..f7fbaa72f 100644 --- a/tests_integration/test_data/projects/streamlit/snowflake.yml +++ b/tests_integration/test_data/projects/streamlit/snowflake.yml @@ -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 diff --git a/tests_integration/test_streamlit.py b/tests_integration/test_streamlit.py index 799965015..971871b21 100644 --- a/tests_integration/test_streamlit.py +++ b/tests_integration/test_streamlit.py @@ -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] From 7cf1075e4989fa8baef76f1db53e3165dbe2cef1 Mon Sep 17 00:00:00 2001 From: Tomasz Urbaszek Date: Thu, 13 Jun 2024 16:26:12 +0200 Subject: [PATCH 2/3] Add release notes --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index f3fff7260..9ab979f54 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -20,6 +20,7 @@ ## Deprecations ## New additions +* Added support for `title` field in Streamlit definition in `snowflake.yml` project file. ## Fixes and improvements From 7af52e9d192ea516ca2035c5c24a1c87379c8f35 Mon Sep 17 00:00:00 2001 From: Tomasz Urbaszek Date: Thu, 13 Jun 2024 18:08:35 +0200 Subject: [PATCH 3/3] fixup! Add release notes --- tests/project/__snapshots__/test_config.ambr | 1 + tests/streamlit/test_commands.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/tests/project/__snapshots__/test_config.ambr b/tests/project/__snapshots__/test_config.ambr index beb24badf..fe9945707 100644 --- a/tests/project/__snapshots__/test_config.ambr +++ b/tests/project/__snapshots__/test_config.ambr @@ -824,6 +824,7 @@ 'query_warehouse': 'test_warehouse', 'schema_name': None, 'stage': 'streamlit', + 'title': None, }), }) # --- diff --git a/tests/streamlit/test_commands.py b/tests/streamlit/test_commands.py index 21a80de44..dc829a713 100644 --- a/tests/streamlit/test_commands.py +++ b/tests/streamlit/test_commands.py @@ -196,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()", @@ -263,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()", @@ -303,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()", @@ -388,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()", @@ -465,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", @@ -530,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), @@ -611,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",