snowflake-cli-labs 3.0.0rc5__py3-none-any.whl → 3.0.2__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.
- README.md +21 -0
- {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/METADATA +6 -96
- snowflake_cli_labs-3.0.2.dist-info/RECORD +5 -0
- snowflake/cli/__about__.py +0 -17
- snowflake/cli/__init__.py +0 -13
- snowflake/cli/_app/__init__.py +0 -22
- snowflake/cli/_app/__main__.py +0 -31
- snowflake/cli/_app/api_impl/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
- snowflake/cli/_app/cli_app.py +0 -252
- snowflake/cli/_app/commands_registration/__init__.py +0 -33
- snowflake/cli/_app/commands_registration/builtin_plugins.py +0 -50
- snowflake/cli/_app/commands_registration/command_plugins_loader.py +0 -169
- snowflake/cli/_app/commands_registration/commands_registration_with_callbacks.py +0 -105
- snowflake/cli/_app/commands_registration/exception_logging.py +0 -26
- snowflake/cli/_app/commands_registration/threadsafe.py +0 -48
- snowflake/cli/_app/commands_registration/typer_registration.py +0 -153
- snowflake/cli/_app/constants.py +0 -19
- snowflake/cli/_app/dev/__init__.py +0 -13
- snowflake/cli/_app/dev/commands_structure.py +0 -48
- snowflake/cli/_app/dev/docs/__init__.py +0 -13
- snowflake/cli/_app/dev/docs/commands_docs_generator.py +0 -118
- snowflake/cli/_app/dev/docs/generator.py +0 -35
- snowflake/cli/_app/dev/docs/project_definition_docs_generator.py +0 -58
- snowflake/cli/_app/dev/docs/project_definition_generate_json_schema.py +0 -227
- snowflake/cli/_app/dev/docs/template_utils.py +0 -23
- snowflake/cli/_app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
- snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +0 -9
- snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +0 -67
- snowflake/cli/_app/dev/pycharm_remote_debug.py +0 -46
- snowflake/cli/_app/loggers.py +0 -199
- snowflake/cli/_app/main_typer.py +0 -62
- snowflake/cli/_app/printing.py +0 -181
- snowflake/cli/_app/secret.py +0 -9
- snowflake/cli/_app/snow_connector.py +0 -309
- snowflake/cli/_app/telemetry.py +0 -220
- snowflake/cli/_app/version_check.py +0 -74
- snowflake/cli/_plugins/__init__.py +0 -13
- snowflake/cli/_plugins/connection/__init__.py +0 -13
- snowflake/cli/_plugins/connection/commands.py +0 -353
- snowflake/cli/_plugins/connection/plugin_spec.py +0 -30
- snowflake/cli/_plugins/connection/util.py +0 -195
- snowflake/cli/_plugins/cortex/__init__.py +0 -13
- snowflake/cli/_plugins/cortex/commands.py +0 -332
- snowflake/cli/_plugins/cortex/constants.py +0 -17
- snowflake/cli/_plugins/cortex/manager.py +0 -189
- snowflake/cli/_plugins/cortex/plugin_spec.py +0 -30
- snowflake/cli/_plugins/cortex/types.py +0 -22
- snowflake/cli/_plugins/git/__init__.py +0 -13
- snowflake/cli/_plugins/git/commands.py +0 -358
- snowflake/cli/_plugins/git/manager.py +0 -151
- snowflake/cli/_plugins/git/plugin_spec.py +0 -30
- snowflake/cli/_plugins/helpers/__init__.py +0 -13
- snowflake/cli/_plugins/helpers/commands.py +0 -90
- snowflake/cli/_plugins/helpers/plugin_spec.py +0 -30
- snowflake/cli/_plugins/init/__init__.py +0 -13
- snowflake/cli/_plugins/init/commands.py +0 -248
- snowflake/cli/_plugins/init/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/artifacts.py +0 -757
- snowflake/cli/_plugins/nativeapp/bundle_context.py +0 -31
- snowflake/cli/_plugins/nativeapp/codegen/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +0 -91
- snowflake/cli/_plugins/nativeapp/codegen/compiler.py +0 -149
- snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +0 -306
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -249
- snowflake/cli/_plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -59
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +0 -61
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +0 -523
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +0 -114
- snowflake/cli/_plugins/nativeapp/commands.py +0 -559
- snowflake/cli/_plugins/nativeapp/common_flags.py +0 -44
- snowflake/cli/_plugins/nativeapp/constants.py +0 -27
- snowflake/cli/_plugins/nativeapp/entities/__init__.py +0 -0
- snowflake/cli/_plugins/nativeapp/entities/application.py +0 -878
- snowflake/cli/_plugins/nativeapp/entities/application_package.py +0 -1392
- snowflake/cli/_plugins/nativeapp/exceptions.py +0 -113
- snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -24
- snowflake/cli/_plugins/nativeapp/manager.py +0 -415
- snowflake/cli/_plugins/nativeapp/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/policy.py +0 -53
- snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
- snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
- snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -70
- snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
- snowflake/cli/_plugins/nativeapp/utils.py +0 -98
- snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -262
- snowflake/cli/_plugins/nativeapp/version/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/version/commands.py +0 -141
- snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -98
- snowflake/cli/_plugins/notebook/__init__.py +0 -13
- snowflake/cli/_plugins/notebook/commands.py +0 -86
- snowflake/cli/_plugins/notebook/exceptions.py +0 -20
- snowflake/cli/_plugins/notebook/manager.py +0 -71
- snowflake/cli/_plugins/notebook/plugin_spec.py +0 -30
- snowflake/cli/_plugins/notebook/types.py +0 -15
- snowflake/cli/_plugins/object/__init__.py +0 -13
- snowflake/cli/_plugins/object/command_aliases.py +0 -95
- snowflake/cli/_plugins/object/commands.py +0 -180
- snowflake/cli/_plugins/object/common.py +0 -85
- snowflake/cli/_plugins/object/manager.py +0 -118
- snowflake/cli/_plugins/object/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/commands.py +0 -450
- snowflake/cli/_plugins/snowpark/common.py +0 -268
- snowflake/cli/_plugins/snowpark/models.py +0 -150
- snowflake/cli/_plugins/snowpark/package/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +0 -199
- snowflake/cli/_plugins/snowpark/package/commands.py +0 -195
- snowflake/cli/_plugins/snowpark/package/manager.py +0 -44
- snowflake/cli/_plugins/snowpark/package/utils.py +0 -26
- snowflake/cli/_plugins/snowpark/package_utils.py +0 -354
- snowflake/cli/_plugins/snowpark/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/snowpark_entity.py +0 -29
- snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +0 -173
- snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +0 -109
- snowflake/cli/_plugins/snowpark/snowpark_shared.py +0 -59
- snowflake/cli/_plugins/snowpark/zipper.py +0 -89
- snowflake/cli/_plugins/spcs/__init__.py +0 -33
- snowflake/cli/_plugins/spcs/common.py +0 -99
- snowflake/cli/_plugins/spcs/compute_pool/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/compute_pool/commands.py +0 -241
- snowflake/cli/_plugins/spcs/compute_pool/manager.py +0 -121
- snowflake/cli/_plugins/spcs/image_registry/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_registry/commands.py +0 -65
- snowflake/cli/_plugins/spcs/image_registry/manager.py +0 -105
- snowflake/cli/_plugins/spcs/image_repository/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_repository/commands.py +0 -202
- snowflake/cli/_plugins/spcs/image_repository/manager.py +0 -84
- snowflake/cli/_plugins/spcs/plugin_spec.py +0 -30
- snowflake/cli/_plugins/spcs/services/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/services/commands.py +0 -345
- snowflake/cli/_plugins/spcs/services/manager.py +0 -208
- snowflake/cli/_plugins/sql/__init__.py +0 -13
- snowflake/cli/_plugins/sql/commands.py +0 -86
- snowflake/cli/_plugins/sql/manager.py +0 -92
- snowflake/cli/_plugins/sql/plugin_spec.py +0 -30
- snowflake/cli/_plugins/sql/snowsql_templating.py +0 -28
- snowflake/cli/_plugins/stage/__init__.py +0 -13
- snowflake/cli/_plugins/stage/commands.py +0 -264
- snowflake/cli/_plugins/stage/diff.py +0 -280
- snowflake/cli/_plugins/stage/manager.py +0 -582
- snowflake/cli/_plugins/stage/md5.py +0 -160
- snowflake/cli/_plugins/stage/plugin_spec.py +0 -30
- snowflake/cli/_plugins/stage/utils.py +0 -54
- snowflake/cli/_plugins/streamlit/__init__.py +0 -13
- snowflake/cli/_plugins/streamlit/commands.py +0 -195
- snowflake/cli/_plugins/streamlit/manager.py +0 -220
- snowflake/cli/_plugins/streamlit/plugin_spec.py +0 -30
- snowflake/cli/_plugins/streamlit/streamlit_entity.py +0 -12
- snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +0 -66
- snowflake/cli/_plugins/workspace/__init__.py +0 -13
- snowflake/cli/_plugins/workspace/action_context.py +0 -18
- snowflake/cli/_plugins/workspace/commands.py +0 -306
- snowflake/cli/_plugins/workspace/manager.py +0 -74
- snowflake/cli/_plugins/workspace/plugin_spec.py +0 -30
- snowflake/cli/api/__init__.py +0 -48
- snowflake/cli/api/cli_global_context.py +0 -247
- snowflake/cli/api/commands/__init__.py +0 -13
- snowflake/cli/api/commands/alias.py +0 -23
- snowflake/cli/api/commands/common.py +0 -25
- snowflake/cli/api/commands/decorators.py +0 -369
- snowflake/cli/api/commands/execution_metadata.py +0 -40
- snowflake/cli/api/commands/experimental_behaviour.py +0 -18
- snowflake/cli/api/commands/flags.py +0 -561
- snowflake/cli/api/commands/overrideable_parameter.py +0 -143
- snowflake/cli/api/commands/snow_typer.py +0 -247
- snowflake/cli/api/commands/utils.py +0 -18
- snowflake/cli/api/config.py +0 -380
- snowflake/cli/api/connections.py +0 -216
- snowflake/cli/api/console/__init__.py +0 -17
- snowflake/cli/api/console/abc.py +0 -94
- snowflake/cli/api/console/console.py +0 -134
- snowflake/cli/api/console/enum.py +0 -17
- snowflake/cli/api/constants.py +0 -90
- snowflake/cli/api/entities/common.py +0 -56
- snowflake/cli/api/entities/utils.py +0 -370
- snowflake/cli/api/errno.py +0 -28
- snowflake/cli/api/exceptions.py +0 -190
- snowflake/cli/api/feature_flags.py +0 -54
- snowflake/cli/api/identifiers.py +0 -190
- snowflake/cli/api/metrics.py +0 -92
- snowflake/cli/api/output/__init__.py +0 -13
- snowflake/cli/api/output/formats.py +0 -20
- snowflake/cli/api/output/types.py +0 -118
- snowflake/cli/api/plugins/__init__.py +0 -13
- snowflake/cli/api/plugins/command/__init__.py +0 -72
- snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
- snowflake/cli/api/plugins/plugin_config.py +0 -32
- snowflake/cli/api/project/__init__.py +0 -13
- snowflake/cli/api/project/definition.py +0 -126
- snowflake/cli/api/project/definition_conversion.py +0 -400
- snowflake/cli/api/project/definition_manager.py +0 -145
- snowflake/cli/api/project/errors.py +0 -56
- snowflake/cli/api/project/project_verification.py +0 -23
- snowflake/cli/api/project/schemas/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/common.py +0 -153
- snowflake/cli/api/project/schemas/entities/entities.py +0 -61
- snowflake/cli/api/project/schemas/project_definition.py +0 -330
- snowflake/cli/api/project/schemas/template.py +0 -77
- snowflake/cli/api/project/schemas/updatable_model.py +0 -202
- snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/identifier_model.py +0 -51
- snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/native_app/application.py +0 -61
- snowflake/cli/api/project/schemas/v1/native_app/native_app.py +0 -93
- snowflake/cli/api/project/schemas/v1/native_app/package.py +0 -84
- snowflake/cli/api/project/schemas/v1/native_app/path_mapping.py +0 -65
- snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/snowpark/argument.py +0 -28
- snowflake/cli/api/project/schemas/v1/snowpark/callable.py +0 -69
- snowflake/cli/api/project/schemas/v1/snowpark/snowpark.py +0 -36
- snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +0 -47
- snowflake/cli/api/project/util.py +0 -278
- snowflake/cli/api/rendering/__init__.py +0 -13
- snowflake/cli/api/rendering/jinja.py +0 -118
- snowflake/cli/api/rendering/project_definition_templates.py +0 -43
- snowflake/cli/api/rendering/project_templates.py +0 -98
- snowflake/cli/api/rendering/sql_templates.py +0 -105
- snowflake/cli/api/rest_api.py +0 -178
- snowflake/cli/api/sanitizers.py +0 -43
- snowflake/cli/api/secure_path.py +0 -360
- snowflake/cli/api/secure_utils.py +0 -118
- snowflake/cli/api/sql_execution.py +0 -280
- snowflake/cli/api/utils/__init__.py +0 -13
- snowflake/cli/api/utils/cursor.py +0 -34
- snowflake/cli/api/utils/definition_rendering.py +0 -415
- snowflake/cli/api/utils/dict_utils.py +0 -73
- snowflake/cli/api/utils/error_handling.py +0 -23
- snowflake/cli/api/utils/graph.py +0 -97
- snowflake/cli/api/utils/models.py +0 -63
- snowflake/cli/api/utils/naming_utils.py +0 -13
- snowflake/cli/api/utils/path_utils.py +0 -36
- snowflake/cli/api/utils/templating_functions.py +0 -144
- snowflake/cli/api/utils/types.py +0 -35
- snowflake_cli_labs-3.0.0rc5.dist-info/RECORD +0 -242
- snowflake_cli_labs-3.0.0rc5.dist-info/entry_points.txt +0 -2
- {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/licenses/LICENSE +0 -0
snowflake/cli/_app/loggers.py
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import logging
|
|
18
|
-
import logging.config
|
|
19
|
-
from dataclasses import asdict, dataclass, field
|
|
20
|
-
from typing import Any, Dict, List
|
|
21
|
-
|
|
22
|
-
import typer
|
|
23
|
-
from snowflake.cli.api.exceptions import InvalidLogsConfiguration
|
|
24
|
-
from snowflake.cli.api.secure_path import SecurePath
|
|
25
|
-
from snowflake.connector.errors import ConfigSourceError
|
|
26
|
-
|
|
27
|
-
_DEFAULT_LOG_FILENAME = "snowflake-cli.log"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@dataclass
|
|
31
|
-
class LogFormatterConfig:
|
|
32
|
-
_format: str
|
|
33
|
-
_class: str = "logging.Formatter"
|
|
34
|
-
datefmt: str = "%Y-%m-%d %H:%M:%S"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@dataclass
|
|
38
|
-
class LoggerConfig:
|
|
39
|
-
level: int = logging.NOTSET
|
|
40
|
-
handlers: List[str] = field(default_factory=list)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
@dataclass
|
|
44
|
-
class DefaultLoggingConfig:
|
|
45
|
-
version: int = 1
|
|
46
|
-
disable_existing_loggers: bool = True
|
|
47
|
-
formatters: Dict[str, LogFormatterConfig] = field(
|
|
48
|
-
default_factory=lambda: {
|
|
49
|
-
"default_formatter": LogFormatterConfig(
|
|
50
|
-
_format="%(asctime)s %(levelname)s %(message)s"
|
|
51
|
-
),
|
|
52
|
-
"detailed_formatter": LogFormatterConfig(
|
|
53
|
-
_format="%(asctime)s %(levelname)s [%(name)s] %(message)s"
|
|
54
|
-
),
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
filters: Dict[str, Any] = field(default_factory=dict)
|
|
58
|
-
handlers: Dict[str, Any] = field(
|
|
59
|
-
default_factory=lambda: {
|
|
60
|
-
"console": {
|
|
61
|
-
"class": "logging.StreamHandler",
|
|
62
|
-
"formatter": "default_formatter",
|
|
63
|
-
"level": logging.ERROR,
|
|
64
|
-
},
|
|
65
|
-
"file": {
|
|
66
|
-
"class": "logging.handlers.TimedRotatingFileHandler",
|
|
67
|
-
"filename": None,
|
|
68
|
-
"when": "midnight",
|
|
69
|
-
"formatter": "detailed_formatter",
|
|
70
|
-
"level": logging.INFO,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
)
|
|
74
|
-
loggers: Dict[str, Any] = field(
|
|
75
|
-
default_factory=lambda: {
|
|
76
|
-
"snowflake.cli": LoggerConfig(handlers=["console", "file"]),
|
|
77
|
-
"snowflake": LoggerConfig(),
|
|
78
|
-
"snowflake.connector.telemetry": LoggerConfig(level=logging.CRITICAL),
|
|
79
|
-
}
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
@dataclass
|
|
84
|
-
class InitialLoggingConfig(DefaultLoggingConfig):
|
|
85
|
-
loggers: Dict[str, Any] = field(
|
|
86
|
-
default_factory=lambda: {
|
|
87
|
-
"snowflake.cli": LoggerConfig(level=logging.INFO, handlers=["file"]),
|
|
88
|
-
"snowflake": LoggerConfig(),
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def _remove_underscore_prefixes_from_keys(d: Dict[str, Any]) -> None:
|
|
94
|
-
for k, v in list(d.items()):
|
|
95
|
-
if k.startswith("_"):
|
|
96
|
-
d[k[1:]] = d.pop(k)
|
|
97
|
-
if isinstance(v, dict):
|
|
98
|
-
_remove_underscore_prefixes_from_keys(v)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
class FileLogsConfig:
|
|
102
|
-
def __init__(self, debug: bool) -> None:
|
|
103
|
-
from snowflake.cli.api.config import (
|
|
104
|
-
get_logs_config,
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
config = get_logs_config()
|
|
108
|
-
|
|
109
|
-
self.path: SecurePath = SecurePath(config["path"])
|
|
110
|
-
self.save_logs: bool = config["save_logs"]
|
|
111
|
-
self.level: int = logging.getLevelName(config["level"].upper())
|
|
112
|
-
if debug:
|
|
113
|
-
self.level = logging.DEBUG
|
|
114
|
-
|
|
115
|
-
self._check_log_level(config)
|
|
116
|
-
if self.save_logs:
|
|
117
|
-
self._create_logs_directory_if_not_exists()
|
|
118
|
-
|
|
119
|
-
def _create_logs_directory_if_not_exists(self):
|
|
120
|
-
if not self.path.exists():
|
|
121
|
-
self.path.mkdir(parents=True)
|
|
122
|
-
|
|
123
|
-
def _check_log_level(self, config):
|
|
124
|
-
possible_log_levels = [
|
|
125
|
-
logging.DEBUG,
|
|
126
|
-
logging.INFO,
|
|
127
|
-
logging.WARN,
|
|
128
|
-
logging.ERROR,
|
|
129
|
-
logging.CRITICAL,
|
|
130
|
-
]
|
|
131
|
-
if self.level not in possible_log_levels:
|
|
132
|
-
raise InvalidLogsConfiguration(
|
|
133
|
-
f"Invalid 'level' value set in [logs] section: {config['level']}. "
|
|
134
|
-
f"'level' should be one of: {' / '.join(logging.getLevelName(lvl) for lvl in possible_log_levels)}"
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
@property
|
|
138
|
-
def filename(self):
|
|
139
|
-
return self.path.path / _DEFAULT_LOG_FILENAME
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def create_initial_loggers():
|
|
143
|
-
config = InitialLoggingConfig()
|
|
144
|
-
try:
|
|
145
|
-
file_logs_config = FileLogsConfig(debug=False)
|
|
146
|
-
if file_logs_config.save_logs:
|
|
147
|
-
config.handlers["file"]["filename"] = file_logs_config.filename
|
|
148
|
-
_configurate_logging(config)
|
|
149
|
-
except ConfigSourceError:
|
|
150
|
-
pass
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def create_loggers(verbose: bool, debug: bool):
|
|
154
|
-
"""Creates a logger depending on the SnowCLI parameters and config file.
|
|
155
|
-
verbose == True - print info and higher logs in default format
|
|
156
|
-
debug == True - print debug and higher logs in debug format
|
|
157
|
-
none of above - print only error logs in default format
|
|
158
|
-
"""
|
|
159
|
-
config = DefaultLoggingConfig()
|
|
160
|
-
|
|
161
|
-
if verbose and debug:
|
|
162
|
-
raise typer.BadParameter("Only one parameter `verbose` or `debug` is possible")
|
|
163
|
-
elif debug:
|
|
164
|
-
config.handlers["console"].update(
|
|
165
|
-
level=logging.DEBUG,
|
|
166
|
-
formatter="detailed_formatter",
|
|
167
|
-
)
|
|
168
|
-
# In debug mode we also want to get snowflake connector logs
|
|
169
|
-
config.loggers["snowflake"].handlers = ["file", "console"]
|
|
170
|
-
elif verbose:
|
|
171
|
-
config.handlers["console"].update(level=logging.INFO)
|
|
172
|
-
|
|
173
|
-
global_log_level = config.handlers["console"]["level"]
|
|
174
|
-
|
|
175
|
-
file_logs_config = FileLogsConfig(debug=debug)
|
|
176
|
-
if file_logs_config.save_logs:
|
|
177
|
-
config.handlers["file"].update(
|
|
178
|
-
level=file_logs_config.level,
|
|
179
|
-
filename=file_logs_config.filename,
|
|
180
|
-
)
|
|
181
|
-
if file_logs_config.level < global_log_level:
|
|
182
|
-
global_log_level = file_logs_config.level
|
|
183
|
-
else:
|
|
184
|
-
# We need to remove handler definition - otherwise it creates file even if `save_logs` is False
|
|
185
|
-
del config.handlers["file"]
|
|
186
|
-
for logger in config.loggers.values():
|
|
187
|
-
if "file" in logger.handlers:
|
|
188
|
-
logger.handlers.remove("file")
|
|
189
|
-
|
|
190
|
-
config.loggers["snowflake.cli"].level = global_log_level
|
|
191
|
-
config.loggers["snowflake"].level = global_log_level
|
|
192
|
-
|
|
193
|
-
_configurate_logging(config)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
def _configurate_logging(config: DefaultLoggingConfig | InitialLoggingConfig) -> None:
|
|
197
|
-
dict_config = asdict(config)
|
|
198
|
-
_remove_underscore_prefixes_from_keys(dict_config)
|
|
199
|
-
logging.config.dictConfig(dict_config)
|
snowflake/cli/_app/main_typer.py
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import sys
|
|
18
|
-
|
|
19
|
-
import typer
|
|
20
|
-
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
21
|
-
from snowflake.cli.api.commands.flags import DEFAULT_CONTEXT_SETTINGS, DebugOption
|
|
22
|
-
from snowflake.cli.api.console import cli_console
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def _handle_exception(exception: Exception):
|
|
26
|
-
if get_cli_context().enable_tracebacks:
|
|
27
|
-
raise exception
|
|
28
|
-
else:
|
|
29
|
-
cli_console.warning(
|
|
30
|
-
"\nAn unexpected exception occurred. Use --debug option to see the traceback. Exception message:\n\n"
|
|
31
|
-
+ exception.__str__()
|
|
32
|
-
)
|
|
33
|
-
raise SystemExit(1)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class SnowCliMainTyper(typer.Typer):
|
|
37
|
-
"""
|
|
38
|
-
Top-level SnowCLI Typer.
|
|
39
|
-
It contains global exception handling.
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
def __init__(self):
|
|
43
|
-
super().__init__(
|
|
44
|
-
context_settings=DEFAULT_CONTEXT_SETTINGS,
|
|
45
|
-
pretty_exceptions_show_locals=False,
|
|
46
|
-
add_completion=True,
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
def __call__(self, *args, **kwargs):
|
|
50
|
-
# early detection of "--debug" flag
|
|
51
|
-
# necessary in case of errors which happen during argument parsing
|
|
52
|
-
# (for example badly formatted config file)
|
|
53
|
-
# Hack: We have to go around Typer by checking sys.argv as it does not allow
|
|
54
|
-
# to easily peek into subcommand arguments.
|
|
55
|
-
DebugOption.callback(
|
|
56
|
-
any(param in sys.argv for param in DebugOption.param_decls)
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
try:
|
|
60
|
-
super().__call__(*args, **kwargs)
|
|
61
|
-
except Exception as exception:
|
|
62
|
-
_handle_exception(exception)
|
snowflake/cli/_app/printing.py
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
import json
|
|
18
|
-
import sys
|
|
19
|
-
from datetime import datetime
|
|
20
|
-
from json import JSONEncoder
|
|
21
|
-
from pathlib import Path
|
|
22
|
-
from textwrap import indent
|
|
23
|
-
from typing import TextIO
|
|
24
|
-
|
|
25
|
-
from rich import box, get_console
|
|
26
|
-
from rich import print as rich_print
|
|
27
|
-
from rich.live import Live
|
|
28
|
-
from rich.table import Table
|
|
29
|
-
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
30
|
-
from snowflake.cli.api.output.formats import OutputFormat
|
|
31
|
-
from snowflake.cli.api.output.types import (
|
|
32
|
-
CollectionResult,
|
|
33
|
-
CommandResult,
|
|
34
|
-
MessageResult,
|
|
35
|
-
MultipleResults,
|
|
36
|
-
ObjectResult,
|
|
37
|
-
StreamResult,
|
|
38
|
-
)
|
|
39
|
-
from snowflake.cli.api.sanitizers import sanitize_for_terminal
|
|
40
|
-
|
|
41
|
-
NO_ITEMS_FOUND: str = "No data"
|
|
42
|
-
|
|
43
|
-
# ensure we do not break URLs that wrap lines
|
|
44
|
-
get_console().soft_wrap = True
|
|
45
|
-
|
|
46
|
-
# Disable markup to avoid escaping errors
|
|
47
|
-
get_console()._markup = False # noqa: SLF001
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class CustomJSONEncoder(JSONEncoder):
|
|
51
|
-
"""Custom JSON encoder handling serialization of non-standard types"""
|
|
52
|
-
|
|
53
|
-
def default(self, o):
|
|
54
|
-
if isinstance(o, str):
|
|
55
|
-
return sanitize_for_terminal(o)
|
|
56
|
-
if isinstance(o, (ObjectResult, MessageResult)):
|
|
57
|
-
return o.result
|
|
58
|
-
if isinstance(o, (CollectionResult, MultipleResults)):
|
|
59
|
-
return list(o.result)
|
|
60
|
-
if isinstance(o, datetime):
|
|
61
|
-
return o.isoformat()
|
|
62
|
-
if isinstance(o, Path):
|
|
63
|
-
return str(o)
|
|
64
|
-
return super().default(o)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def _get_format_type() -> OutputFormat:
|
|
68
|
-
output_format = get_cli_context().output_format
|
|
69
|
-
if output_format:
|
|
70
|
-
return output_format
|
|
71
|
-
return OutputFormat.TABLE
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def _get_table():
|
|
75
|
-
return Table(show_header=True, box=box.ASCII)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _print_multiple_table_results(obj: CollectionResult):
|
|
79
|
-
items = obj.result
|
|
80
|
-
try:
|
|
81
|
-
first_item = next(items)
|
|
82
|
-
except StopIteration:
|
|
83
|
-
rich_print(NO_ITEMS_FOUND, end="\n\n")
|
|
84
|
-
return
|
|
85
|
-
table = _get_table()
|
|
86
|
-
for column in first_item.keys():
|
|
87
|
-
table.add_column(column, overflow="fold")
|
|
88
|
-
with Live(table, refresh_per_second=4):
|
|
89
|
-
table.add_row(*[str(i) for i in first_item.values()])
|
|
90
|
-
for item in items:
|
|
91
|
-
table.add_row(*[str(i) for i in item.values()])
|
|
92
|
-
# Add separator between tables
|
|
93
|
-
rich_print(flush=True)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def is_structured_format(output_format):
|
|
97
|
-
return output_format == OutputFormat.JSON
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def print_structured(result: CommandResult):
|
|
101
|
-
"""Handles outputs like json, yml and other structured and parsable formats."""
|
|
102
|
-
printed_end_line = False
|
|
103
|
-
if isinstance(result, MultipleResults):
|
|
104
|
-
_stream_json(result)
|
|
105
|
-
elif isinstance(result, StreamResult):
|
|
106
|
-
# A StreamResult prints each value onto its own line
|
|
107
|
-
# instead of joining all the values into a JSON array
|
|
108
|
-
for r in result.result:
|
|
109
|
-
json.dump(r, sys.stdout, cls=CustomJSONEncoder)
|
|
110
|
-
print(flush=True)
|
|
111
|
-
printed_end_line = True
|
|
112
|
-
else:
|
|
113
|
-
json.dump(result, sys.stdout, cls=CustomJSONEncoder, indent=4)
|
|
114
|
-
# Adds empty line at the end
|
|
115
|
-
if not printed_end_line:
|
|
116
|
-
print(flush=True)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def _stream_json(result):
|
|
120
|
-
"""Simple helper for streaming multiple results as a JSON."""
|
|
121
|
-
indent_size = 2
|
|
122
|
-
|
|
123
|
-
class _Indented:
|
|
124
|
-
def __init__(self, stream: TextIO):
|
|
125
|
-
self._stream = stream
|
|
126
|
-
|
|
127
|
-
def write(self, text: str):
|
|
128
|
-
return self._stream.write(indent(text, " " * indent_size))
|
|
129
|
-
|
|
130
|
-
print("[")
|
|
131
|
-
results = result.result
|
|
132
|
-
res = next(results, None)
|
|
133
|
-
while res:
|
|
134
|
-
json.dump(res, _Indented(sys.stdout), cls=CustomJSONEncoder, indent=indent_size) # type: ignore
|
|
135
|
-
if res := next(results, None):
|
|
136
|
-
print(",")
|
|
137
|
-
print("\n]")
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def print_unstructured(obj: CommandResult | None):
|
|
141
|
-
"""Handles outputs like table, plain text and other unstructured types."""
|
|
142
|
-
if not obj:
|
|
143
|
-
rich_print("Done", flush=True)
|
|
144
|
-
elif not obj.result:
|
|
145
|
-
rich_print("No data", flush=True)
|
|
146
|
-
elif isinstance(obj, MessageResult):
|
|
147
|
-
rich_print(sanitize_for_terminal(obj.message), flush=True)
|
|
148
|
-
else:
|
|
149
|
-
if isinstance(obj, ObjectResult):
|
|
150
|
-
_print_single_table(obj)
|
|
151
|
-
elif isinstance(obj, CollectionResult):
|
|
152
|
-
_print_multiple_table_results(obj)
|
|
153
|
-
else:
|
|
154
|
-
raise TypeError(f"No print strategy for type: {type(obj)}")
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def _print_single_table(obj):
|
|
158
|
-
table = _get_table()
|
|
159
|
-
table.add_column("key", overflow="fold")
|
|
160
|
-
table.add_column("value", overflow="fold")
|
|
161
|
-
for key, value in obj.result.items():
|
|
162
|
-
table.add_row(
|
|
163
|
-
sanitize_for_terminal(str(key)), sanitize_for_terminal(str(value))
|
|
164
|
-
)
|
|
165
|
-
rich_print(table, flush=True)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
def print_result(cmd_result: CommandResult, output_format: OutputFormat | None = None):
|
|
169
|
-
output_format = output_format or _get_format_type()
|
|
170
|
-
if is_structured_format(output_format):
|
|
171
|
-
print_structured(cmd_result)
|
|
172
|
-
elif isinstance(cmd_result, (MultipleResults, StreamResult)):
|
|
173
|
-
for res in cmd_result.result:
|
|
174
|
-
print_result(res)
|
|
175
|
-
elif (
|
|
176
|
-
isinstance(cmd_result, (MessageResult, ObjectResult, CollectionResult))
|
|
177
|
-
or cmd_result is None
|
|
178
|
-
):
|
|
179
|
-
print_unstructured(cmd_result)
|
|
180
|
-
else:
|
|
181
|
-
raise ValueError(f"Unexpected type {type(cmd_result)}")
|