Skip to content

Commit 6479df9

Browse files
sfc-gh-mborinsCortex Code
andcommitted
fix: resolve CI failures for snow run command
Fix code quality issues (trailing whitespace, ruff G004 f-string logging, black formatting), Windows test failures (subprocess mock was polluting global scope via shared module reference), and update E2E snapshots to include the new run command in snow --help output. .... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code) Co-Authored-By: Cortex Code <[email protected]>
1 parent a73fa71 commit 6479df9

File tree

5 files changed

+50
-34
lines changed

5 files changed

+50
-34
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def run_script(
116116
for name in scripts:
117117
cc.message(f" {name}")
118118
return MessageResult("\nSpecify a script name to run, or use --list")
119-
return MessageResult("No scripts defined. Add a 'scripts' section to snowflake.yml or manifest.yml")
119+
return MessageResult(
120+
"No scripts defined. Add a 'scripts' section to snowflake.yml or manifest.yml"
121+
)
120122

121123
vars_dict = {}
122124
if var_overrides:

src/snowflake/cli/_plugins/run/manager.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import os
1919
import re
2020
import shlex
21-
import subprocess
2221
import sys
2322
from dataclasses import dataclass
2423
from pathlib import Path
24+
from subprocess import run as _subprocess_run
2525
from typing import Dict, List, Optional, Tuple
2626

2727
import yaml
@@ -58,7 +58,7 @@ def __init__(self, project_root: Path):
5858

5959
def _load_scripts(self) -> None:
6060
"""Load scripts from snowflake.yml or manifest.yml.
61-
61+
6262
Scripts can be defined in either file but not both.
6363
Raises ClickException if scripts are found in both files.
6464
"""
@@ -81,15 +81,23 @@ def _load_scripts(self) -> None:
8181
self._scripts = manifest_scripts
8282
self._scripts_source = manifest_source
8383

84-
def _load_snowflake_scripts(self) -> Tuple[Optional[Dict[str, ScriptModel]], Optional[str]]:
84+
def _load_snowflake_scripts(
85+
self,
86+
) -> Tuple[Optional[Dict[str, ScriptModel]], Optional[str]]:
8587
"""Load scripts from snowflake.yml via project definition."""
8688
ctx = get_cli_context()
8789
project_def = ctx.project_definition
88-
if project_def and isinstance(project_def, DefinitionV20) and project_def.scripts:
90+
if (
91+
project_def
92+
and isinstance(project_def, DefinitionV20)
93+
and project_def.scripts
94+
):
8995
return project_def.scripts, "snowflake.yml"
9096
return None, None
9197

92-
def _load_manifest_scripts(self) -> Tuple[Optional[Dict[str, ScriptModel]], Optional[str]]:
98+
def _load_manifest_scripts(
99+
self,
100+
) -> Tuple[Optional[Dict[str, ScriptModel]], Optional[str]]:
93101
"""Load scripts from manifest.yml if present."""
94102
manifest_path = SecurePath(self.project_root / MANIFEST_FILE_NAME)
95103
if not manifest_path.exists():
@@ -99,7 +107,7 @@ def _load_manifest_scripts(self) -> Tuple[Optional[Dict[str, ScriptModel]], Opti
99107
with manifest_path.open("r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB) as f:
100108
manifest_data = yaml.safe_load(f.read())
101109
except Exception as e:
102-
log.debug(f"Could not read manifest.yml: {e}")
110+
log.debug("Could not read manifest.yml: %s", e)
103111
return None, None
104112

105113
if not manifest_data or "scripts" not in manifest_data:
@@ -216,7 +224,13 @@ def execute_script(
216224

217225
if script.run:
218226
return self._execute_composite(
219-
name, script, extra_args, var_overrides, dry_run, verbose, continue_on_error
227+
name,
228+
script,
229+
extra_args,
230+
var_overrides,
231+
dry_run,
232+
verbose,
233+
continue_on_error,
220234
)
221235

222236
return self._execute_command(
@@ -260,14 +274,14 @@ def _execute_command(
260274
)
261275

262276
if sys.platform == "win32":
263-
result = subprocess.run(
277+
result = _subprocess_run(
264278
cmd,
265279
shell=True,
266280
cwd=cwd,
267281
env=env,
268282
)
269283
else:
270-
result = subprocess.run(
284+
result = _subprocess_run(
271285
cmd,
272286
shell=True,
273287
cwd=cwd,
@@ -276,7 +290,7 @@ def _execute_command(
276290
)
277291
else:
278292
args = shlex.split(cmd)
279-
result = subprocess.run(
293+
result = _subprocess_run(
280294
args,
281295
cwd=cwd,
282296
env=env,

tests/run/test_commands.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
from unittest import mock
1616

17-
import pytest
18-
19-
SUBPROCESS_RUN = "snowflake.cli._plugins.run.manager.subprocess.run"
17+
SUBPROCESS_RUN = "snowflake.cli._plugins.run.manager._subprocess_run"
2018

2119

2220
class TestRunList:
@@ -96,15 +94,19 @@ def test_run_composite_script(self, mock_run, runner, project_directory):
9694
assert "2 scripts executed" in result.output
9795

9896
@mock.patch(SUBPROCESS_RUN)
99-
def test_run_composite_script_stops_on_error(self, mock_run, runner, project_directory):
97+
def test_run_composite_script_stops_on_error(
98+
self, mock_run, runner, project_directory
99+
):
100100
mock_run.return_value = mock.Mock(returncode=1)
101101
with project_directory("run_scripts"):
102102
result = runner.invoke(["run", "deploy-all"])
103103
assert result.exit_code == 1
104104
assert mock_run.call_count == 1
105105

106106
@mock.patch(SUBPROCESS_RUN)
107-
def test_run_composite_script_continue_on_error(self, mock_run, runner, project_directory):
107+
def test_run_composite_script_continue_on_error(
108+
self, mock_run, runner, project_directory
109+
):
108110
mock_run.return_value = mock.Mock(returncode=1)
109111
with project_directory("run_scripts"):
110112
result = runner.invoke(["run", "deploy-all", "--continue-on-error"])
@@ -168,7 +170,9 @@ def test_run_script_from_manifest(self, mock_run, runner, project_directory):
168170
assert "echo" in mock_run.call_args[0][0][0]
169171

170172
@mock.patch(SUBPROCESS_RUN)
171-
def test_run_composite_script_from_manifest(self, mock_run, runner, project_directory):
173+
def test_run_composite_script_from_manifest(
174+
self, mock_run, runner, project_directory
175+
):
172176
mock_run.return_value = mock.Mock(returncode=0)
173177
with project_directory("run_manifest_scripts"):
174178
result = runner.invoke(["run", "all"])

tests/run/test_integration.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
16-
from pathlib import Path
1715
from unittest import mock
1816

19-
import pytest
20-
21-
SUBPROCESS_RUN = "snowflake.cli._plugins.run.manager.subprocess.run"
17+
SUBPROCESS_RUN = "snowflake.cli._plugins.run.manager._subprocess_run"
2218

2319

2420
class TestRunIntegration:
2521
"""Integration tests for snow run command."""
2622

2723
@mock.patch(SUBPROCESS_RUN)
28-
def test_run_echo_script_in_real_project(
29-
self, mock_run, runner, project_directory
30-
):
24+
def test_run_echo_script_in_real_project(self, mock_run, runner, project_directory):
3125
"""Test running a simple echo script."""
3226
mock_run.return_value = mock.Mock(returncode=0)
3327
with project_directory("run_scripts"):
@@ -38,9 +32,7 @@ def test_run_echo_script_in_real_project(
3832
mock_run.assert_called_once()
3933

4034
@mock.patch(SUBPROCESS_RUN)
41-
def test_composite_script_runs_all_steps(
42-
self, mock_run, runner, project_directory
43-
):
35+
def test_composite_script_runs_all_steps(self, mock_run, runner, project_directory):
4436
"""Test composite script executes all child scripts."""
4537
mock_run.return_value = mock.Mock(returncode=0)
4638
with project_directory("run_scripts"):
@@ -63,9 +55,7 @@ def test_variable_interpolation_from_env_section(
6355
assert "TEMP.DEV_PLATFORM" in cmd
6456

6557
@mock.patch(SUBPROCESS_RUN)
66-
def test_override_variable_from_cli(
67-
self, mock_run, runner, project_directory
68-
):
58+
def test_override_variable_from_cli(self, mock_run, runner, project_directory):
6959
"""Test that -D flag properly overrides variables."""
7060
mock_run.return_value = mock.Mock(returncode=0)
7161
with project_directory("run_scripts"):
@@ -75,9 +65,7 @@ def test_override_variable_from_cli(
7565
assert "PRODUCTION" in cmd
7666

7767
@mock.patch(SUBPROCESS_RUN)
78-
def test_shell_mode_for_pipes(
79-
self, mock_run, runner, project_directory
80-
):
68+
def test_shell_mode_for_pipes(self, mock_run, runner, project_directory):
8169
"""Test that shell=true scripts use shell execution."""
8270
mock_run.return_value = mock.Mock(returncode=0)
8371
with project_directory("run_scripts"):

tests_e2e/__snapshots__/test_installation.ambr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
| logs Retrieves logs for a given object. |
4141
| notebook Manages notebooks in Snowflake. |
4242
| object Manages Snowflake objects like warehouses and stages |
43+
| run Execute project scripts defined in snowflake.yml or |
44+
| manifest.yml. |
4345
| snowpark Manages procedures and functions. |
4446
| spcs Manages Snowpark Container Services compute pools, |
4547
| services, image registries, and image repositories. |
@@ -104,6 +106,8 @@
104106
| logs Retrieves logs for a given object. |
105107
| notebook Manages notebooks in Snowflake. |
106108
| object Manages Snowflake objects like warehouses and stages |
109+
| run Execute project scripts defined in snowflake.yml or |
110+
| manifest.yml. |
107111
| snowpark Manages procedures and functions. |
108112
| spcs Manages Snowpark Container Services compute pools, services, |
109113
| image registries, and image repositories. |
@@ -149,6 +153,8 @@
149153
| logs Retrieves logs for a given object. |
150154
| notebook Manages notebooks in Snowflake. |
151155
| object Manages Snowflake objects like warehouses and stages |
156+
| run Execute project scripts defined in snowflake.yml or |
157+
| manifest.yml. |
152158
| snowpark Manages procedures and functions. |
153159
| spcs Manages Snowpark Container Services compute pools, |
154160
| services, image registries, and image repositories. |
@@ -233,6 +239,8 @@
233239
| logs Retrieves logs for a given object. |
234240
| notebook Manages notebooks in Snowflake. |
235241
| object Manages Snowflake objects like warehouses and stages |
242+
| run Execute project scripts defined in snowflake.yml or |
243+
| manifest.yml. |
236244
| snowpark Manages procedures and functions. |
237245
| spcs Manages Snowpark Container Services compute pools, services, |
238246
| image registries, and image repositories. |

0 commit comments

Comments
 (0)