Raise an exception if there's no package name in metadata

That's an error state that can't be allowed to proceed further.
This commit is contained in:
Karolina Surma
2025-02-07 19:52:06 +01:00
parent e4795439e7
commit 1376e0ba49
2 changed files with 12 additions and 2 deletions
+6
View File
@@ -26,10 +26,16 @@ class SdistNotFoundError(Pyp2specError):
"""Raised when there's no sdist file in the PyPI metadata"""
class MissingPackageNameError(Pyp2specError):
"""Raised when there's no package name in the metadata"""
def normalize_name(package_name: str) -> str:
"""Normalize given package name as defined in PEP 503.
The resulting string better conforms with Fedora's Packaging Guidelines."""
if not package_name:
raise MissingPackageNameError("Cannot create a package without a name")
return re.sub(r"[-_.]+", "-", package_name).lower()
+6 -2
View File
@@ -3,7 +3,7 @@ import pytest
from pyp2spec.utils import filter_license_classifiers, prepend_name_with_python
from pyp2spec.utils import normalize_name, get_extras, is_archful
from pyp2spec.utils import normalize_as_wheel_name, archive_name
from pyp2spec.utils import resolve_url, SdistNotFoundError
from pyp2spec.utils import resolve_url, SdistNotFoundError, MissingPackageNameError
def test_license_classifier_read_correctly():
@@ -122,13 +122,17 @@ def test_archfulness_is_detected_from_multiple_urls_3():
("my.package", "my_package"),
("my_package-", "my_package_"),
("noweirdchars", "noweirdchars"),
("", ""),
]
)
def test_normalize_as_wheel_name(name, expected):
assert normalize_as_wheel_name(name) == expected
def test_empty_package_name_results_in_exception():
with pytest.raises(MissingPackageNameError):
normalize_as_wheel_name("")
def test_archive_name_valid():
archive_urls = [
{