Skip to content

Commit

Permalink
shlex.split()
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-gbloom committed Aug 23, 2024
1 parent 5b9f91e commit a3bb31d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
6 changes: 2 additions & 4 deletions src/snowflake/cli/_plugins/workspace/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ def deploy(
"""
Deploys the specified entity.
"""

has_paths = paths is not None and len(paths) > 0
if prune is None and recursive is None and not has_paths:
if prune is None and recursive is None and not paths:
prune = True
recursive = True
else:
Expand All @@ -111,7 +109,7 @@ def deploy(
if recursive is None:
recursive = False

if has_paths and prune:
if paths and prune:
raise IncompatibleParametersError(["paths", "--prune"])

cli_context = get_cli_context()
Expand Down
5 changes: 3 additions & 2 deletions tests_integration/nativeapp/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import os.path
import yaml
from shlex import split

from tests.project.fixtures import *
from tests_integration.test_utils import enable_definition_v2_feature_flag
Expand All @@ -38,10 +39,10 @@ def template_setup(runner, nativeapp_project_directory, request):
# Vanilla bundle on the unmodified template
if command.startswith("ws"):
execute_bundle_command = lambda: runner.invoke_with_connection(
command.split()
split(command)
)
else:
execute_bundle_command = lambda: runner.invoke_json(command.split())
execute_bundle_command = lambda: runner.invoke_json(split(command))
result = execute_bundle_command()

assert result.exit_code == 0
Expand Down
36 changes: 17 additions & 19 deletions tests_integration/nativeapp/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import os
import uuid
from shlex import split

from snowflake.cli.api.project.util import TEST_RESOURCE_SUFFIX_VAR
from tests.nativeapp.utils import touch
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_nativeapp_deploy(
):
project_name = "myapp"
with nativeapp_project_directory(test_project):
result = runner.invoke_with_connection(command.split())
result = runner.invoke_with_connection(split(command))
assert result.exit_code == 0
assert sanitize_deploy_output(result.output) == snapshot

Expand Down Expand Up @@ -102,7 +102,7 @@ def test_nativeapp_deploy(
)

# re-deploying should be a no-op; make sure we don't issue any PUT commands
result = runner.invoke_with_connection([*command.split(), "--debug"])
result = runner.invoke_with_connection([*split(command), "--debug"])
assert result.exit_code == 0
assert "Successfully uploaded chunk 0 of file" not in result.output

Expand Down Expand Up @@ -193,7 +193,7 @@ def test_nativeapp_deploy_prune(
os.remove(os.path.join("app", "README.md"))

# deploy
result = runner.invoke_with_connection(command.split())
result = runner.invoke_with_connection(split(command))
assert result.exit_code == 0
assert sanitize_deploy_output(result.output) == snapshot

Expand Down Expand Up @@ -236,7 +236,7 @@ def test_nativeapp_deploy_files(
# sync only two specific files to stage
result = runner.invoke_with_connection(
[
*command.split(),
*split(command),
"app/manifest.yml",
"app/setup_script.sql",
]
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_nativeapp_deploy_nested_directories(
touch("app/nested/dir/file.txt")

result = runner.invoke_with_connection(
[*command.split(), "app/nested/dir/file.txt"]
[*split(command), "app/nested/dir/file.txt"]
)
assert result.exit_code == 0
assert sanitize_deploy_output(result.output) == snapshot
Expand Down Expand Up @@ -322,13 +322,13 @@ def test_nativeapp_deploy_directory(
with nativeapp_project_directory(test_project):
touch("app/dir/file.txt")
result = runner.invoke_with_connection(
[*command.split(), "app/dir", "--no-recursive"]
[*split(command), "app/dir", "--no-recursive"]
)
assert_that_result_failed_with_message_containing(
result, "Add the -r flag to deploy directories."
)

result = runner.invoke_with_connection([*command.split(), "app/dir", "-r"])
result = runner.invoke_with_connection([*split(command), "app/dir", "-r"])
assert result.exit_code == 0

package_name = f"{project_name}_pkg_{default_username}{resource_suffix}".upper()
Expand Down Expand Up @@ -358,7 +358,7 @@ def test_nativeapp_deploy_directory_no_recursive(
):
with nativeapp_project_directory(test_project):
touch("app/nested/dir/file.txt")
result = runner.invoke_with_connection_json([*command.split(), "app/nested"])
result = runner.invoke_with_connection_json([*split(command), "app/nested"])
assert result.exit_code == 1, result.output


Expand All @@ -380,9 +380,7 @@ def test_nativeapp_deploy_unknown_path(
runner,
):
with nativeapp_project_directory(test_project):
result = runner.invoke_with_connection_json(
[*command.split(), "does_not_exist"]
)
result = runner.invoke_with_connection_json([*split(command), "does_not_exist"])
assert result.exit_code == 1
assert "The following path does not exist:" in result.output

Expand All @@ -405,7 +403,7 @@ def test_nativeapp_deploy_path_with_no_mapping(
runner,
):
with nativeapp_project_directory(test_project):
result = runner.invoke_with_connection_json([*command.split(), "snowflake.yml"])
result = runner.invoke_with_connection_json([*split(command), "snowflake.yml"])
assert result.exit_code == 1
assert "No artifact found for" in result.output

Expand All @@ -430,7 +428,7 @@ def test_nativeapp_deploy_rejects_pruning_when_path_is_specified(
with nativeapp_project_directory(test_project):
os.unlink("app/README.md")
result = runner.invoke_with_connection_json(
[*command.split(), "app/README.md", "--prune"]
[*split(command), "app/README.md", "--prune"]
)

assert_that_result_is_usage_error(
Expand Down Expand Up @@ -463,7 +461,7 @@ def test_nativeapp_deploy_looks_for_prefix_matches(
):
project_name = "myapp"
with nativeapp_project_directory(test_project):
result = runner.invoke_with_connection([*command.split(), "-r", "app"])
result = runner.invoke_with_connection([*split(command), "-r", "app"])
assert result.exit_code == 0
assert sanitize_deploy_output(result.output) == snapshot

Expand All @@ -481,7 +479,7 @@ def test_nativeapp_deploy_looks_for_prefix_matches(
)

result = runner.invoke_with_connection(
[*command.split(), "-r", "lib/parent/child/c"]
[*split(command), "-r", "lib/parent/child/c"]
)
assert result.exit_code == 0
stage_files = runner.invoke_with_connection_json(
Expand All @@ -498,7 +496,7 @@ def test_nativeapp_deploy_looks_for_prefix_matches(
)

result = runner.invoke_with_connection(
[*command.split(), "lib/parent/child/a.py"]
[*split(command), "lib/parent/child/a.py"]
)
assert result.exit_code == 0
stage_files = runner.invoke_with_connection_json(
Expand All @@ -514,7 +512,7 @@ def test_nativeapp_deploy_looks_for_prefix_matches(
stage_files.json, {"name": "stage/parent-lib/child/b.py"}
)

result = runner.invoke_with_connection([*command.split(), "lib", "-r"])
result = runner.invoke_with_connection([*split(command), "lib", "-r"])
assert result.exit_code == 0
stage_files = runner.invoke_with_connection_json(
["stage", "list-files", f"{package_name}.{stage_name}"]
Expand Down Expand Up @@ -554,7 +552,7 @@ def test_nativeapp_deploy_dot(
):
project_name = "myapp"
with nativeapp_project_directory(test_project):
result = runner.invoke_with_connection([*command.split(), "-r", "."])
result = runner.invoke_with_connection([*split(command), "-r", "."])
assert result.exit_code == 0
assert sanitize_deploy_output(result.output) == snapshot

Expand Down

0 comments on commit a3bb31d

Please sign in to comment.