diff --git a/src/snowcli/cli/appify/commands.py b/src/snowcli/cli/appify/commands.py index a2661f28e2..da5574a4b0 100644 --- a/src/snowcli/cli/appify/commands.py +++ b/src/snowcli/cli/appify/commands.py @@ -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, @@ -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}.") diff --git a/src/snowcli/cli/appify/generate.py b/src/snowcli/cli/appify/generate.py index e69de29bb2..0837787cab 100644 --- a/src/snowcli/cli/appify/generate.py +++ b/src/snowcli/cli/appify/generate.py @@ -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()) diff --git a/src/snowcli/cli/appify/metadata.py b/src/snowcli/cli/appify/metadata.py index eb18bfc3b5..c7c37262aa 100644 --- a/src/snowcli/cli/appify/metadata.py +++ b/src/snowcli/cli/appify/metadata.py @@ -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