Skip to content

Commit

Permalink
Bring back glob support in streamlit (#1605)
Browse files Browse the repository at this point in the history
* Bring back glob support in streamlit

* fixup! Bring back glob support in streamlit
  • Loading branch information
sfc-gh-turbaszek committed Sep 20, 2024
1 parent bebcf2a commit 0dd7426
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 43 deletions.
13 changes: 2 additions & 11 deletions src/snowflake/cli/_plugins/streamlit/streamlit_entity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,14 @@ class StreamlitEntityModel(EntityModelBase, ExternalAccessBaseModel, ImportsBase
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 artifact in self.artifacts:
if "*" in artifact.name:
continue
if not artifact.exists():
raise ValueError(
f"Specified artifact {artifact} does not exist locally."
Expand Down
15 changes: 0 additions & 15 deletions tests/streamlit/__snapshots__/test_commands.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@

'''
# ---
# 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'], |
| 'identifier': 'test_streamlit_deploy_snowcli', 'main_file': 'foo_bar.py', |
| '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. |
+------------------------------------------------------------------------------+

'''
# ---
# name: test_multiple_streamlit_raise_error_if_multiple_entities
'''
Usage: default streamlit deploy [OPTIONS] [ENTITY_ID]
Expand Down
17 changes: 0 additions & 17 deletions tests/streamlit/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,6 @@ def test_deploy_only_streamlit_file_replace(
mock_typer.launch.assert_not_called()


def test_main_file_must_be_in_artifacts(
runner, mock_ctx, project_directory, alter_snowflake_yml, snapshot
):
with project_directory("example_streamlit_v2") as pdir:
alter_snowflake_yml(
pdir / "snowflake.yml",
parameter_path="entities.my_streamlit.main_file",
value="foo_bar.py",
)

result = runner.invoke(
["streamlit", "deploy"],
)
assert result.exit_code == 1
assert result.output == snapshot


def test_artifacts_must_exists(
runner, mock_ctx, project_directory, alter_snowflake_yml, snapshot
):
Expand Down
21 changes: 21 additions & 0 deletions tests_integration/test_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ def test_streamlit_deploy_with_imports(
assert result.json[0]["import_urls"] == '["@stage/foo.py","@stage/bar.py"]'


@pytest.mark.integration
@pytest.mark.parametrize("pattern", ["*.py", "*"])
def test_streamlit_deploy_with_glob_patterns(
pattern,
runner,
snowflake_session,
test_database,
_new_streamlit_role,
project_directory,
alter_snowflake_yml,
):
with project_directory(f"streamlit_v2"):
alter_snowflake_yml(
"snowflake.yml", "entities.my_streamlit.artifacts", [pattern]
)
result = runner.invoke_with_connection_json(
["streamlit", "deploy", "--replace"]
)
assert result.exit_code == 0


@pytest.mark.integration
@pytest.mark.skip(
reason="only works in accounts with experimental checkout behavior enabled"
Expand Down

0 comments on commit 0dd7426

Please sign in to comment.