Skip to content

Commit

Permalink
Build snowpark deps only if any exist (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-turbaszek authored Aug 23, 2024
1 parent 743a183 commit 5e929c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/snowflake/cli/_plugins/snowpark/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,14 @@ def build(
requirements=download_result.anaconda_packages,
)

cli_console.step(f"Creating {project_paths.dependencies.name}")
zip_dir(
source=temp_deps_dir.path,
dest_zip=project_paths.dependencies,
)
if any(temp_deps_dir.path.iterdir()):
cli_console.step(f"Creating {project_paths.dependencies.name}")
zip_dir(
source=temp_deps_dir.path,
dest_zip=project_paths.dependencies,
)
else:
cli_console.step(f"No external dependencies.")

artifacts = set()
for entity in get_snowpark_entities(pd).values():
Expand Down
10 changes: 7 additions & 3 deletions tests_integration/test_snowpark.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ def test_snowpark_with_separately_created_package(

with project_directory("snowpark_with_import") as p_dir:

_test_steps.snowpark_build_should_zip_files(additional_files=[Path("app.zip")])
_test_steps.snowpark_build_should_zip_files(
additional_files=[Path("app.zip")], no_dependencies=True
)

_test_steps.snowpark_deploy_should_finish_successfully_and_return(
[
Expand Down Expand Up @@ -464,7 +466,9 @@ def test_snowpark_default_arguments(
):
database = test_database.upper()
with project_directory("snowpark_with_default_values") as tmp_dir:
_test_steps.snowpark_build_should_zip_files(additional_files=[Path("app.zip")])
_test_steps.snowpark_build_should_zip_files(
additional_files=[Path("app.zip")], no_dependencies=True
)

_test_steps.snowpark_deploy_should_finish_successfully_and_return(
[
Expand Down Expand Up @@ -730,7 +734,7 @@ def test_build_skip_version_check(
)
assert result.exit_code == 0, result.output
assert "Build done." in result.output
assert "Creating dependencies.zip" in result.output
assert "Creating dependencies.zip" not in result.output
assert "Creating: app.zip" in result.output


Expand Down
8 changes: 6 additions & 2 deletions tests_integration/testing_utils/snowpark_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,15 @@ def object_describe_should_return_entity_description(
)
assert result.json is not None

def snowpark_build_should_zip_files(self, *args, additional_files=None) -> None:
def snowpark_build_should_zip_files(
self, *args, additional_files=None, no_dependencies=False
) -> None:
if not additional_files:
additional_files = []

if not no_dependencies:
additional_files.append(Path("dependencies.zip"))

current_files = set(Path(".").glob("**/*"))
result = self._setup.runner.invoke_json(
["snowpark", "build", "--format", "JSON", *args]
Expand All @@ -179,7 +184,6 @@ def snowpark_build_should_zip_files(self, *args, additional_files=None) -> None:

assert_that_current_working_directory_contains_only_following_files(
*current_files,
Path("dependencies.zip"),
*additional_files,
Path("requirements.snowflake.txt"),
excluded_paths=[".packages"],
Expand Down

0 comments on commit 5e929c0

Please sign in to comment.