Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astus committed Jan 16, 2025
1 parent 6ef2d27 commit 02cb662
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 64 deletions.
8 changes: 4 additions & 4 deletions src/snowflake/cli/_plugins/snowpark/snowpark_entity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from snowflake.cli.api.feature_flags import FeatureFlag
from snowflake.cli.api.identifiers import FQN
from snowflake.cli.api.project.schemas.entities.common import (
Artifacts,
EntityModelBase,
EntityModelBaseWithArtifacts,
ExternalAccessBaseModel,
ImportsBaseModel,
PathMapping,
Expand All @@ -33,7 +32,9 @@
from snowflake.cli.api.project.schemas.v1.snowpark.argument import Argument


class SnowparkEntityModel(EntityModelBase, ExternalAccessBaseModel, ImportsBaseModel):
class SnowparkEntityModel(
EntityModelBaseWithArtifacts, ExternalAccessBaseModel, ImportsBaseModel
):
handler: str = Field(
title="Function’s or procedure’s implementation of the object inside source module",
examples=["functions.hello_function"],
Expand All @@ -48,7 +49,6 @@ class SnowparkEntityModel(EntityModelBase, ExternalAccessBaseModel, ImportsBaseM
title="Python version to use when executing ", default=None
)
stage: str = Field(title="Stage in which artifacts will be stored")
artifacts: Artifacts = Field(title="List of required sources")

@field_validator("artifacts")
@classmethod
Expand Down
25 changes: 7 additions & 18 deletions src/snowflake/cli/_plugins/streamlit/streamlit_entity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@

from typing import Literal, Optional

from pydantic import Field, field_validator
from pydantic import Field
from snowflake.cli.api.project.schemas.entities.common import (
Artifacts,
EntityModelBase,
EntityModelBaseWithArtifacts,
ExternalAccessBaseModel,
ImportsBaseModel,
PathMapping,
)
from snowflake.cli.api.project.schemas.updatable_model import (
DiscriminatorField,
)


class StreamlitEntityModel(EntityModelBase, ExternalAccessBaseModel, ImportsBaseModel):
class StreamlitEntityModel(
EntityModelBaseWithArtifacts, ExternalAccessBaseModel, ImportsBaseModel
):
type: Literal["streamlit"] = DiscriminatorField() # noqa: A003
title: Optional[str] = Field(
title="Human-readable title for the Streamlit dashboard", default=None
Expand All @@ -44,20 +45,8 @@ class StreamlitEntityModel(EntityModelBase, ExternalAccessBaseModel, ImportsBase
stage: Optional[str] = Field(
title="Stage in which the app’s artifacts will be stored", default="streamlit"
)
# Artifacts were optional, so to avoid BCR, we need to make them optional here as well
artifacts: Optional[Artifacts] = Field(
title="List of files which should be deployed. Each file needs to exist locally. "
"Main file needs to be included in the artifacts.",
title="List of paths or file source/destination pairs to add to the deploy root",
default=None,
)

@field_validator("artifacts")
@classmethod
def _convert_artifacts(cls, artifacts: Artifacts) -> Artifacts:
_artifacts = []
for artifact in artifacts:
if isinstance(artifact, PathMapping):
path_mapping = artifact
else:
path_mapping = PathMapping(src=artifact)
_artifacts.append(path_mapping)
return _artifacts
68 changes: 34 additions & 34 deletions tests/helpers/__snapshots__/test_v1_to_v2.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
- snowpark_shared
identifier:
name: hello_procedure
artifacts:
- src: <% ctx.env.project_source %>
dest: <! project_name | to_snowflake_identifier !>
handler: procedures.hello_procedure
returns: string
signature:
- name: name
type: string
stage: <! stage | to_snowflake_identifier !>
artifacts:
- src: <% ctx.env.project_source %>
dest: <! project_name | to_snowflake_identifier !>
type: procedure
execute_as_caller: false
test_procedure:
Expand All @@ -32,13 +32,13 @@
- snowpark_shared
identifier:
name: test_procedure
artifacts:
- src: <% ctx.env.project_source %>
dest: <! project_name | to_snowflake_identifier !>
handler: procedures.test_procedure
returns: string
signature: ''
stage: <! stage | to_snowflake_identifier !>
artifacts:
- src: <% ctx.env.project_source %>
dest: <! project_name | to_snowflake_identifier !>
type: procedure
execute_as_caller: false
hello_function:
Expand All @@ -50,15 +50,15 @@
- snowpark_shared
identifier:
name: hello_function
artifacts:
- src: <% ctx.env.project_source %>
dest: <! project_name | to_snowflake_identifier !>
handler: functions.hello_function
returns: string
signature:
- name: name
type: string
stage: <! stage | to_snowflake_identifier !>
artifacts:
- src: <% ctx.env.project_source %>
dest: <! project_name | to_snowflake_identifier !>
type: function
env:
project_source: app/
Expand Down Expand Up @@ -108,17 +108,17 @@
streamlit_entity_1:
identifier:
name: <! name | to_snowflake_identifier !>
artifacts:
- src: streamlit_app.py
- src: environment.yml
- src: pages
- src: common/hello.py
type: streamlit
title: <% ctx.env.streamlit_title %>
query_warehouse: <! query_warehouse | to_snowflake_identifier !>
main_file: streamlit_app.py
pages_dir: pages
stage: <! stage | to_snowflake_identifier !>
artifacts:
- src: streamlit_app.py
- src: environment.yml
- src: pages
- src: common/hello.py
env:
streamlit_title: My Fancy Streamlit

Expand Down Expand Up @@ -181,15 +181,15 @@
- snowpark_shared
identifier:
name: procedureName
artifacts:
- src: app/
dest: my_snowpark_project
handler: hello
returns: string
signature:
- name: name
type: string
stage: dev_deployment
artifacts:
- src: app/
dest: my_snowpark_project
type: procedure
execute_as_caller: false
func1:
Expand All @@ -201,6 +201,9 @@
- snowpark_shared
identifier:
name: func1
artifacts:
- src: app/
dest: my_snowpark_project
handler: app.func1_handler
returns: string
signature:
Expand All @@ -211,23 +214,20 @@
type: variant
runtime: '3.1'
stage: dev_deployment
artifacts:
- src: app/
dest: my_snowpark_project
type: function
test_streamlit:
identifier:
name: test_streamlit
artifacts:
- src: streamlit_app.py
- src: environment.yml
- src: pages
type: streamlit
title: My Fancy Streamlit
query_warehouse: test_warehouse
main_file: streamlit_app.py
pages_dir: None
stage: streamlit
artifacts:
- src: streamlit_app.py
- src: environment.yml
- src: pages
pkg:
meta:
role: pkg_role
Expand Down Expand Up @@ -381,15 +381,15 @@
- snowpark_shared
identifier:
name: procedureName
artifacts:
- src: app/
dest: my_snowpark_project
handler: hello
returns: string
signature:
- name: name
type: string
stage: dev_deployment
artifacts:
- src: app/
dest: my_snowpark_project
type: procedure
execute_as_caller: false
func1:
Expand All @@ -401,6 +401,9 @@
- snowpark_shared
identifier:
name: func1
artifacts:
- src: app/
dest: my_snowpark_project
handler: app.func1_handler
returns: string
signature:
Expand All @@ -411,23 +414,20 @@
type: variant
runtime: '3.10'
stage: dev_deployment
artifacts:
- src: app/
dest: my_snowpark_project
type: function
test_streamlit:
identifier:
name: test_streamlit
artifacts:
- src: streamlit_app.py
- src: environment.yml
- src: pages
type: streamlit
title: My Fancy Streamlit
query_warehouse: test_warehouse
main_file: streamlit_app.py
pages_dir: None
stage: streamlit
artifacts:
- src: streamlit_app.py
- src: environment.yml
- src: pages
pkg:
meta:
role: pkg_role
Expand Down
8 changes: 0 additions & 8 deletions tests/streamlit/__snapshots__/test_streamlit_entity.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,3 @@
TITLE = 'My Fancy Streamlit';
'''
# ---
# name: test_nativeapp_children_interface.1
'''
CREATE STREAMLIT IDENTIFIER('test_streamlit')
MAIN_FILE = 'streamlit_app.py'
QUERY_WAREHOUSE = 'test_warehouse'
TITLE = 'My Fancy Streamlit';
'''
# ---

0 comments on commit 02cb662

Please sign in to comment.