Skip to content

Commit

Permalink
Snow 1650685 fix snowpark package (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pczajka authored and sfc-gh-jsikorski committed Sep 10, 2024
1 parent 54e854c commit 9059144
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Fixed `snow git setup` command behaviour for fully qualified repository names.
* Fixed `snow git setup` command behaviour in case API integration or secret with default name already exists.
* `snow streamlit deploy` will check for existing streamlit instance before deploying anything.
* Fixed `snow snowpark package create` creating empty zip when package name contained capital letters.

# v3.0.0
## Backward incompatibility
Expand Down
3 changes: 2 additions & 1 deletion src/snowflake/cli/_plugins/snowpark/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ def from_wheel(cls, wheel_path: Path):
if line.startswith(dep_keyword)
]
name = cls._get_name_from_wheel_filename(wheel_path.name)

return cls(name=name, wheel_path=wheel_path, dependencies=dependencies)

@staticmethod
def _get_name_from_wheel_filename(wheel_filename: str) -> str:
# wheel filename is in format {name}-{version}[-{extra info}]
# https://peps.python.org/pep-0491/#file-name-convention
return wheel_filename.split("-")[0]
return wheel_filename.split("-")[0].lower()

@staticmethod
def to_wheel_name_format(package_name: str) -> str:
Expand Down
30 changes: 29 additions & 1 deletion tests/snowpark/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
# limitations under the License.

import pytest
from snowflake.cli._plugins.snowpark.models import Requirement, get_package_name
from snowflake.cli._plugins.snowpark.models import (
Requirement,
WheelMetadata,
get_package_name,
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -58,3 +62,27 @@ def test_requirement_is_parsed_correctly(line, name, extras):
)
def test_get_package_name(line, name):
assert get_package_name(line) == name


def test_wheel_metadata_parsing(test_root_path):
from snowflake.cli._plugins.snowpark.zipper import zip_dir
from snowflake.cli.api.secure_path import SecurePath

with SecurePath.temporary_directory() as tmpdir:
wheel_path = tmpdir / "Zendesk-1.1.1-py3-none-any.whl"

# prepare .whl package
package_dir = tmpdir / "ZendeskWhl"
package_dir.mkdir()
package_src = (
SecurePath(test_root_path) / "test_data" / "local_packages" / ".packages"
)
for srcdir in ["zendesk", "Zendesk-1.1.1.dist-info"]:
(package_src / srcdir).copy(package_dir.path)
zip_dir(source=package_dir.path, dest_zip=wheel_path.path)

# check metadata
meta = WheelMetadata.from_wheel(wheel_path.path)
assert meta.name == "zendesk"
assert meta.wheel_path == wheel_path.path
assert meta.dependencies == ["httplib2", "simplejson"]
24 changes: 24 additions & 0 deletions tests_integration/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,30 @@ def test_package_with_native_libraries(self, directory_for_test, runner):
assert result.exit_code == 1
assert "at https://support.anaconda.com/" in result.output

@pytest.mark.integration
def test_package_with_capital_letters(self, directory_for_test, runner):
# TODO: change to package controlled by SF, for example dummy-package-with-Capital-Letters
package_name = "Zendesk"
result = runner.invoke(
[
"snowpark",
"package",
"create",
package_name,
"--ignore-anaconda",
"--allow-shared-libraries",
]
)
assert result.exit_code == 0
zipfile = f"{package_name.lower()}.zip"
assert Path(zipfile).exists()
files = self._get_filenames_from_zip(zipfile)
assert any(
file.startswith(package_name) and file.endswith("dist-info/")
for file in files
)

@pytest.mark.integration
@pytest.mark.integration
def test_incorrect_input(self, runner):
from packaging.requirements import InvalidRequirement
Expand Down

0 comments on commit 9059144

Please sign in to comment.