snowflake-cli-labs 2.8.0rc1__py3-none-any.whl → 3.0.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/cli/__about__.py +1 -1
- snowflake/cli/{app → _app}/__main__.py +1 -1
- snowflake/cli/{app → _app}/cli_app.py +12 -12
- snowflake/cli/{app → _app}/commands_registration/builtin_plugins.py +13 -19
- snowflake/cli/{app → _app}/commands_registration/command_plugins_loader.py +9 -9
- snowflake/cli/{app → _app}/commands_registration/commands_registration_with_callbacks.py +4 -4
- snowflake/cli/{app → _app}/commands_registration/exception_logging.py +2 -2
- snowflake/cli/{app → _app}/commands_registration/typer_registration.py +2 -2
- snowflake/cli/{app → _app}/dev/docs/commands_docs_generator.py +30 -12
- snowflake/cli/{app → _app}/dev/docs/generator.py +3 -3
- snowflake/cli/{app → _app}/dev/docs/project_definition_docs_generator.py +4 -4
- snowflake/cli/{app → _app}/dev/docs/templates/usage.rst.jinja2 +14 -4
- snowflake/cli/{app → _app}/main_typer.py +2 -2
- snowflake/cli/{app → _app}/printing.py +2 -2
- snowflake/cli/{app → _app}/snow_connector.py +24 -17
- snowflake/cli/{app → _app}/telemetry.py +4 -5
- snowflake/cli/{plugins → _plugins}/connection/commands.py +25 -7
- snowflake/cli/_plugins/connection/plugin_spec.py +30 -0
- snowflake/cli/{plugins → _plugins}/connection/util.py +16 -0
- snowflake/cli/{plugins → _plugins}/cortex/commands.py +54 -49
- snowflake/cli/{plugins → _plugins}/cortex/constants.py +1 -1
- snowflake/cli/{plugins → _plugins}/cortex/manager.py +5 -5
- snowflake/cli/{plugins → _plugins}/cortex/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/git/commands.py +32 -20
- snowflake/cli/{plugins → _plugins}/git/manager.py +20 -11
- snowflake/cli/{plugins → _plugins}/git/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/init/commands.py +10 -6
- snowflake/cli/{plugins → _plugins}/init/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/artifacts.py +14 -0
- snowflake/cli/_plugins/nativeapp/bundle_context.py +31 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/artifact_processor.py +3 -3
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/compiler.py +32 -18
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +249 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/setup_driver.py.source +5 -2
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +4 -4
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +23 -29
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +93 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +171 -42
- snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/exceptions.py +3 -3
- snowflake/cli/{plugins → _plugins}/nativeapp/init.py +1 -1
- snowflake/cli/_plugins/nativeapp/manager.py +572 -0
- snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +35 -19
- snowflake/cli/{plugins → _plugins}/nativeapp/run_processor.py +25 -23
- snowflake/cli/{plugins → _plugins}/nativeapp/teardown_processor.py +24 -110
- snowflake/cli/{plugins → _plugins}/nativeapp/v2_conversions/v2_to_v1_decorator.py +47 -28
- snowflake/cli/{plugins → _plugins}/nativeapp/version/commands.py +15 -12
- snowflake/cli/{plugins → _plugins}/nativeapp/version/version_processor.py +22 -20
- snowflake/cli/{plugins → _plugins}/notebook/commands.py +8 -6
- snowflake/cli/{plugins → _plugins}/notebook/manager.py +14 -14
- snowflake/cli/{plugins → _plugins}/notebook/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/notebook/types.py +0 -1
- snowflake/cli/{plugins → _plugins}/object/command_aliases.py +6 -5
- snowflake/cli/{plugins → _plugins}/object/commands.py +16 -10
- snowflake/cli/{plugins → _plugins}/object/manager.py +7 -6
- snowflake/cli/{plugins → _plugins}/object/plugin_spec.py +1 -1
- snowflake/cli/_plugins/snowpark/commands.py +450 -0
- snowflake/cli/_plugins/snowpark/common.py +268 -0
- snowflake/cli/{plugins → _plugins}/snowpark/models.py +0 -7
- snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +2 -36
- snowflake/cli/{plugins → _plugins}/snowpark/package/commands.py +13 -74
- snowflake/cli/{plugins → _plugins}/snowpark/package/manager.py +4 -3
- snowflake/cli/{plugins → _plugins}/snowpark/package_utils.py +5 -5
- snowflake/cli/{plugins/nativeapp → _plugins/snowpark}/plugin_spec.py +1 -1
- snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +109 -0
- snowflake/cli/{plugins → _plugins}/snowpark/snowpark_shared.py +0 -36
- snowflake/cli/{plugins → _plugins}/snowpark/zipper.py +16 -8
- snowflake/cli/{plugins → _plugins}/spcs/__init__.py +5 -7
- snowflake/cli/{plugins → _plugins}/spcs/compute_pool/commands.py +29 -28
- snowflake/cli/{plugins → _plugins}/spcs/compute_pool/manager.py +3 -3
- snowflake/cli/{plugins → _plugins}/spcs/image_registry/commands.py +3 -3
- snowflake/cli/{plugins → _plugins}/spcs/image_repository/commands.py +25 -19
- snowflake/cli/{plugins → _plugins}/spcs/image_repository/manager.py +1 -1
- snowflake/cli/{plugins → _plugins}/spcs/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/spcs/services/commands.py +66 -32
- snowflake/cli/{plugins → _plugins}/spcs/services/manager.py +43 -5
- snowflake/cli/{plugins → _plugins}/sql/commands.py +20 -17
- snowflake/cli/{plugins → _plugins}/sql/manager.py +1 -1
- snowflake/cli/{plugins → _plugins}/sql/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/stage/commands.py +20 -17
- snowflake/cli/{plugins → _plugins}/stage/diff.py +1 -47
- snowflake/cli/{plugins → _plugins}/stage/manager.py +54 -21
- snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
- snowflake/cli/_plugins/stage/utils.py +54 -0
- snowflake/cli/{plugins → _plugins}/streamlit/commands.py +59 -62
- snowflake/cli/{plugins → _plugins}/streamlit/manager.py +51 -70
- snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
- snowflake/cli/_plugins/workspace/action_context.py +17 -0
- snowflake/cli/_plugins/workspace/commands.py +194 -0
- snowflake/cli/_plugins/workspace/manager.py +73 -0
- snowflake/cli/{plugins → _plugins}/workspace/plugin_spec.py +1 -1
- snowflake/cli/api/cli_global_context.py +40 -13
- snowflake/cli/api/commands/common.py +25 -0
- snowflake/cli/api/commands/decorators.py +5 -4
- snowflake/cli/api/commands/experimental_behaviour.py +2 -3
- snowflake/cli/api/commands/flags.py +97 -179
- snowflake/cli/api/commands/overrideable_parameter.py +143 -0
- snowflake/cli/api/commands/snow_typer.py +14 -6
- snowflake/cli/api/commands/typer_pre_execute.py +3 -3
- snowflake/cli/api/commands/utils.py +18 -0
- snowflake/cli/api/config.py +18 -5
- snowflake/cli/api/console/abc.py +5 -2
- snowflake/cli/api/constants.py +11 -0
- snowflake/cli/api/entities/application_entity.py +12 -0
- snowflake/cli/api/entities/application_package_entity.py +553 -0
- snowflake/cli/api/entities/common.py +51 -0
- snowflake/cli/api/entities/snowpark_entity.py +29 -0
- snowflake/cli/api/entities/streamlit_entity.py +12 -0
- snowflake/cli/api/entities/utils.py +357 -0
- snowflake/cli/api/exceptions.py +31 -5
- snowflake/cli/api/feature_flags.py +0 -1
- snowflake/cli/api/identifiers.py +41 -9
- snowflake/cli/api/project/definition.py +37 -6
- snowflake/cli/api/project/definition_conversion.py +194 -0
- snowflake/cli/api/project/definition_manager.py +12 -1
- snowflake/cli/api/project/project_verification.py +3 -3
- snowflake/cli/api/project/schemas/entities/{application_entity.py → application_entity_model.py} +21 -9
- snowflake/cli/api/project/schemas/entities/{application_package_entity.py → application_package_entity_model.py} +43 -15
- snowflake/cli/api/project/schemas/entities/common.py +80 -6
- snowflake/cli/api/project/schemas/entities/entities.py +38 -8
- snowflake/cli/api/project/schemas/entities/snowpark_entity.py +176 -0
- snowflake/cli/api/project/schemas/entities/streamlit_entity_model.py +73 -0
- snowflake/cli/api/project/schemas/identifier_model.py +10 -1
- snowflake/cli/api/project/schemas/native_app/application.py +8 -9
- snowflake/cli/api/project/schemas/native_app/package.py +7 -1
- snowflake/cli/api/project/schemas/project_definition.py +98 -27
- snowflake/cli/api/project/schemas/updatable_model.py +11 -3
- snowflake/cli/api/project/util.py +23 -6
- snowflake/cli/api/rendering/jinja.py +14 -8
- snowflake/cli/api/rendering/project_definition_templates.py +1 -1
- snowflake/cli/api/rendering/sql_templates.py +43 -11
- snowflake/cli/api/secure_path.py +16 -18
- snowflake/cli/api/secure_utils.py +90 -1
- snowflake/cli/api/sql_execution.py +48 -19
- snowflake/cli/api/utils/definition_rendering.py +18 -8
- {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/METADATA +13 -13
- snowflake_cli_labs-3.0.0rc1.dist-info/RECORD +236 -0
- snowflake_cli_labs-3.0.0rc1.dist-info/entry_points.txt +2 -0
- snowflake/cli/api/commands/project_initialisation.py +0 -65
- snowflake/cli/app/build_and_push.sh +0 -8
- snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
- snowflake/cli/plugins/nativeapp/manager.py +0 -823
- snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
- snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
- snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
- snowflake/cli/plugins/snowpark/commands.py +0 -548
- snowflake/cli/plugins/snowpark/common.py +0 -307
- snowflake/cli/plugins/snowpark/manager.py +0 -109
- snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
- snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
- snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
- snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
- snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
- snowflake/cli/plugins/workspace/commands.py +0 -35
- snowflake/cli/templates/default_snowpark/.gitignore +0 -4
- snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
- snowflake/cli/templates/default_snowpark/app/common.py +0 -2
- snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
- snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
- snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
- snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
- snowflake/cli/templates/default_streamlit/.gitignore +0 -4
- snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
- snowflake/cli/templates/default_streamlit/environment.yml +0 -6
- snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
- snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
- snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
- snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
- snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
- /snowflake/cli/{app → _app}/__init__.py +0 -0
- /snowflake/cli/{app → _app}/api_impl/__init__.py +0 -0
- /snowflake/cli/{app → _app}/api_impl/plugin/__init__.py +0 -0
- /snowflake/cli/{app → _app}/api_impl/plugin/plugin_config_provider_impl.py +0 -0
- /snowflake/cli/{app → _app}/commands_registration/__init__.py +0 -0
- /snowflake/cli/{app → _app}/commands_registration/threadsafe.py +0 -0
- /snowflake/cli/{app → _app}/constants.py +0 -0
- /snowflake/cli/{app → _app}/dev/__init__.py +0 -0
- /snowflake/cli/{app → _app}/dev/commands_structure.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/__init__.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/project_definition_generate_json_schema.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/template_utils.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/templates/definition_description.rst.jinja2 +0 -0
- /snowflake/cli/{app → _app}/dev/docs/templates/overview.rst.jinja2 +0 -0
- /snowflake/cli/{app → _app}/dev/pycharm_remote_debug.py +0 -0
- /snowflake/cli/{app → _app}/loggers.py +0 -0
- /snowflake/cli/{plugins → _plugins}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/connection/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/cortex/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/cortex/types.py +0 -0
- /snowflake/cli/{plugins → _plugins}/git/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/init/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/sandbox.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/models.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/constants.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/feature_flags.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/policy.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/utils.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/version/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/notebook/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/notebook/exceptions.py +0 -0
- /snowflake/cli/{plugins → _plugins}/object/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/object/common.py +0 -0
- /snowflake/cli/{plugins → _plugins}/snowpark/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/snowpark/package/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/snowpark/package/utils.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/common.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/compute_pool/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/image_registry/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/image_registry/manager.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/image_repository/__init__.py +0 -0
- /snowflake/cli/{plugins/spcs/jobs → _plugins/spcs/services}/__init__.py +0 -0
- /snowflake/cli/{plugins/spcs/services → _plugins/sql}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/sql/snowsql_templating.py +0 -0
- /snowflake/cli/{plugins/sql → _plugins/stage}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/stage/md5.py +0 -0
- /snowflake/cli/{plugins/stage → _plugins/streamlit}/__init__.py +0 -0
- /snowflake/cli/{plugins/streamlit → _plugins/workspace}/__init__.py +0 -0
- /snowflake/cli/{plugins/workspace → api/project/schemas/entities}/__init__.py +0 -0
- {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-3.0.0rc1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from textwrap import dedent
|
|
4
|
+
from typing import Any, List, NoReturn, Optional
|
|
5
|
+
|
|
6
|
+
import jinja2
|
|
7
|
+
from click import ClickException
|
|
8
|
+
from snowflake.cli._plugins.nativeapp.artifacts import (
|
|
9
|
+
BundleMap,
|
|
10
|
+
resolve_without_follow,
|
|
11
|
+
)
|
|
12
|
+
from snowflake.cli._plugins.nativeapp.constants import OWNER_COL
|
|
13
|
+
from snowflake.cli._plugins.nativeapp.exceptions import (
|
|
14
|
+
InvalidTemplateInFileError,
|
|
15
|
+
MissingScriptError,
|
|
16
|
+
UnexpectedOwnerError,
|
|
17
|
+
)
|
|
18
|
+
from snowflake.cli._plugins.nativeapp.utils import verify_exists, verify_no_directories
|
|
19
|
+
from snowflake.cli._plugins.stage.diff import (
|
|
20
|
+
DiffResult,
|
|
21
|
+
StagePath,
|
|
22
|
+
compute_stage_diff,
|
|
23
|
+
preserve_from_diff,
|
|
24
|
+
sync_local_diff_with_stage,
|
|
25
|
+
to_stage_path,
|
|
26
|
+
)
|
|
27
|
+
from snowflake.cli._plugins.stage.utils import print_diff_to_console
|
|
28
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
29
|
+
from snowflake.cli.api.console.abc import AbstractConsole
|
|
30
|
+
from snowflake.cli.api.entities.common import get_sql_executor
|
|
31
|
+
from snowflake.cli.api.errno import (
|
|
32
|
+
DOES_NOT_EXIST_OR_CANNOT_BE_PERFORMED,
|
|
33
|
+
NO_WAREHOUSE_SELECTED_IN_SESSION,
|
|
34
|
+
)
|
|
35
|
+
from snowflake.cli.api.exceptions import SnowflakeSQLExecutionError
|
|
36
|
+
from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
|
|
37
|
+
from snowflake.cli.api.project.util import unquote_identifier
|
|
38
|
+
from snowflake.cli.api.rendering.sql_templates import (
|
|
39
|
+
choose_sql_jinja_env_based_on_template_syntax,
|
|
40
|
+
)
|
|
41
|
+
from snowflake.cli.api.secure_path import UNLIMITED, SecurePath
|
|
42
|
+
from snowflake.connector import ProgrammingError
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def generic_sql_error_handler(
|
|
46
|
+
err: ProgrammingError, role: Optional[str] = None, warehouse: Optional[str] = None
|
|
47
|
+
) -> NoReturn:
|
|
48
|
+
# Potential refactor: If moving away from Python 3.8 and 3.9 to >= 3.10, use match ... case
|
|
49
|
+
if err.errno == DOES_NOT_EXIST_OR_CANNOT_BE_PERFORMED:
|
|
50
|
+
raise ProgrammingError(
|
|
51
|
+
msg=dedent(
|
|
52
|
+
f"""\
|
|
53
|
+
Received error message '{err.msg}' while executing SQL statement.
|
|
54
|
+
'{role}' may not have access to warehouse '{warehouse}'.
|
|
55
|
+
Please grant usage privilege on warehouse to this role.
|
|
56
|
+
"""
|
|
57
|
+
),
|
|
58
|
+
errno=err.errno,
|
|
59
|
+
)
|
|
60
|
+
elif err.errno == NO_WAREHOUSE_SELECTED_IN_SESSION:
|
|
61
|
+
raise ProgrammingError(
|
|
62
|
+
msg=dedent(
|
|
63
|
+
f"""\
|
|
64
|
+
Received error message '{err.msg}' while executing SQL statement.
|
|
65
|
+
Please provide a warehouse for the active session role in your project definition file, config.toml file, or via command line.
|
|
66
|
+
"""
|
|
67
|
+
),
|
|
68
|
+
errno=err.errno,
|
|
69
|
+
)
|
|
70
|
+
elif "does not exist or not authorized" in err.msg:
|
|
71
|
+
raise ProgrammingError(
|
|
72
|
+
msg=dedent(
|
|
73
|
+
f"""\
|
|
74
|
+
Received error message '{err.msg}' while executing SQL statement.
|
|
75
|
+
Please check the name of the resource you are trying to query or the permissions of the role you are using to run the query.
|
|
76
|
+
"""
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
raise err
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def ensure_correct_owner(row: dict, role: str, obj_name: str) -> None:
|
|
83
|
+
"""
|
|
84
|
+
Check if an object has the right owner role
|
|
85
|
+
"""
|
|
86
|
+
actual_owner = row[
|
|
87
|
+
OWNER_COL
|
|
88
|
+
].upper() # Because unquote_identifier() always returns uppercase str
|
|
89
|
+
if actual_owner != unquote_identifier(role):
|
|
90
|
+
raise UnexpectedOwnerError(obj_name, role, actual_owner)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _get_stage_paths_to_sync(
|
|
94
|
+
local_paths_to_sync: List[Path], deploy_root: Path
|
|
95
|
+
) -> List[StagePath]:
|
|
96
|
+
"""
|
|
97
|
+
Takes a list of paths (files and directories), returning a list of all files recursively relative to the deploy root.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
stage_paths = []
|
|
101
|
+
for path in local_paths_to_sync:
|
|
102
|
+
if path.is_dir():
|
|
103
|
+
for current_dir, _dirs, files in os.walk(path):
|
|
104
|
+
for file in files:
|
|
105
|
+
deploy_path = Path(current_dir, file).relative_to(deploy_root)
|
|
106
|
+
stage_paths.append(to_stage_path(deploy_path))
|
|
107
|
+
else:
|
|
108
|
+
stage_paths.append(to_stage_path(path.relative_to(deploy_root)))
|
|
109
|
+
return stage_paths
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def sync_deploy_root_with_stage(
|
|
113
|
+
console: AbstractConsole,
|
|
114
|
+
deploy_root: Path,
|
|
115
|
+
package_name: str,
|
|
116
|
+
stage_schema: str,
|
|
117
|
+
bundle_map: BundleMap,
|
|
118
|
+
role: str,
|
|
119
|
+
prune: bool,
|
|
120
|
+
recursive: bool,
|
|
121
|
+
stage_fqn: str,
|
|
122
|
+
local_paths_to_sync: List[Path] | None = None,
|
|
123
|
+
print_diff: bool = True,
|
|
124
|
+
) -> DiffResult:
|
|
125
|
+
"""
|
|
126
|
+
Ensures that the files on our remote stage match the artifacts we have in
|
|
127
|
+
the local filesystem.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
bundle_map (BundleMap): The artifact mapping computed by the `build_bundle` function.
|
|
131
|
+
role (str): The name of the role to use for queries and commands.
|
|
132
|
+
prune (bool): Whether to prune artifacts from the stage that don't exist locally.
|
|
133
|
+
recursive (bool): Whether to traverse directories recursively.
|
|
134
|
+
stage_fqn (str): The name of the stage to diff against and upload to.
|
|
135
|
+
local_paths_to_sync (List[Path], optional): List of local paths to sync. Defaults to None to sync all
|
|
136
|
+
local paths. Note that providing an empty list here is equivalent to None.
|
|
137
|
+
print_diff (bool): Whether to print the diff between the local files and the remote stage. Defaults to True
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
A `DiffResult` instance describing the changes that were performed.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
sql_executor = get_sql_executor()
|
|
144
|
+
# Does a stage already exist within the application package, or we need to create one?
|
|
145
|
+
# Using "if not exists" should take care of either case.
|
|
146
|
+
console.step(
|
|
147
|
+
f"Checking if stage {stage_fqn} exists, or creating a new one if none exists."
|
|
148
|
+
)
|
|
149
|
+
with sql_executor.use_role(role):
|
|
150
|
+
sql_executor.execute_query(
|
|
151
|
+
f"create schema if not exists {package_name}.{stage_schema}"
|
|
152
|
+
)
|
|
153
|
+
sql_executor.execute_query(
|
|
154
|
+
f"""
|
|
155
|
+
create stage if not exists {stage_fqn}
|
|
156
|
+
encryption = (TYPE = 'SNOWFLAKE_SSE')
|
|
157
|
+
DIRECTORY = (ENABLE = TRUE)"""
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# Perform a diff operation and display results to the user for informational purposes
|
|
161
|
+
if print_diff:
|
|
162
|
+
console.step(
|
|
163
|
+
"Performing a diff between the Snowflake stage and your local deploy_root ('%s') directory."
|
|
164
|
+
% deploy_root.resolve()
|
|
165
|
+
)
|
|
166
|
+
diff: DiffResult = compute_stage_diff(deploy_root, stage_fqn)
|
|
167
|
+
|
|
168
|
+
if local_paths_to_sync:
|
|
169
|
+
# Deploying specific files/directories
|
|
170
|
+
resolved_paths_to_sync = [
|
|
171
|
+
resolve_without_follow(p) for p in local_paths_to_sync
|
|
172
|
+
]
|
|
173
|
+
if not recursive:
|
|
174
|
+
verify_no_directories(resolved_paths_to_sync)
|
|
175
|
+
|
|
176
|
+
deploy_paths_to_sync = []
|
|
177
|
+
for resolved_path in resolved_paths_to_sync:
|
|
178
|
+
verify_exists(resolved_path)
|
|
179
|
+
deploy_paths = bundle_map.to_deploy_paths(resolved_path)
|
|
180
|
+
if not deploy_paths:
|
|
181
|
+
if resolved_path.is_dir() and recursive:
|
|
182
|
+
# No direct artifact mapping found for this path. Check to see
|
|
183
|
+
# if there are subpaths of this directory that are matches. We
|
|
184
|
+
# loop over sources because it's likely a much smaller list
|
|
185
|
+
# than the project directory.
|
|
186
|
+
for src in bundle_map.all_sources(absolute=True):
|
|
187
|
+
if resolved_path in src.parents:
|
|
188
|
+
# There is a source that contains this path, get its dest path(s)
|
|
189
|
+
deploy_paths.extend(bundle_map.to_deploy_paths(src))
|
|
190
|
+
|
|
191
|
+
if not deploy_paths:
|
|
192
|
+
raise ClickException(f"No artifact found for {resolved_path}")
|
|
193
|
+
deploy_paths_to_sync.extend(deploy_paths)
|
|
194
|
+
|
|
195
|
+
stage_paths_to_sync = _get_stage_paths_to_sync(
|
|
196
|
+
deploy_paths_to_sync, resolve_without_follow(deploy_root)
|
|
197
|
+
)
|
|
198
|
+
diff = preserve_from_diff(diff, stage_paths_to_sync)
|
|
199
|
+
else:
|
|
200
|
+
# Full deploy
|
|
201
|
+
if not recursive:
|
|
202
|
+
verify_no_directories(deploy_root.resolve().iterdir())
|
|
203
|
+
|
|
204
|
+
if not prune:
|
|
205
|
+
files_not_removed = [str(path) for path in diff.only_on_stage]
|
|
206
|
+
diff.only_on_stage = []
|
|
207
|
+
|
|
208
|
+
if len(files_not_removed) > 0:
|
|
209
|
+
files_not_removed_str = "\n".join(files_not_removed)
|
|
210
|
+
console.warning(
|
|
211
|
+
f"The following files exist only on the stage:\n{files_not_removed_str}\n\nUse the --prune flag to delete them from the stage."
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
if print_diff:
|
|
215
|
+
print_diff_to_console(diff, bundle_map)
|
|
216
|
+
|
|
217
|
+
# Upload diff-ed files to application package stage
|
|
218
|
+
if diff.has_changes():
|
|
219
|
+
console.step(
|
|
220
|
+
"Updating the Snowflake stage from your local %s directory."
|
|
221
|
+
% deploy_root.resolve(),
|
|
222
|
+
)
|
|
223
|
+
sync_local_diff_with_stage(
|
|
224
|
+
role=role,
|
|
225
|
+
deploy_root_path=deploy_root,
|
|
226
|
+
diff_result=diff,
|
|
227
|
+
stage_fqn=stage_fqn,
|
|
228
|
+
)
|
|
229
|
+
return diff
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _execute_sql_script(
|
|
233
|
+
script_content: str,
|
|
234
|
+
database_name: Optional[str] = None,
|
|
235
|
+
) -> None:
|
|
236
|
+
"""
|
|
237
|
+
Executing the provided SQL script content.
|
|
238
|
+
This assumes that a relevant warehouse is already active.
|
|
239
|
+
If database_name is passed in, it will be used first.
|
|
240
|
+
"""
|
|
241
|
+
try:
|
|
242
|
+
sql_executor = get_sql_executor()
|
|
243
|
+
if database_name is not None:
|
|
244
|
+
sql_executor.execute_query(f"use database {database_name}")
|
|
245
|
+
sql_executor.execute_queries(script_content)
|
|
246
|
+
except ProgrammingError as err:
|
|
247
|
+
generic_sql_error_handler(err)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def execute_post_deploy_hooks(
|
|
251
|
+
console: AbstractConsole,
|
|
252
|
+
project_root: Path,
|
|
253
|
+
post_deploy_hooks: Optional[List[PostDeployHook]],
|
|
254
|
+
deployed_object_type: str,
|
|
255
|
+
database_name: str,
|
|
256
|
+
) -> None:
|
|
257
|
+
"""
|
|
258
|
+
Executes post-deploy hooks for the given object type.
|
|
259
|
+
While executing SQL post deploy hooks, it first switches to the database provided in the input.
|
|
260
|
+
All post deploy scripts templates will first be expanded using the global template context.
|
|
261
|
+
"""
|
|
262
|
+
if not post_deploy_hooks:
|
|
263
|
+
return
|
|
264
|
+
|
|
265
|
+
with console.phase(f"Executing {deployed_object_type} post-deploy actions"):
|
|
266
|
+
sql_scripts_paths = []
|
|
267
|
+
for hook in post_deploy_hooks:
|
|
268
|
+
if hook.sql_script:
|
|
269
|
+
sql_scripts_paths.append(hook.sql_script)
|
|
270
|
+
else:
|
|
271
|
+
raise ValueError(
|
|
272
|
+
f"Unsupported {deployed_object_type} post-deploy hook type: {hook}"
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
scripts_content_list = render_script_templates(
|
|
276
|
+
project_root,
|
|
277
|
+
get_cli_context().template_context,
|
|
278
|
+
sql_scripts_paths,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
for index, sql_script_path in enumerate(sql_scripts_paths):
|
|
282
|
+
console.step(f"Executing SQL script: {sql_script_path}")
|
|
283
|
+
_execute_sql_script(
|
|
284
|
+
script_content=scripts_content_list[index],
|
|
285
|
+
database_name=database_name,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def render_script_templates(
|
|
290
|
+
project_root: Path,
|
|
291
|
+
jinja_context: dict[str, Any],
|
|
292
|
+
scripts: List[str],
|
|
293
|
+
override_env: Optional[jinja2.Environment] = None,
|
|
294
|
+
) -> List[str]:
|
|
295
|
+
"""
|
|
296
|
+
Input:
|
|
297
|
+
- project_root: path to project root
|
|
298
|
+
- jinja_context: a dictionary with the jinja context
|
|
299
|
+
- scripts: list of script paths relative to the project root
|
|
300
|
+
- override_env: optional jinja environment to use for rendering,
|
|
301
|
+
if not provided, the environment will be chosen based on the template syntax
|
|
302
|
+
Returns:
|
|
303
|
+
- List of rendered scripts content
|
|
304
|
+
Size of the return list is the same as the size of the input scripts list.
|
|
305
|
+
"""
|
|
306
|
+
scripts_contents = []
|
|
307
|
+
for relpath in scripts:
|
|
308
|
+
script_full_path = SecurePath(project_root) / relpath
|
|
309
|
+
try:
|
|
310
|
+
template_content = script_full_path.read_text(file_size_limit_mb=UNLIMITED)
|
|
311
|
+
env = override_env or choose_sql_jinja_env_based_on_template_syntax(
|
|
312
|
+
template_content, reference_name=relpath
|
|
313
|
+
)
|
|
314
|
+
result = env.from_string(template_content).render(jinja_context)
|
|
315
|
+
scripts_contents.append(result)
|
|
316
|
+
|
|
317
|
+
except FileNotFoundError as e:
|
|
318
|
+
raise MissingScriptError(relpath) from e
|
|
319
|
+
|
|
320
|
+
except jinja2.TemplateSyntaxError as e:
|
|
321
|
+
raise InvalidTemplateInFileError(relpath, e, e.lineno) from e
|
|
322
|
+
|
|
323
|
+
except jinja2.UndefinedError as e:
|
|
324
|
+
raise InvalidTemplateInFileError(relpath, e) from e
|
|
325
|
+
|
|
326
|
+
return scripts_contents
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def validation_item_to_str(item: dict[str, str | int]):
|
|
330
|
+
s = item["message"]
|
|
331
|
+
if item["errorCode"]:
|
|
332
|
+
s = f"{s} (error code {item['errorCode']})"
|
|
333
|
+
return s
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def drop_generic_object(
|
|
337
|
+
console: AbstractConsole,
|
|
338
|
+
object_type: str,
|
|
339
|
+
object_name: str,
|
|
340
|
+
role: str,
|
|
341
|
+
cascade: bool = False,
|
|
342
|
+
):
|
|
343
|
+
"""
|
|
344
|
+
Drop object using the given role.
|
|
345
|
+
"""
|
|
346
|
+
sql_executor = get_sql_executor()
|
|
347
|
+
with sql_executor.use_role(role):
|
|
348
|
+
console.step(f"Dropping {object_type} {object_name} now.")
|
|
349
|
+
drop_query = f"drop {object_type} {object_name}"
|
|
350
|
+
if cascade:
|
|
351
|
+
drop_query += " cascade"
|
|
352
|
+
try:
|
|
353
|
+
sql_executor.execute_query(drop_query)
|
|
354
|
+
except:
|
|
355
|
+
raise SnowflakeSQLExecutionError(drop_query)
|
|
356
|
+
|
|
357
|
+
console.message(f"Dropped {object_type} {object_name} successfully.")
|
snowflake/cli/api/exceptions.py
CHANGED
|
@@ -17,8 +17,9 @@ from __future__ import annotations
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Optional
|
|
19
19
|
|
|
20
|
-
from click.exceptions import ClickException
|
|
20
|
+
from click.exceptions import ClickException, UsageError
|
|
21
21
|
from snowflake.cli.api.constants import ObjectType
|
|
22
|
+
from snowflake.connector.compat import IS_WINDOWS
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
class EnvironmentVariableNotFoundError(ClickException):
|
|
@@ -101,9 +102,16 @@ class ObjectAlreadyExistsError(ClickException):
|
|
|
101
102
|
|
|
102
103
|
|
|
103
104
|
class NoProjectDefinitionError(ClickException):
|
|
104
|
-
def __init__(self, project_type: str,
|
|
105
|
+
def __init__(self, project_type: str, project_root: str | Path):
|
|
105
106
|
super().__init__(
|
|
106
|
-
f"No {project_type} project definition found in {
|
|
107
|
+
f"No {project_type} project definition found in {project_root}"
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class InvalidProjectDefinitionVersionError(ClickException):
|
|
112
|
+
def __init__(self, expected_version: str, actual_version: str):
|
|
113
|
+
super().__init__(
|
|
114
|
+
f"This command only supports definition version {expected_version}, got {actual_version}."
|
|
107
115
|
)
|
|
108
116
|
|
|
109
117
|
|
|
@@ -133,9 +141,18 @@ class DirectoryIsNotEmptyError(ClickException):
|
|
|
133
141
|
|
|
134
142
|
class ConfigFileTooWidePermissionsError(ClickException):
|
|
135
143
|
def __init__(self, path: Path):
|
|
136
|
-
|
|
137
|
-
f'
|
|
144
|
+
change_permissons_command = (
|
|
145
|
+
f'icacls "{path}" /deny <USER_ID>:F'
|
|
146
|
+
if IS_WINDOWS
|
|
147
|
+
else f'chmod 0600 "{path}"'
|
|
138
148
|
)
|
|
149
|
+
msg = f"Configuration file {path} has too wide permissions, run `{change_permissons_command}`."
|
|
150
|
+
if IS_WINDOWS:
|
|
151
|
+
msg += (
|
|
152
|
+
f'\nTo check which users have access to the file run `icacls "{path}"`.'
|
|
153
|
+
"Run the above command for all users except you and administrators."
|
|
154
|
+
)
|
|
155
|
+
super().__init__(msg)
|
|
139
156
|
|
|
140
157
|
|
|
141
158
|
class DatabaseNotProvidedError(ClickException):
|
|
@@ -162,3 +179,12 @@ class FQNInconsistencyError(ClickException):
|
|
|
162
179
|
super().__init__(
|
|
163
180
|
f"{part.capitalize()} provided but name '{name}' is fully qualified name."
|
|
164
181
|
)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class IncompatibleParametersError(UsageError):
|
|
185
|
+
def __init__(self, options: list[str]):
|
|
186
|
+
options_with_quotes = [f"'{option}'" for option in options]
|
|
187
|
+
comma_separated_options = ", ".join(options_with_quotes[:-1])
|
|
188
|
+
super().__init__(
|
|
189
|
+
f"Parameters {comma_separated_options} and {options_with_quotes[-1]} are incompatible and cannot be used simultaneously."
|
|
190
|
+
)
|
snowflake/cli/api/identifiers.py
CHANGED
|
@@ -17,9 +17,11 @@ from __future__ import annotations
|
|
|
17
17
|
import re
|
|
18
18
|
|
|
19
19
|
from click import ClickException
|
|
20
|
-
from snowflake.cli.api.cli_global_context import cli_context
|
|
21
20
|
from snowflake.cli.api.exceptions import FQNInconsistencyError, FQNNameError
|
|
22
|
-
from snowflake.cli.api.project.schemas.identifier_model import
|
|
21
|
+
from snowflake.cli.api.project.schemas.identifier_model import (
|
|
22
|
+
Identifier,
|
|
23
|
+
ObjectIdentifierBaseModel,
|
|
24
|
+
)
|
|
23
25
|
from snowflake.cli.api.project.util import VALID_IDENTIFIER_REGEX, identifier_for_url
|
|
24
26
|
|
|
25
27
|
|
|
@@ -35,10 +37,17 @@ class FQN:
|
|
|
35
37
|
fqn = FQN.from_string("my_name").set_database("db").set_schema("foo")
|
|
36
38
|
"""
|
|
37
39
|
|
|
38
|
-
def __init__(
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
database: str | None,
|
|
43
|
+
schema: str | None,
|
|
44
|
+
name: str,
|
|
45
|
+
signature: str | None = None,
|
|
46
|
+
):
|
|
39
47
|
self._database = database
|
|
40
48
|
self._schema = schema
|
|
41
49
|
self._name = name
|
|
50
|
+
self.signature = signature
|
|
42
51
|
|
|
43
52
|
@property
|
|
44
53
|
def database(self) -> str | None:
|
|
@@ -72,6 +81,8 @@ class FQN:
|
|
|
72
81
|
|
|
73
82
|
@property
|
|
74
83
|
def sql_identifier(self) -> str:
|
|
84
|
+
if self.signature:
|
|
85
|
+
return f"IDENTIFIER('{self.identifier}'){self.signature}"
|
|
75
86
|
return f"IDENTIFIER('{self.identifier}')"
|
|
76
87
|
|
|
77
88
|
def __str__(self):
|
|
@@ -98,9 +109,13 @@ class FQN:
|
|
|
98
109
|
else:
|
|
99
110
|
database = None
|
|
100
111
|
schema = result.group("first_qualifier")
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
|
|
113
|
+
signature = None
|
|
114
|
+
if result.group("signature"):
|
|
115
|
+
signature = result.group("signature")
|
|
116
|
+
return cls(
|
|
117
|
+
name=unqualified_name, schema=schema, database=database, signature=signature
|
|
118
|
+
)
|
|
104
119
|
|
|
105
120
|
@classmethod
|
|
106
121
|
def from_stage(cls, stage: str) -> "FQN":
|
|
@@ -110,11 +125,11 @@ class FQN:
|
|
|
110
125
|
return cls.from_string(name)
|
|
111
126
|
|
|
112
127
|
@classmethod
|
|
113
|
-
def
|
|
128
|
+
def from_identifier_model_v1(cls, model: ObjectIdentifierBaseModel) -> "FQN":
|
|
114
129
|
"""Create an instance from object model."""
|
|
115
130
|
if not isinstance(model, ObjectIdentifierBaseModel):
|
|
116
131
|
raise ClickException(
|
|
117
|
-
f"Expected {type(ObjectIdentifierBaseModel)}, got {model}."
|
|
132
|
+
f"Expected {type(ObjectIdentifierBaseModel).__name__}, got {model}."
|
|
118
133
|
)
|
|
119
134
|
|
|
120
135
|
fqn = cls.from_string(model.name)
|
|
@@ -126,6 +141,21 @@ class FQN:
|
|
|
126
141
|
|
|
127
142
|
return fqn.set_database(model.database).set_schema(model.schema_name)
|
|
128
143
|
|
|
144
|
+
@classmethod
|
|
145
|
+
def from_identifier_model_v2(cls, model: Identifier) -> "FQN":
|
|
146
|
+
"""Create an instance from object model."""
|
|
147
|
+
if not isinstance(model, Identifier):
|
|
148
|
+
raise ClickException(f"Expected {type(Identifier).__name__}, got {model}.")
|
|
149
|
+
|
|
150
|
+
fqn = cls.from_string(model.name)
|
|
151
|
+
|
|
152
|
+
if fqn.database and model.database:
|
|
153
|
+
raise FQNInconsistencyError("database", model.name)
|
|
154
|
+
if fqn.schema and model.schema_:
|
|
155
|
+
raise FQNInconsistencyError("schema", model.name)
|
|
156
|
+
|
|
157
|
+
return fqn.set_database(model.database).set_schema(model.schema_)
|
|
158
|
+
|
|
129
159
|
def set_database(self, database: str | None) -> "FQN":
|
|
130
160
|
if database:
|
|
131
161
|
self._database = database
|
|
@@ -151,4 +181,6 @@ class FQN:
|
|
|
151
181
|
|
|
152
182
|
def using_context(self) -> "FQN":
|
|
153
183
|
"""Update the instance with database and schema from connection in current cli context."""
|
|
154
|
-
|
|
184
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
185
|
+
|
|
186
|
+
return self.using_connection(get_cli_context().connection)
|
|
@@ -18,7 +18,8 @@ from pathlib import Path
|
|
|
18
18
|
from typing import List, Optional
|
|
19
19
|
|
|
20
20
|
import yaml
|
|
21
|
-
from
|
|
21
|
+
from click import ClickException
|
|
22
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
22
23
|
from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
|
|
23
24
|
from snowflake.cli.api.project.schemas.project_definition import (
|
|
24
25
|
ProjectProperties,
|
|
@@ -30,7 +31,10 @@ from snowflake.cli.api.project.util import (
|
|
|
30
31
|
to_identifier,
|
|
31
32
|
)
|
|
32
33
|
from snowflake.cli.api.secure_path import SecurePath
|
|
33
|
-
from snowflake.cli.api.utils.definition_rendering import
|
|
34
|
+
from snowflake.cli.api.utils.definition_rendering import (
|
|
35
|
+
raw_project_properties,
|
|
36
|
+
render_definition_template,
|
|
37
|
+
)
|
|
34
38
|
from snowflake.cli.api.utils.dict_utils import deep_merge_dicts
|
|
35
39
|
from snowflake.cli.api.utils.types import Context, Definition
|
|
36
40
|
|
|
@@ -42,8 +46,13 @@ def _get_merged_definitions(paths: List[Path]) -> Optional[Definition]:
|
|
|
42
46
|
if len(spaths) == 0:
|
|
43
47
|
return None
|
|
44
48
|
|
|
49
|
+
loader = yaml.BaseLoader
|
|
50
|
+
loader.add_constructor(
|
|
51
|
+
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _no_duplicates_constructor
|
|
52
|
+
)
|
|
53
|
+
|
|
45
54
|
with spaths[0].open("r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB) as base_yml:
|
|
46
|
-
definition = yaml.load(base_yml.read(), Loader=
|
|
55
|
+
definition = yaml.load(base_yml.read(), Loader=loader) or {}
|
|
47
56
|
|
|
48
57
|
for override_path in spaths[1:]:
|
|
49
58
|
with override_path.open(
|
|
@@ -58,7 +67,9 @@ def _get_merged_definitions(paths: List[Path]) -> Optional[Definition]:
|
|
|
58
67
|
|
|
59
68
|
|
|
60
69
|
def load_project(
|
|
61
|
-
paths: List[Path],
|
|
70
|
+
paths: List[Path],
|
|
71
|
+
context_overrides: Optional[Context] = None,
|
|
72
|
+
render_templates: bool = True,
|
|
62
73
|
) -> ProjectProperties:
|
|
63
74
|
"""
|
|
64
75
|
Loads project definition, optionally overriding values. Definition values
|
|
@@ -66,7 +77,10 @@ def load_project(
|
|
|
66
77
|
Templating is also applied after the merging process.
|
|
67
78
|
"""
|
|
68
79
|
merged_definitions = _get_merged_definitions(paths)
|
|
69
|
-
|
|
80
|
+
if render_templates:
|
|
81
|
+
return render_definition_template(merged_definitions, context_overrides or {})
|
|
82
|
+
else:
|
|
83
|
+
return raw_project_properties(merged_definitions)
|
|
70
84
|
|
|
71
85
|
|
|
72
86
|
def default_app_package(project_name: str):
|
|
@@ -75,10 +89,27 @@ def default_app_package(project_name: str):
|
|
|
75
89
|
|
|
76
90
|
|
|
77
91
|
def default_role():
|
|
78
|
-
conn =
|
|
92
|
+
conn = get_cli_context().connection
|
|
79
93
|
return conn.role
|
|
80
94
|
|
|
81
95
|
|
|
82
96
|
def default_application(project_name: str):
|
|
83
97
|
user = sanitize_identifier(get_env_username() or DEFAULT_USERNAME).lower()
|
|
84
98
|
return append_to_identifier(to_identifier(project_name), f"_{user}")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _no_duplicates_constructor(loader, node, deep=False):
|
|
102
|
+
"""
|
|
103
|
+
Raises error it there are duplicated keys on the same level in the yaml file
|
|
104
|
+
"""
|
|
105
|
+
mapping = {}
|
|
106
|
+
|
|
107
|
+
for key_node, value_node in node.value:
|
|
108
|
+
key = loader.construct_object(key_node, deep=deep)
|
|
109
|
+
value = loader.construct_object(value_node, deep=deep)
|
|
110
|
+
if key in mapping.keys():
|
|
111
|
+
raise ClickException(
|
|
112
|
+
f"While loading the project definition file, duplicate key was found: {key}"
|
|
113
|
+
)
|
|
114
|
+
mapping[key] = value
|
|
115
|
+
return loader.construct_mapping(node, deep)
|