Skip to content

Commit

Permalink
SNOW-1653357 Refactor build_bundle to use method in ApplicationPackag…
Browse files Browse the repository at this point in the history
…eEntity (#1539)

Extracts the body of `ApplicationPackageEntity.action_bundle()` to a separate method and changes `NativeAppManager.build_bundle()` to use it too.
  • Loading branch information
sfc-gh-fcampbell authored Sep 6, 2024
1 parent 62d0c0f commit 4bfecfe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/snowflake/cli/_plugins/nativeapp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
from snowflake.cli._plugins.connection.util import make_snowsight_url
from snowflake.cli._plugins.nativeapp.artifacts import (
BundleMap,
build_bundle,
)
from snowflake.cli._plugins.nativeapp.codegen.compiler import (
NativeAppCompiler,
)
from snowflake.cli._plugins.nativeapp.constants import (
NAME_COL,
Expand Down Expand Up @@ -219,10 +215,14 @@ def build_bundle(self) -> BundleMap:
"""
Populates the local deploy root from artifact sources.
"""
bundle_map = build_bundle(self.project_root, self.deploy_root, self.artifacts)
compiler = NativeAppCompiler(self.na_project.get_bundle_context())
compiler.compile_artifacts()
return bundle_map
return ApplicationPackageEntity.bundle(
project_root=self.project_root,
deploy_root=self.deploy_root,
bundle_root=self.bundle_root,
generated_root=self.generated_root,
package_name=self.package_name,
artifacts=self.artifacts,
)

def sync_deploy_root_with_stage(
self,
Expand Down
37 changes: 27 additions & 10 deletions src/snowflake/cli/api/entities/application_package_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
ApplicationPackageEntityModel,
)
from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
from snowflake.cli.api.project.util import extract_schema
from snowflake.cli.api.rendering.jinja import (
get_basic_jinja_env,
Expand All @@ -63,20 +64,14 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):

def action_bundle(self, ctx: ActionContext):
model = self._entity_model
bundle_map = build_bundle(
ctx.project_root, Path(model.deploy_root), model.artifacts
)
bundle_context = BundleContext(
package_name=model.identifier,
artifacts=model.artifacts,
return self.bundle(
project_root=ctx.project_root,
bundle_root=Path(model.bundle_root),
deploy_root=Path(model.deploy_root),
bundle_root=Path(model.bundle_root),
generated_root=Path(model.generated_root),
package_name=model.identifier,
artifacts=model.artifacts,
)
compiler = NativeAppCompiler(bundle_context)
compiler.compile_artifacts()
return bundle_map

def action_deploy(
self,
Expand Down Expand Up @@ -193,6 +188,28 @@ def deploy_to_scratch_stage_fn():
)
ctx.console.message("Setup script is valid")

@staticmethod
def bundle(
project_root: Path,
deploy_root: Path,
bundle_root: Path,
generated_root: Path,
artifacts: list[PathMapping],
package_name: str,
):
bundle_map = build_bundle(project_root, deploy_root, artifacts)
bundle_context = BundleContext(
package_name=package_name,
artifacts=artifacts,
project_root=project_root,
bundle_root=bundle_root,
deploy_root=deploy_root,
generated_root=generated_root,
)
compiler = NativeAppCompiler(bundle_context)
compiler.compile_artifacts()
return bundle_map

@staticmethod
def get_existing_app_pkg_info(
package_name: str,
Expand Down

0 comments on commit 4bfecfe

Please sign in to comment.