-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support project definition V2 in streamlit deploy command (#1369)
- Loading branch information
1 parent
edd5594
commit 415f3af
Showing
27 changed files
with
348 additions
and
81 deletions.
There are no files selected for viewing
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
68 changes: 68 additions & 0 deletions
68
src/snowflake/cli/api/project/schemas/entities/streamlit_entity.py
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,68 @@ | ||
# Copyright (c) 2024 Snowflake Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import List, Literal, Optional | ||
|
||
from pydantic import Field, model_validator | ||
from snowflake.cli.api.project.schemas.entities.common import EntityBase | ||
from snowflake.cli.api.project.schemas.identifier_model import ObjectIdentifierModel | ||
|
||
|
||
class StreamlitEntity(EntityBase, ObjectIdentifierModel(object_name="Streamlit")): # type: ignore | ||
type: Literal["streamlit"] # noqa: A003 | ||
title: Optional[str] = Field( | ||
title="Human-readable title for the Streamlit dashboard", default=None | ||
) | ||
query_warehouse: str = Field( | ||
title="Snowflake warehouse to host the app", default=None | ||
) | ||
main_file: Optional[str] = Field( | ||
title="Entrypoint file of the Streamlit app", default="streamlit_app.py" | ||
) | ||
pages_dir: Optional[str] = Field(title="Streamlit pages", default=None) | ||
stage: Optional[str] = Field( | ||
title="Stage in which the app’s artifacts will be stored", default="streamlit" | ||
) | ||
# Possibly can be PathMapping | ||
artifacts: Optional[List[Path]] = Field( | ||
title="List of files which should be deployed. Each file needs to exist locally. " | ||
"Main file needs to be included in the artifacts.", | ||
default=None, | ||
) | ||
|
||
@model_validator(mode="after") | ||
def main_file_must_be_in_artifacts(self): | ||
if not self.artifacts: | ||
return self | ||
|
||
if Path(self.main_file) not in self.artifacts: | ||
raise ValueError( | ||
f"Specified main file {self.main_file} is not included in artifacts." | ||
) | ||
return self | ||
|
||
@model_validator(mode="after") | ||
def artifacts_must_exists(self): | ||
if not self.artifacts: | ||
return self | ||
|
||
for artefact in self.artifacts: | ||
if not artefact.exists(): | ||
raise ValueError( | ||
f"Specified artefact {artefact} does not exist locally." | ||
) | ||
|
||
return self |
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
Empty file.
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,31 @@ | ||
# serializer version: 1 | ||
# name: test_artifacts_must_exists | ||
''' | ||
+- Error ----------------------------------------------------------------------+ | ||
| During evaluation of DefinitionV20 in project definition following errors | | ||
| were encountered: | | ||
| For field entities.my_streamlit.streamlit you provided '{'artifacts': | | ||
| ['streamlit_app.py', 'foo_bar.py', 'pages/', 'environment.yml'], | | ||
| 'main_file': 'streamlit_app.py', 'name': 'test_streamlit_deploy_snowcli', | | ||
| 'query_warehouse': 'xsmall', 'stage': 'streamlit', 'title': 'My Fancy | | ||
| Streamlit', 'type': 'streamlit'}'. This caused: Value error, Specified | | ||
| artefact foo_bar.py does not exist locally. | | ||
+------------------------------------------------------------------------------+ | ||
|
||
''' | ||
# --- | ||
# name: test_main_file_must_be_in_artifacts | ||
''' | ||
+- Error ----------------------------------------------------------------------+ | ||
| During evaluation of DefinitionV20 in project definition following errors | | ||
| were encountered: | | ||
| For field entities.my_streamlit.streamlit you provided '{'artifacts': | | ||
| ['streamlit_app.py', 'utils/utils.py', 'pages/', 'environment.yml'], | | ||
| 'main_file': 'foo_bar.py', 'name': 'test_streamlit_deploy_snowcli', | | ||
| 'query_warehouse': 'xsmall', 'stage': 'streamlit', 'title': 'My Fancy | | ||
| Streamlit', 'type': 'streamlit'}'. This caused: Value error, Specified main | | ||
| file foo_bar.py is not included in artifacts. | | ||
+------------------------------------------------------------------------------+ | ||
|
||
''' | ||
# --- |
Oops, something went wrong.