Skip to content

Commit

Permalink
SNOW-1758715 Convert ApplicationPackageEntity.bundle to instance meth…
Browse files Browse the repository at this point in the history
…od (#1801)

Convert ApplicationPackageEntity.bundle to instance method
  • Loading branch information
sfc-gh-fcampbell authored Oct 25, 2024
1 parent f963b9f commit aadbc0f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,7 @@ class ApplicationPackageEntity(EntityBase[ApplicationPackageEntityModel]):
"""

def action_bundle(self, action_ctx: ActionContext, *args, **kwargs):
model = self._entity_model
workspace_ctx = self._workspace_ctx
return self.bundle(
project_root=workspace_ctx.project_root,
deploy_root=workspace_ctx.project_root / model.deploy_root,
bundle_root=workspace_ctx.project_root / model.bundle_root,
generated_root=(
workspace_ctx.project_root / model.deploy_root / model.generated_root
),
package_name=model.identifier,
artifacts=model.artifacts,
)
return self._bundle()

def action_deploy(
self,
Expand Down Expand Up @@ -330,13 +319,7 @@ def action_version_create(
package_name = model.fqn.identifier

console = workspace_ctx.console
project_root = workspace_ctx.project_root
deploy_root = workspace_ctx.project_root / model.deploy_root
bundle_root = workspace_ctx.project_root / model.bundle_root
generated_root = (
workspace_ctx.project_root / model.deploy_root / model.generated_root
)
package_role = (model.meta and model.meta.role) or workspace_ctx.default_role
stage_fqn = f"{package_name}.{model.stage}"

if force:
Expand All @@ -363,14 +346,7 @@ def action_version_create(
"""
)
)
bundle_map = self.bundle(
project_root=project_root,
deploy_root=deploy_root,
bundle_root=bundle_root,
generated_root=generated_root,
artifacts=model.artifacts,
package_name=package_name,
)
bundle_map = self._bundle()
version, patch = find_version_info_in_manifest_file(deploy_root)
if not version:
raise ClickException(
Expand Down Expand Up @@ -462,15 +438,8 @@ def action_version_drop(
package_name = model.fqn.identifier

console = workspace_ctx.console
project_root = workspace_ctx.project_root
deploy_root = workspace_ctx.project_root / model.deploy_root
bundle_root = workspace_ctx.project_root / model.bundle_root
generated_root = (
workspace_ctx.project_root / model.deploy_root / model.generated_root
)
artifacts = model.artifacts
package_role = (model.meta and model.meta.role) or workspace_ctx.default_role
package_distribution = model.distribution

if force:
interactive = False
Expand Down Expand Up @@ -503,14 +472,7 @@ def action_version_drop(
"""
)
)
self.bundle(
project_root=project_root,
deploy_root=deploy_root,
bundle_root=bundle_root,
generated_root=generated_root,
artifacts=artifacts,
package_name=package_name,
)
self._bundle()
version, _ = find_version_info_in_manifest_file(deploy_root)
if not version:
raise ClickException(
Expand Down Expand Up @@ -554,19 +516,21 @@ def action_version_drop(
f"Version {version} in application package {package_name} dropped successfully."
)

@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)
def _bundle(self):
model = self._entity_model
workspace_ctx = self._workspace_ctx

project_root = workspace_ctx.project_root
deploy_root = workspace_ctx.project_root / model.deploy_root
bundle_root = workspace_ctx.project_root / model.bundle_root
generated_root = (
workspace_ctx.project_root / model.deploy_root / model.generated_root
)

bundle_map = build_bundle(project_root, deploy_root, model.artifacts)
bundle_context = BundleContext(
package_name=package_name,
artifacts=artifacts,
package_name=model.fqn.identifier,
artifacts=model.artifacts,
project_root=project_root,
bundle_root=bundle_root,
deploy_root=deploy_root,
Expand Down Expand Up @@ -600,28 +564,12 @@ def _deploy(
policy = DenyAlwaysPolicy()

console = workspace_ctx.console
project_root = workspace_ctx.project_root
deploy_root = workspace_ctx.project_root / model.deploy_root
bundle_root = workspace_ctx.project_root / model.bundle_root
generated_root = (
workspace_ctx.project_root / model.deploy_root / model.generated_root
)
package_role = (model.meta and model.meta.role) or workspace_ctx.default_role
package_distribution = model.distribution
stage_fqn = stage_fqn or f"{package_name}.{model.stage}"
package_warehouse = (
model.meta and model.meta.warehouse
) or workspace_ctx.default_warehouse

# 1. Create a bundle if one wasn't passed in
bundle_map = bundle_map or self.bundle(
project_root=project_root,
deploy_root=deploy_root,
bundle_root=bundle_root,
generated_root=generated_root,
artifacts=model.artifacts,
package_name=package_name,
)
bundle_map = bundle_map or self._bundle()

# 2. Create an empty application package, if none exists
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/nativeapp/test_version_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_add_new_patch_custom(

# Test version create when user did not pass in a version AND we could not find a version in the manifest file either
@mock.patch(
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity.bundle",
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity._bundle",
return_value=None,
)
@mock.patch(
Expand Down
8 changes: 4 additions & 4 deletions tests/nativeapp/test_version_drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_process_has_no_existing_app_pkg(
)
@mock_get_app_pkg_distribution_in_sf()
@mock.patch(
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity.bundle",
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity._bundle",
return_value=None,
)
@mock.patch(
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_process_no_version_from_user_no_version_in_manifest(
)
@mock_get_app_pkg_distribution_in_sf()
@mock.patch(
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity.bundle",
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity._bundle",
return_value=None,
)
@mock.patch(
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_process_drop_cannot_complete(
)
@mock_get_app_pkg_distribution_in_sf()
@mock.patch(
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity.bundle",
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity._bundle",
return_value=None,
)
@mock.patch(
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_process_drop_from_manifest(
)
@mock_get_app_pkg_distribution_in_sf()
@mock.patch(
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity.bundle",
f"{APPLICATION_PACKAGE_ENTITY_MODULE}.ApplicationPackageEntity._bundle",
return_value=None,
)
@mock.patch(SQL_EXECUTOR_EXECUTE)
Expand Down

0 comments on commit aadbc0f

Please sign in to comment.