Skip to content

Commit 24146a2

Browse files
Jw/snow 2273956 remove snowflake yml dependency (#2572)
* feat: [SNOW-2273956] add a spinner to console api * feat: [SNOW-2273956] refactor dcm create, list-deployments and drop-deployment * feat: [SNOW-2273956] refactor dcm plan and deploy * cleanup: [SNOW-2273956] remove DCMProjectEntity * style: [SNOW-2273956] style spinner * feat: [SNOW-2273956] wip: prevent redos * fix: [SNOW-2273956] fix unit test * fix: [SNOW-2273956] respond to initial batch of comments * fix: [SNOW-2273956] respond to initial batch of comments * feat: [SNOW-2273956] use pydantic for regexp validation * feat: [SNOW-2273956] move upload logic and project validation to manager
1 parent feca5e6 commit 24146a2

File tree

24 files changed

+869
-272
lines changed

24 files changed

+869
-272
lines changed

src/snowflake/cli/_plugins/dbt/commands.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import typer
2121
from click import types
22-
from rich.progress import Progress, SpinnerColumn, TextColumn
2322
from snowflake.cli._plugins.dbt.constants import (
2423
DBT_COMMANDS,
2524
OUTPUT_COLUMN_NAME,
@@ -33,6 +32,7 @@
3332
from snowflake.cli.api.commands.flags import identifier_argument, like_option
3433
from snowflake.cli.api.commands.overrideable_parameter import OverrideableOption
3534
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
35+
from snowflake.cli.api.console.console import cli_console
3636
from snowflake.cli.api.constants import ObjectType
3737
from snowflake.cli.api.exceptions import CliError
3838
from snowflake.cli.api.feature_flags import FeatureFlag
@@ -186,13 +186,8 @@ def _dbt_execute(
186186
f"Command submitted. You can check the result with `snow sql -q \"select execution_status from table(information_schema.query_history_by_user()) where query_id in ('{result.sfqid}');\"`"
187187
)
188188

189-
with Progress(
190-
SpinnerColumn(),
191-
TextColumn("[progress.description]{task.description}"),
192-
transient=True,
193-
) as progress:
194-
progress.add_task(description=f"Executing 'dbt {dbt_command}'", total=None)
195-
189+
with cli_console.spinner() as spinner:
190+
spinner.add_task(description=f"Executing 'dbt {dbt_command}'", total=None)
196191
result = dbt_manager.execute(*execute_args)
197192

198193
try:

src/snowflake/cli/_plugins/dcm/commands.py

Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,26 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import time
1514
from typing import List, Optional
1615

1716
import typer
18-
from snowflake.cli._plugins.dcm.dcm_project_entity_model import (
19-
DCMProjectEntityModel,
20-
)
2117
from snowflake.cli._plugins.dcm.manager import DCMProjectManager
2218
from snowflake.cli._plugins.object.command_aliases import add_object_command_aliases
2319
from snowflake.cli._plugins.object.commands import scope_option
2420
from snowflake.cli._plugins.object.manager import ObjectManager
25-
from snowflake.cli._plugins.stage.manager import StageManager
26-
from snowflake.cli.api.artifacts.upload import sync_artifacts_with_stage
27-
from snowflake.cli.api.cli_global_context import get_cli_context
28-
from snowflake.cli.api.commands.decorators import with_project_definition
2921
from snowflake.cli.api.commands.flags import (
3022
IfExistsOption,
3123
IfNotExistsOption,
3224
OverrideableOption,
33-
entity_argument,
3425
identifier_argument,
3526
like_option,
3627
variables_option,
3728
)
3829
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
39-
from snowflake.cli.api.commands.utils import get_entity_for_operation
4030
from snowflake.cli.api.console.console import cli_console
41-
from snowflake.cli.api.constants import ObjectType
31+
from snowflake.cli.api.constants import (
32+
ObjectType,
33+
)
4234
from snowflake.cli.api.exceptions import CliError
4335
from snowflake.cli.api.feature_flags import FeatureFlag
4436
from snowflake.cli.api.identifiers import FQN
@@ -47,8 +39,6 @@
4739
QueryJsonValueResult,
4840
QueryResult,
4941
)
50-
from snowflake.cli.api.project.project_paths import ProjectPaths
51-
from snowflake.cli.api.project.util import unquote_identifier
5242

5343
app = SnowTyperFactory(
5444
name="dcm",
@@ -127,14 +117,19 @@ def deploy(
127117
"""
128118
Applies changes defined in DCM Project to Snowflake.
129119
"""
130-
result = DCMProjectManager().execute(
131-
project_name=identifier,
132-
configuration=configuration,
133-
from_stage=from_stage if from_stage else _sync_local_files(),
134-
variables=variables,
135-
alias=alias,
136-
output_path=None,
137-
)
120+
manager = DCMProjectManager()
121+
if not from_stage:
122+
from_stage = manager.sync_local_files(project_identifier=identifier)
123+
with cli_console.spinner() as spinner:
124+
spinner.add_task(description=f"Deploying dcm project {identifier}", total=None)
125+
result = manager.execute(
126+
project_identifier=identifier,
127+
configuration=configuration,
128+
from_stage=from_stage,
129+
variables=variables,
130+
alias=alias,
131+
output_path=None,
132+
)
138133
return QueryJsonValueResult(result)
139134

140135

@@ -154,21 +149,27 @@ def plan(
154149
"""
155150
Plans a DCM Project deployment (validates without executing).
156151
"""
157-
result = DCMProjectManager().execute(
158-
project_name=identifier,
159-
configuration=configuration,
160-
from_stage=from_stage if from_stage else _sync_local_files(),
161-
dry_run=True,
162-
variables=variables,
163-
output_path=output_path,
164-
)
152+
manager = DCMProjectManager()
153+
if not from_stage:
154+
from_stage = manager.sync_local_files(project_identifier=identifier)
155+
156+
with cli_console.spinner() as spinner:
157+
spinner.add_task(description=f"Planning dcm project {identifier}", total=None)
158+
result = manager.execute(
159+
project_identifier=identifier,
160+
configuration=configuration,
161+
from_stage=from_stage,
162+
dry_run=True,
163+
variables=variables,
164+
output_path=output_path,
165+
)
166+
165167
return QueryJsonValueResult(result)
166168

167169

168170
@app.command(requires_connection=True)
169-
@with_project_definition()
170171
def create(
171-
entity_id: str = entity_argument("dcm"),
172+
identifier: FQN = dcm_identifier,
172173
if_not_exists: bool = IfNotExistsOption(
173174
help="Do nothing if the project already exists."
174175
),
@@ -177,25 +178,18 @@ def create(
177178
"""
178179
Creates a DCM Project in Snowflake.
179180
"""
180-
cli_context = get_cli_context()
181-
project: DCMProjectEntityModel = get_entity_for_operation(
182-
cli_context=cli_context,
183-
entity_id=entity_id,
184-
project_definition=cli_context.project_definition,
185-
entity_type="dcm",
186-
)
187181
om = ObjectManager()
188-
if om.object_exists(object_type="dcm", fqn=project.fqn):
189-
message = f"DCM Project '{project.fqn}' already exists."
182+
if om.object_exists(object_type="dcm", fqn=identifier):
183+
message = f"DCM Project '{identifier}' already exists."
190184
if if_not_exists:
191185
return MessageResult(message)
192186
raise CliError(message)
193187

194188
dpm = DCMProjectManager()
195-
with cli_console.phase(f"Creating DCM Project '{project.fqn}'"):
196-
dpm.create(project=project)
189+
with cli_console.phase(f"Creating DCM Project '{identifier}'"):
190+
dpm.create(project_identifier=identifier)
197191

198-
return MessageResult(f"DCM Project '{project.fqn}' successfully created.")
192+
return MessageResult(f"DCM Project '{identifier}' successfully created.")
199193

200194

201195
@app.command(requires_connection=True)
@@ -207,7 +201,7 @@ def list_deployments(
207201
Lists deployments of given DCM Project.
208202
"""
209203
pm = DCMProjectManager()
210-
results = pm.list_deployments(project_name=identifier)
204+
results = pm.list_deployments(project_identifier=identifier)
211205
return QueryResult(results)
212206

213207

@@ -235,40 +229,10 @@ def drop_deployment(
235229

236230
dpm = DCMProjectManager()
237231
dpm.drop_deployment(
238-
project_name=identifier,
232+
project_identifier=identifier,
239233
deployment_name=deployment_name,
240234
if_exists=if_exists,
241235
)
242236
return MessageResult(
243237
f"Deployment '{deployment_name}' dropped from DCM Project '{identifier}'."
244238
)
245-
246-
247-
def _sync_local_files() -> str:
248-
cli_context = get_cli_context()
249-
project_entity = get_entity_for_operation(
250-
cli_context=cli_context,
251-
entity_id=None,
252-
project_definition=cli_context.project_definition,
253-
entity_type="dcm",
254-
)
255-
256-
# Create a temporary stage for this deployment session
257-
stage_manager = StageManager()
258-
unquoted_name = unquote_identifier(project_entity.fqn.name)
259-
stage_fqn = FQN.from_string(
260-
f"DCM_{unquoted_name}_{int(time.time())}_TMP_STAGE"
261-
).using_context()
262-
263-
with cli_console.phase("Creating temporary stage for deployment"):
264-
stage_manager.create(fqn=stage_fqn, temporary=True)
265-
cli_console.step(f"Created temporary stage: {stage_fqn}")
266-
267-
with cli_console.phase("Syncing local files to temporary stage"):
268-
sync_artifacts_with_stage(
269-
project_paths=ProjectPaths(project_root=cli_context.project_root),
270-
stage_root=stage_fqn.identifier,
271-
artifacts=project_entity.artifacts,
272-
)
273-
274-
return stage_fqn.identifier

src/snowflake/cli/_plugins/dcm/dcm_project_entity_model.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)