Move the name normalizing functions to utils

They are used in both scripts.
This commit is contained in:
Karolina Surma
2024-10-22 19:08:24 +02:00
parent 99fc8ca32f
commit 59b51e13f5
3 changed files with 21 additions and 13 deletions
+2 -6
View File
@@ -12,7 +12,7 @@ except ImportError:
from jinja2 import Template
from pyp2spec.rpmversion import RpmVersion
from pyp2spec.utils import Pyp2specError
from pyp2spec.utils import Pyp2specError, normalize_as_wheel_name
TEMPLATE_FILENAME = "template.spec"
@@ -104,11 +104,7 @@ def same_as_rpm(pypi_version):
def archive_name(config):
"""
PEP 625 specifies the sdist name to be normalized according to the wheel spec:
https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
"""
return config.get_string("pypi_name").replace("-", "_")
return normalize_as_wheel_name(config.get_string("pypi_name"))
def source(config, pypi_version):
+2 -7
View File
@@ -12,7 +12,7 @@ from packaging.requirements import Requirement
from pyp2spec.rpmversion import RpmVersion
from pyp2spec.license_processor import classifiers_to_spdx_identifiers
from pyp2spec.license_processor import license_keyword_to_spdx_identifiers, good_for_fedora
from pyp2spec.utils import Pyp2specError
from pyp2spec.utils import Pyp2specError, normalize
class SdistNotFoundError(Pyp2specError):
@@ -58,12 +58,7 @@ class PypiPackage:
The resulting string better conforms with Fedora's Packaging Guidelines.
"""
return self.normalize(self.pypi_package_data["info"]["name"])
def normalize(self, package_name):
"""Normalize given package name as defined in PEP 503"""
return re.sub(r"[-_.]+", "-", package_name).lower()
return normalize(self.pypi_package_data["info"]["name"])
def _get_from_url(self, url, error_str):
response = self._session.get(url)
+17
View File
@@ -1,2 +1,19 @@
import re
class Pyp2specError(Exception):
"""Metaexception to derive the custom errors from"""
def normalize(package_name):
"""Normalize given package name as defined in PEP 503"""
return re.sub(r"[-_.]+", "-", package_name).lower()
def normalize_as_wheel_name(package_name):
"""Normalize as in the wheel specification:
https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
PEP 625 specifies sdist names to this format."""
return normalize(package_name).replace("-", "_")