-
Notifications
You must be signed in to change notification settings - Fork 54
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
Support project definition V2 in streamlit deploy command #1369
Changes from 5 commits
8d10ec2
5057e90
a117b5d
c7ea05e
e0cf215
d1b490e
69c9e8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 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 additional files which should be included into deployment artifacts", | ||
sfc-gh-turbaszek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if not artefact.exists(): | ||
raise ValueError( | ||
f"Specified artefact {artefact} does not exist locally." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
|
||
return self |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,9 @@ def _convert_env( | |
return env | ||
return ProjectEnvironment(default_env=(env or {}), override_env={}) | ||
|
||
def get_entities_by_type(self, entity_type: str): | ||
return {i: e for i, e in self.entities.items() if e.get_type() == entity_type} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sfc-gh-jsikorski you may be interested in this helper. |
||
|
||
def build_project_definition(**data): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
definition_version: "1.1" | ||
streamlit: | ||
name: streamlit_app | ||
stage: my_streamlit_stage | ||
query_warehouse: my_streamlit_warehouse | ||
main_file: streamlit_app.py | ||
env_file: environment.yml | ||
pages_dir: pages/ | ||
additional_source_files: | ||
- common/hello.py | ||
definition_version: "2" | ||
entities: | ||
my_streamlit: | ||
type: "streamlit" | ||
name: "my_dashboard" | ||
title: "My Streamlit Dashboard" | ||
stage: "my_streamlit_stage" | ||
query_warehouse: 'my_streamlit_warehouse' | ||
main_file: streamlit_app.py | ||
pages_dir: pages/ | ||
artifacts: | ||
- streamlit_app.py | ||
- environment.yml | ||
- common/hello.py | ||
- pages/ |
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.
We need to pull up the definition of
stage
andartifact
so the fields can be shared between Streamlit and Application Package (and likely function / spro).