Skip to content

Commit

Permalink
include stages in snowflake.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-cgorrie committed Dec 12, 2023
1 parent 48ca3e2 commit 1b57bb3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/snowcli/cli/appify/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
from typing import Optional

import typer
from snowcli.cli.common.decorators import (
global_options,
global_options_with_connection,
)
from snowcli.cli.common.decorators import global_options_with_connection
from snowcli.cli.common.flags import DEFAULT_CONTEXT_SETTINGS
from snowcli.cli.nativeapp.init import nativeapp_init
from snowcli.output.decorators import with_output
from snowcli.output.types import CommandResult, MessageResult

from snowcli.cli.appify.metadata import MetadataDumper
from snowcli.cli.appify.generate import modify_yml

# from snowcli.cli.appify.generate import ...
from strictyaml import as_document

app = typer.Typer(
context_settings=DEFAULT_CONTEXT_SETTINGS,
Expand Down Expand Up @@ -48,7 +46,14 @@ def appify(
dumper = MetadataDumper(db, project.path)
dumper.execute()

# for stage in dumper.stages:
# pass
with modify_yml(project.path / "snowflake.yml") as snowflake_yml:
native_app = snowflake_yml["native_app"]

# include referenced stages in our app stage
artifacts = native_app["artifacts"].data
for stage_id in dumper.referenced_stage_ids:
stage_path = dumper.get_stage_path(stage_id).relative_to(project.path)
artifacts.append(str(stage_path))
native_app["artifacts"] = as_document(artifacts)

return MessageResult(f"Created Native Application project from {db}.")
20 changes: 20 additions & 0 deletions src/snowcli/cli/appify/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Generator
from contextlib import contextmanager
from pathlib import Path
from strictyaml import YAML, load

from snowcli.cli.project.schemas.project_definition import project_schema


@contextmanager
def modify_yml(path: Path) -> Generator[YAML, None, None]:
"""
Read, then write back modifications made to a YAML file.
"""
with open(path, "r") as f:
yml = load(f.read(), schema=project_schema)

yield yml

with open(path, "w") as f:
f.write(yml.as_yaml())
4 changes: 2 additions & 2 deletions src/snowcli/cli/appify/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def _is_procedure_callers_rights(self, identifier: str) -> str:

def _get_callable_stage_ids(self, domain: str, identifier: str) -> List[str]:
"""
Returns the stage IDs that are imported by this procedure,
or the empty list if the procedure is not backed by code in a stage.
Returns the stage IDs that are imported by this callable (procedure / function),
or the empty list if the callable is not backed by code in a stage.
"""
cursor = self._execute_query(
f"describe {domain} {identifier}", cursor_class=DictCursor
Expand Down

0 comments on commit 1b57bb3

Please sign in to comment.