-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project definition v2 entity schemas: application and application package #1280
Changes from all commits
0eaf420
f7dc71f
1e806be
65d62f5
8126435
1858673
244483a
984a046
240fb53
d618d8f
cb7b090
35617a7
df209b3
2b85a04
4c84b9d
c66479e
2c9793d
fd475e9
1fd8975
79f06fb
56b9847
bd79cd0
a6c6ab2
90e6f2c
5227eda
d5188dc
6b3faa6
c25b4fb
1beb393
f4fa56a
c49d6d6
e0555b0
9665a6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (c) 2024 Snowflake Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Literal, Optional | ||
|
||
from pydantic import AliasChoices, Field | ||
from snowflake.cli.api.project.schemas.entities.application_package_entity import ( | ||
ApplicationPackageEntity, | ||
) | ||
from snowflake.cli.api.project.schemas.entities.common import ( | ||
EntityBase, | ||
TargetField, | ||
) | ||
from snowflake.cli.api.project.schemas.updatable_model import ( | ||
UpdatableModel, | ||
) | ||
|
||
|
||
class ApplicationEntity(EntityBase): | ||
type: Literal["application"] # noqa: A003 | ||
name: str = Field( | ||
title="Name of the application created when this entity is deployed" | ||
) | ||
from_: ApplicationFromField = Field( | ||
validation_alias=AliasChoices("from"), | ||
title="An application package this entity should be created from", | ||
) | ||
debug: Optional[bool] = Field( | ||
title="Whether to enable debug mode when using a named stage to create an application object", | ||
default=None, | ||
) | ||
|
||
|
||
class ApplicationFromField(UpdatableModel): | ||
target: TargetField[ApplicationPackageEntity] = Field( | ||
title="Reference to an application package entity", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) 2024 Snowflake Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import List, Literal, Optional, Union | ||
|
||
from pydantic import Field | ||
from snowflake.cli.api.project.schemas.entities.common import ( | ||
EntityBase, | ||
) | ||
from snowflake.cli.api.project.schemas.native_app.package import DistributionOptions | ||
from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping | ||
from snowflake.cli.api.project.schemas.updatable_model import IdentifierField | ||
|
||
|
||
class ApplicationPackageEntity(EntityBase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some properties not accounted for here, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added these as well. While we maintain both versions we will have to remember to update v2 schema when we make v1 changes. |
||
type: Literal["application package"] # noqa: A003 | ||
name: str = Field( | ||
title="Name of the application package created when this entity is deployed" | ||
) | ||
artifacts: List[Union[PathMapping, Path]] = Field( | ||
title="List of paths or file source/destination pairs to add to the deploy root", | ||
) | ||
bundle_root: Optional[Path] = Field( | ||
title="Folder at the root of your project where artifacts necessary to perform the bundle step are stored.", | ||
default=Path("output/bundle/"), | ||
) | ||
deploy_root: Optional[Path] = Field( | ||
title="Folder at the root of your project where the build step copies the artifacts", | ||
default=Path("output/deploy/"), | ||
) | ||
generated_root: Optional[Path] = Field( | ||
title="Subdirectory of the deploy root where files generated by the Snowflake CLI will be written.", | ||
default=Path("__generated/"), | ||
) | ||
stage: Optional[str] = IdentifierField( | ||
title="Identifier of the stage that stores the application artifacts.", | ||
default="app_src.stage", | ||
) | ||
scratch_stage: Optional[str] = IdentifierField( | ||
title="Identifier of the stage that stores temporary scratch data used by the Snowflake CLI.", | ||
default="app_src.stage_snowflake_cli_scratch", | ||
) | ||
distribution: Optional[DistributionOptions] = Field( | ||
title="Distribution of the application package created by the Snowflake CLI", | ||
default="internal", | ||
) | ||
manifest: Path = Field( | ||
title="Path to manifest.yml", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (c) 2024 Snowflake Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from abc import ABC | ||
from typing import Generic, List, Optional, TypeVar | ||
|
||
from pydantic import AliasChoices, Field, GetCoreSchemaHandler, ValidationInfo | ||
from pydantic_core import core_schema | ||
from snowflake.cli.api.project.schemas.native_app.application import ( | ||
ApplicationPostDeployHook, | ||
) | ||
from snowflake.cli.api.project.schemas.updatable_model import ( | ||
IdentifierField, | ||
UpdatableModel, | ||
) | ||
|
||
|
||
class MetaField(UpdatableModel): | ||
warehouse: Optional[str] = IdentifierField( | ||
title="Warehouse used to run the scripts", default=None | ||
) | ||
role: Optional[str] = IdentifierField( | ||
title="Role to use when creating the entity object", | ||
default=None, | ||
) | ||
post_deploy: Optional[List[ApplicationPostDeployHook]] = Field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this common for all entities? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep |
||
title="Actions that will be executed after the application object is created/upgraded", | ||
default=None, | ||
) | ||
|
||
|
||
class DefaultsField(UpdatableModel): | ||
schema_: Optional[str] = Field( | ||
title="Schema.", | ||
validation_alias=AliasChoices("schema"), | ||
default=None, | ||
) | ||
stage: Optional[str] = Field( | ||
title="Stage.", | ||
default=None, | ||
) | ||
|
||
|
||
class EntityBase(ABC, UpdatableModel): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Non-blocking) I would like to see e.g. |
||
@classmethod | ||
def get_type(cls) -> str: | ||
return cls.model_fields["type"].annotation.__args__[0] | ||
|
||
meta: Optional[MetaField] = Field(title="Meta fields", default=None) | ||
|
||
|
||
TargetType = TypeVar("TargetType") | ||
|
||
|
||
class TargetField(Generic[TargetType]): | ||
def __init__(self, entity_target_key: str): | ||
self.value = entity_target_key | ||
|
||
def __repr__(self): | ||
return self.value | ||
|
||
@classmethod | ||
def validate(cls, value: str, info: ValidationInfo) -> TargetField: | ||
return cls(value) | ||
|
||
@classmethod | ||
def __get_pydantic_core_schema__( | ||
cls, source_type, handler: GetCoreSchemaHandler | ||
) -> core_schema.CoreSchema: | ||
return core_schema.with_info_after_validator_function( | ||
cls.validate, handler(str), field_name=handler.field_name | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (c) 2024 Snowflake Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Union, get_args | ||
|
||
from snowflake.cli.api.project.schemas.entities.application_entity import ( | ||
ApplicationEntity, | ||
) | ||
from snowflake.cli.api.project.schemas.entities.application_package_entity import ( | ||
ApplicationPackageEntity, | ||
) | ||
|
||
Entity = Union[ApplicationEntity, ApplicationPackageEntity] | ||
|
||
ALL_ENTITIES = [*get_args(Entity)] | ||
|
||
v2_entity_types_map = {e.get_type(): e for e in ALL_ENTITIES} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Non-blocking) In the future, we should pull the generic type attr up, e.g.