-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from StrictYAML to Pydantic (#870)
* Revert "Bump tomlkit from 0.12.3 to 0.12.4 (#848)" (#863) This reverts commit 80467b3. mraba/app-factory: create app with factory (#860) * mraba/app-factory: create app with factory SNOW-1043081: Adding support for qualified names for image repositories. (#823) * SNOW-1043081: Adding support for qualified image repository names * SNOW-1043081: Fixing test imports * SNOW-1043081: Adding tests for getting image repository url without db or schema SNOW-1011771: Added generic REPLACE, IF EXISTS, IF NOT EXISTS flags (#826) * SNOW-1011771: Adding generic OR REPLACE, IF EXISTS, IF NOT EXISTS flags to flags.py * SNOW-1011771: Using generic ReplaceOption in snowpark deploy and streamlit deploy * SNOW-1011771: Using generic IfNotExistsOption in compute pool create and updating unit tests. * SNOW-1011771: Using generic IfNotExistsOption in service create and updating unit tests * SNOW-1011771: Using generic ReplaceOption and IfNotExistsOption in image-repository create. * SNOW-1011771: Fixup * SNOW-1011771: Update release notes * SNOW-1011771: Update test_help_messages * SNOW-1011771: precommit * SNOW-1011771: Adding validation that only one create mode option can be set at once * fixup * SNOW-1011771: Updating tests for REPLACE AND IF NOT EXISTS case on image-repository create to throw error * SNOW-1011771: Adding snapshots * SNOW-1011771: Adding a new mutually_exclusive field to OverrideableOption * formatting * SNOW-1011771: Adding tests for OverrideableOption * SNOW-1011771: Fixing test failures due to improperly quoted string Add snow --help to test_help_messages (#821) * Add snow --help to test_help_messages * update snapshot Avoid plain print, make sure silent is eager flag (#871) [NADE] Update CODEOWNERS to use NADE team id. (#873) update to using nade team in codeowners New workflow to stop running workflows after new commit (#862) * new workflow * new workflow * new workflow * new workflow * typo fix * typo fix * import fix * import fix * import fix * import fix * import fix * import fix * import fix * new approach * new approach * new approach * new approach * new approach * New approach * added to test * Added to more workflows * Dummy commit Schemas adjusting native apps to streamlit fixing streamlit fixies after unit tests fixies after unit tests fixing for snowflake fixing for snowflake Fixes after review Fixes after review Fixes after review * Fixes after review * Implemented error class * Fixes * Fixes * Fixes * Fixes * typo fix * Added unit test * Added unit test * Fixes after review * Fixes after review * Fixes * Fixes * Fixes --------- Co-authored-by: Adam Stus <adam.stus@snowflake.com>
- Loading branch information
1 parent
d53aacd
commit 99b96c4
Showing
42 changed files
with
1,299 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from textwrap import dedent | ||
|
||
from pydantic import ValidationError | ||
|
||
|
||
class SchemaValidationError(Exception): | ||
generic_message = "For field {loc} you provided '{loc}'. This caused: {msg}" | ||
message_templates = { | ||
"string_type": "{msg} for field '{loc}', you provided '{input}'", | ||
"extra_forbidden": "{msg}. You provided field '{loc}' with value '{input}' that is not present in the schema", | ||
"missing": "Your project definition is missing following fields: {loc}", | ||
} | ||
|
||
def __init__(self, error: ValidationError): | ||
errors = error.errors() | ||
message = f"During evaluation of {error.title} schema following errors were encoutered:\n" | ||
message += "\n".join( | ||
[ | ||
self.message_templates.get(e["type"], self.generic_message).format(**e) | ||
for e in errors | ||
] | ||
) | ||
|
||
super().__init__(dedent(message)) |
This file was deleted.
Oops, something went wrong.
Empty file.
31 changes: 31 additions & 0 deletions
31
src/snowflake/cli/api/project/schemas/native_app/application.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal, Optional | ||
|
||
from pydantic import Field | ||
from snowflake.cli.api.project.schemas.updatable_model import ( | ||
IdentifierField, | ||
UpdatableModel, | ||
) | ||
|
||
|
||
class Application(UpdatableModel): | ||
role: Optional[str] = Field( | ||
title="Role to use when creating the application object and consumer-side objects", | ||
default=None, | ||
) | ||
name: Optional[str] = Field( | ||
title="Name of the application object created when you run the snow app run command", | ||
default=None, | ||
) | ||
warehouse: Optional[str] = IdentifierField( | ||
title="Name of the application object created when you run the snow app run command", | ||
default=None, | ||
) | ||
debug: Optional[bool] = Field( | ||
title="Whether to enable debug mode when using a named stage to create an application object", | ||
default=True, | ||
) | ||
|
||
|
||
DistributionOptions = Literal["internal", "external", "INTERNAL", "EXTERNAL"] |
39 changes: 39 additions & 0 deletions
39
src/snowflake/cli/api/project/schemas/native_app/native_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
import re | ||
from typing import List, Optional, Union | ||
|
||
from pydantic import Field, field_validator | ||
from snowflake.cli.api.project.schemas.native_app.application import Application | ||
from snowflake.cli.api.project.schemas.native_app.package import Package | ||
from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping | ||
from snowflake.cli.api.project.schemas.updatable_model import UpdatableModel | ||
from snowflake.cli.api.project.util import ( | ||
SCHEMA_AND_NAME, | ||
) | ||
|
||
|
||
class NativeApp(UpdatableModel): | ||
name: str = Field( | ||
title="Project identifier", | ||
) | ||
artifacts: List[Union[PathMapping, str]] = Field( | ||
title="List of file source and destination pairs to add to the deploy root", | ||
) | ||
deploy_root: Optional[str] = Field( | ||
title="Folder at the root of your project where the build step copies the artifacts.", | ||
default="output/deploy/", | ||
) | ||
source_stage: Optional[str] = Field( | ||
title="Identifier of the stage that stores the application artifacts.", | ||
default="app_src.stage", | ||
) | ||
package: Optional[Package] = Field(title="PackageSchema", default=None) | ||
application: Optional[Application] = Field(title="Application info", default=None) | ||
|
||
@field_validator("source_stage") | ||
@classmethod | ||
def validate_source_stage(cls, input_value: str): | ||
if not re.match(SCHEMA_AND_NAME, input_value): | ||
raise ValueError("Incorrect value for source_stage value of native_app") | ||
return input_value |
40 changes: 40 additions & 0 deletions
40
src/snowflake/cli/api/project/schemas/native_app/package.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List, Optional | ||
|
||
from pydantic import Field, field_validator | ||
from snowflake.cli.api.project.schemas.native_app.application import DistributionOptions | ||
from snowflake.cli.api.project.schemas.updatable_model import ( | ||
IdentifierField, | ||
UpdatableModel, | ||
) | ||
|
||
|
||
class Package(UpdatableModel): | ||
scripts: Optional[List[str]] = Field( | ||
title="List of SQL file paths relative to the project root", default=None | ||
) | ||
role: Optional[str] = IdentifierField( | ||
title="Role to use when creating the application package and provider-side objects", | ||
default=None, | ||
) | ||
name: Optional[str] = IdentifierField( | ||
title="Name of the application package created when you run the snow app run command", | ||
default=None, | ||
) | ||
warehouse: Optional[str] = IdentifierField( | ||
title="Warehouse used to run the scripts", default=None | ||
) | ||
distribution: Optional[DistributionOptions] = Field( | ||
title="Distribution of the application package created by the Snowflake CLI", | ||
default="internal", | ||
) | ||
|
||
@field_validator("scripts") | ||
@classmethod | ||
def validate_scripts(cls, input_list): | ||
if len(input_list) != len(set(input_list)): | ||
raise ValueError( | ||
"package.scripts field should contain unique values. Check the list for duplicates and try again" | ||
) | ||
return input_list |
10 changes: 10 additions & 0 deletions
10
src/snowflake/cli/api/project/schemas/native_app/path_mapping.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from snowflake.cli.api.project.schemas.updatable_model import UpdatableModel | ||
|
||
|
||
class PathMapping(UpdatableModel): | ||
src: str | ||
dest: Optional[str] = None |
42 changes: 23 additions & 19 deletions
42
src/snowflake/cli/api/project/schemas/project_definition.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
from snowflake.cli.api.project.schemas import ( | ||
native_app, | ||
snowpark, | ||
streamlit, | ||
) | ||
from snowflake.cli.api.project.schemas.relaxed_map import RelaxedMap | ||
from strictyaml import ( | ||
Int, | ||
Optional, | ||
) | ||
from typing import Optional | ||
|
||
project_schema = RelaxedMap( | ||
{ | ||
"definition_version": Int(), | ||
Optional("native_app"): native_app.native_app_schema, | ||
Optional("snowpark"): snowpark.snowpark_schema, | ||
Optional("streamlit"): streamlit.streamlit_schema, | ||
} | ||
) | ||
from pydantic import Field | ||
from snowflake.cli.api.project.schemas.native_app.native_app import NativeApp | ||
from snowflake.cli.api.project.schemas.snowpark.snowpark import Snowpark | ||
from snowflake.cli.api.project.schemas.streamlit.streamlit import Streamlit | ||
from snowflake.cli.api.project.schemas.updatable_model import UpdatableModel | ||
|
||
project_override_schema = project_schema.as_fully_optional() | ||
|
||
class ProjectDefinition(UpdatableModel): | ||
definition_version: int = Field( | ||
title="Version of the project definition schema, which is currently 1", | ||
ge=1, | ||
le=1, | ||
) | ||
native_app: Optional[NativeApp] = Field( | ||
title="Native app definitions for the project", default=None | ||
) | ||
snowpark: Optional[Snowpark] = Field( | ||
title="Snowpark functions and procedures definitions for the project", | ||
default=None, | ||
) | ||
streamlit: Optional[Streamlit] = Field( | ||
title="Streamlit definitions for the project", default=None | ||
) |
Oops, something went wrong.