diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index e8a3fc702..c9c3fde0d 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -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 diff --git a/src/snowflake/cli/_plugins/snowpark/models.py b/src/snowflake/cli/_plugins/snowpark/models.py index 2a48c55ff..a30aeae05 100644 --- a/src/snowflake/cli/_plugins/snowpark/models.py +++ b/src/snowflake/cli/_plugins/snowpark/models.py @@ -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: diff --git a/tests/snowpark/test_models.py b/tests/snowpark/test_models.py index b8dcbae2e..c1e847398 100644 --- a/tests/snowpark/test_models.py +++ b/tests/snowpark/test_models.py @@ -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( @@ -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"] diff --git a/tests_integration/test_package.py b/tests_integration/test_package.py index 18afcc18e..39022ec15 100644 --- a/tests_integration/test_package.py +++ b/tests_integration/test_package.py @@ -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