Skip to content

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astus committed Jan 8, 2025
1 parent 7be499c commit 1d6e6c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
37 changes: 13 additions & 24 deletions src/snowflake/cli/_plugins/streamlit/streamlit_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

from click import ClickException
from snowflake.cli._plugins.connection.util import make_snowsight_url
from snowflake.cli._plugins.nativeapp.artifacts import build_bundle
from snowflake.cli._plugins.nativeapp.feature_flags import FeatureFlag
from snowflake.cli._plugins.streamlit.streamlit_entity_model import (
StreamlitEntityModel,
)
from snowflake.cli._plugins.workspace.context import ActionContext
from snowflake.cli.api.entities.common import EntityBase, get_sql_executor
from snowflake.cli.api.secure_path import SecurePath
from snowflake.cli.api.project.project_paths import bundle_root
from snowflake.cli.api.project.schemas.entities.common import PathMapping
from snowflake.connector.cursor import SnowflakeCursor


Expand Down Expand Up @@ -70,29 +72,16 @@ def action_get_url(
)

def bundle(self, output_dir: Optional[Path] = None):

if not output_dir:
output_dir = self.root / "output" / self._entity_model.stage

artifacts = self._entity_model.artifacts

output_dir.mkdir(parents=True, exist_ok=True) # type: ignore

output_files = []

# This is far from , but will be replaced by bundlemap mappings.
for file in artifacts:
output_file = output_dir / file.name

if file.is_file():
SecurePath(file).copy(output_file)
elif file.is_dir():
output_file.mkdir(parents=True, exist_ok=True)
SecurePath(file).copy(output_file, dirs_exist_ok=True)

output_files.append(output_file)

return output_files
return build_bundle(
self.root,
output_dir or bundle_root(self.root, "streamlit"),
[
PathMapping(
src=artifact.src, dest=artifact.dest, processors=artifact.processors
)
for artifact in self._entity_model.artifacts
],
)

def action_share(
self, action_ctx: ActionContext, to_role: str, *args, **kwargs
Expand Down
4 changes: 2 additions & 2 deletions tests/streamlit/test_streamlit_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_nativeapp_children_interface(example_streamlit_workspace, snapshot):
sl, action_context = example_streamlit_workspace

sl.bundle()
bundle_artifact = sl.root / "output" / "bundle" / sl.model.stage / "streamlit_app.py"
bundle_artifact = sl.root / "output" / "bundle" / "streamlit" / "streamlit_app.py"
deploy_sql_str = sl.get_deploy_sql()
grant_sql_str = sl.get_usage_grant_sql(app_role="app_role")

Expand All @@ -75,7 +75,7 @@ def test_bundle(example_streamlit_workspace):
entity, action_ctx = example_streamlit_workspace
entity.action_bundle(action_ctx)

output = entity.root / "output" / entity._entity_model.stage # noqa
output = entity.root / "output" / "bundle" / "streamlit" # noqa

assert output.exists()
assert (output / "streamlit_app.py").exists()
Expand Down
6 changes: 4 additions & 2 deletions tests/streamlit/test_streamlit_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ def test_deploy_streamlit_with_default_warehouse(
identifier="my_streamlit_app",
title="MyStreamlit",
main_file=str(main_file),
artifacts=[main_file],
artifacts=["main.py"],
comment="This is a test comment",
)

StreamlitManager(MagicMock(database="DB", schema="SH")).deploy(
streamlit=st, replace=False
streamlit=st,
streamlit_project_paths=StreamlitProjectPaths(Path(temp_dir)),
replace=False,
)

mock_execute_query.assert_called_once_with(
Expand Down

0 comments on commit 1d6e6c1

Please sign in to comment.