Skip to content

Commit

Permalink
Override template context
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fcampbell committed Oct 1, 2024
1 parent 131ecc7 commit 3b79065
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,14 @@ def wrapper(*args, **kwargs):
is_package = isinstance(entity, ApplicationPackageEntityModel)
key = "package_entity_id" if is_package else "app_entity_id"
kwargs[key] = entity_id
get_cli_context_manager().override_project_definition = pdfv2
cm = get_cli_context_manager()
cm.override_project_definition = pdfv2
pdfv2_dump = pdfv2.model_dump(
exclude_none=True, warnings=False, by_alias=True
)
cm.override_template_context = cm.template_context | dict(
ctx=pdfv2_dump
)
else:
package_entity_id = kwargs.get("package_entity_id", "")
app_entity_id = kwargs.get("app_entity_id", "")
Expand Down
9 changes: 6 additions & 3 deletions src/snowflake/cli/api/cli_global_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ class _CliGlobalContextManager:
project_env_overrides_args: dict[str, str] = field(default_factory=dict)

# FIXME: this property only exists to help implement
# nativeapp_definition_v2_to_v1. Consider changing the way
# this calculation is provided to commands in order to remove
# this logic (then make project_definition a non-cloned @property)
# nativeapp_definition_v2_to_v1 and single_app_and_package.
# Consider changing the way this calculation is provided to commands
# in order to remove this logic (then make project_definition a non-cloned @property)
override_project_definition: ProjectDefinition | None = None
override_template_context: dict | None = None

_definition_manager: DefinitionManager | None = None

Expand Down Expand Up @@ -97,6 +98,8 @@ def project_root(self) -> Path:

@property
def template_context(self) -> dict:
if self.override_template_context:
return self.override_template_context
return self._definition_manager_or_raise().template_context

@property
Expand Down

0 comments on commit 3b79065

Please sign in to comment.