mirror of
https://github.com/danieldemus/pyp2spec.git
synced 2026-07-27 21:00:37 +02:00
Account with package names ending with digits
This commit is contained in:
committed by
Karolina Surma
parent
2cca4d3844
commit
3c6a738744
@@ -15,7 +15,7 @@ except ImportError:
|
||||
from jinja2 import Template
|
||||
|
||||
from pyp2spec.rpmversion import RpmVersion
|
||||
from pyp2spec.utils import Pyp2specError
|
||||
from pyp2spec.utils import Pyp2specError, create_compat_name
|
||||
from pyp2spec.utils import warn, yay
|
||||
|
||||
|
||||
@@ -183,12 +183,13 @@ def fill_in_template(config: ConfigFile) -> str:
|
||||
archive_name=archive_basename(config, pypi_version),
|
||||
automode=config.get_bool("automode"),
|
||||
compat=config.get_string("compat"),
|
||||
compat_name=create_compat_name(config.get_string("pypi_name"), config.get_string("compat")),
|
||||
extras=",".join(config.get_list("extras")),
|
||||
license=license,
|
||||
license_notice=license_notice,
|
||||
mandate_license=config.get_bool("license_files_present"),
|
||||
name=config.get_string("pypi_name"),
|
||||
python_name=config.get_string("python_name"),
|
||||
python_compat_name=create_compat_name(config.get_string("python_name"), config.get_string("compat")),
|
||||
pypi_version=pypi_version_or_macro(pypi_version),
|
||||
python_alt_version=config.get_string("python_alt_version"),
|
||||
source=source(config, pypi_version),
|
||||
@@ -208,9 +209,7 @@ def save_spec_file(config: ConfigFile, output: str | None) -> str:
|
||||
|
||||
result = fill_in_template(config)
|
||||
if output is None:
|
||||
output = config.get_string("python_name")
|
||||
if compat := config.get_string("compat"):
|
||||
output += compat
|
||||
output = create_compat_name(config.get_string("python_name"), config.get_string("compat"))
|
||||
output += ".spec"
|
||||
with open(output, "w", encoding="utf-8") as spec_file:
|
||||
spec_file.write(result)
|
||||
|
||||
@@ -11,7 +11,7 @@ from requests import Session
|
||||
from pyp2spec.license_processor import check_compliance, resolve_license_expression
|
||||
from pyp2spec.utils import Pyp2specError, normalize_name, get_extras, get_summary_or_placeholder
|
||||
from pyp2spec.utils import prepend_name_with_python, archive_name
|
||||
from pyp2spec.utils import is_archful, resolve_url
|
||||
from pyp2spec.utils import is_archful, resolve_url, create_compat_name
|
||||
from pyp2spec.utils import warn, caution, inform, yay
|
||||
from pyp2spec.pypi_loaders import load_from_pypi, load_core_metadata_from_pypi, CoreMetadataNotFoundError
|
||||
|
||||
@@ -159,10 +159,8 @@ def save_config(contents: dict, output: str | None = None) -> str:
|
||||
Return the saved file name.
|
||||
"""
|
||||
if not output:
|
||||
package = contents["python_name"]
|
||||
if compat := contents.get("compat"):
|
||||
package += compat
|
||||
output = f"{package}.conf"
|
||||
package_name = create_compat_name(contents.get("python_name"), contents.get("compat"))
|
||||
output = f"{package_name}.conf"
|
||||
with open(output, "wb") as f:
|
||||
tomli_w.dump(contents, f, multiline_strings=True)
|
||||
yay(f"Configuration file was saved successfully to '{output}'")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
%global python3_pkgversion {{ python_alt_version }}
|
||||
|
||||
{% endif -%}
|
||||
Name: {{python_name}}{{compat}}
|
||||
Name: {{python_compat_name}}
|
||||
Version: {{version}}
|
||||
Release: %autorelease
|
||||
# Fill in the actual package summary to submit package to Fedora
|
||||
@@ -27,7 +27,7 @@ This is package '{{name}}' generated automatically by pyp2spec.}
|
||||
%description %_description
|
||||
|
||||
{% if not python_alt_version -%}
|
||||
%package -n python{{python3_pkgversion}}-{{name}}{{compat}}
|
||||
%package -n python{{python3_pkgversion}}-{{compat_name}}
|
||||
Summary: %{summary}
|
||||
{% if compat %}
|
||||
Conflicts: python{{python3_pkgversion}}-{{name}}
|
||||
@@ -77,7 +77,7 @@ Provides: deprecated()
|
||||
{%- endif %}
|
||||
|
||||
|
||||
%files -n python{{python3_pkgversion}}-{{name}}{{compat}} -f %{pyproject_files}
|
||||
%files -n python{{python3_pkgversion}}-{{compat_name}} -f %{pyproject_files}
|
||||
|
||||
|
||||
%changelog
|
||||
|
||||
@@ -190,3 +190,11 @@ def resolve_url(urls: dict) -> str:
|
||||
if values_list := list(normalized_urls.values()):
|
||||
return values_list[0]
|
||||
return "..."
|
||||
|
||||
|
||||
def create_compat_name(name: str, compat: str | None) -> str:
|
||||
if not compat:
|
||||
return name
|
||||
if name[-1].isdigit():
|
||||
return f"{name}_{compat}"
|
||||
return f"{name}{compat}"
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
Name: python-urllib3_2
|
||||
Version: 2.3.0
|
||||
Release: %autorelease
|
||||
# Fill in the actual package summary to submit package to Fedora
|
||||
Summary: HTTP library with thread-safe connection pooling, file post, and more.
|
||||
|
||||
# Check if the automatically generated License and its spelling is correct for Fedora
|
||||
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
|
||||
License: MIT
|
||||
URL: https://github.com/urllib3/urllib3/blob/main/CHANGES.rst
|
||||
Source: %{pypi_source urllib3}
|
||||
|
||||
BuildArch: noarch
|
||||
BuildRequires: python3-devel
|
||||
|
||||
|
||||
# Fill in the actual package description to submit package to Fedora
|
||||
%global _description %{expand:
|
||||
This is package 'urllib3' generated automatically by pyp2spec.}
|
||||
|
||||
%description %_description
|
||||
|
||||
%package -n python3-urllib3_2
|
||||
Summary: %{summary}
|
||||
|
||||
Conflicts: python3-urllib3
|
||||
Provides: deprecated()
|
||||
|
||||
%description -n python3-urllib3 %_description
|
||||
|
||||
# For official Fedora packages, review which extras should be actually packaged
|
||||
# See: https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#Extras
|
||||
%pyproject_extras_subpkg -n python3-urllib3 brotli,h2,socks,zstd
|
||||
|
||||
|
||||
%prep
|
||||
%autosetup -p1 -n urllib3-%{version}
|
||||
|
||||
|
||||
%generate_buildrequires
|
||||
# Keep only those extras which you actually want to package or use during tests
|
||||
%pyproject_buildrequires -x brotli,h2,socks,zstd
|
||||
|
||||
|
||||
%build
|
||||
%pyproject_wheel
|
||||
|
||||
|
||||
%install
|
||||
%pyproject_install
|
||||
# Add top-level Python module names here as arguments, you can use globs
|
||||
%pyproject_save_files -l ...
|
||||
|
||||
|
||||
%check
|
||||
%pyproject_check_import
|
||||
|
||||
|
||||
%files -n python3-urllib3_2 -f %{pyproject_files}
|
||||
|
||||
|
||||
%changelog
|
||||
%autochangelog
|
||||
@@ -50,6 +50,7 @@ def test_archful_flag_is_loaded(config_dir, conf, expected):
|
||||
"default_python3.9-pello.conf", # custom Python version
|
||||
"default_python-pytest7.2.conf", # compat version
|
||||
"default_python-pytest7.conf", # compat version - lower granularity
|
||||
"default_python-urllib3_2.conf", # compat version - pkgname with a digit
|
||||
]
|
||||
)
|
||||
def test_default_generated_specfile(file_regression, config_dir, conf):
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
archful = false
|
||||
archive_name = "urllib3-2.3.0.tar.gz"
|
||||
compat = "2"
|
||||
extras = [
|
||||
"brotli",
|
||||
"h2",
|
||||
"socks",
|
||||
"zstd",
|
||||
]
|
||||
license = "MIT"
|
||||
license_files_present = true
|
||||
pypi_name = "urllib3"
|
||||
pypi_version = "2.3.0"
|
||||
python_name = "python-urllib3"
|
||||
source = "PyPI"
|
||||
summary = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||
url = "https://github.com/urllib3/urllib3/blob/main/CHANGES.rst"
|
||||
@@ -4,6 +4,7 @@ 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, MissingPackageNameError
|
||||
from pyp2spec.utils import create_compat_name
|
||||
|
||||
|
||||
def test_license_classifier_read_correctly():
|
||||
@@ -178,3 +179,15 @@ def test_project_urls_valid_multiple():
|
||||
|
||||
def test_project_urls_empty():
|
||||
assert resolve_url({}) == "..."
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("name", "compat", "expected"), [
|
||||
("my-package-foo", None, "my-package-foo"),
|
||||
("my-package-foo", "3.5", "my-package-foo3.5"),
|
||||
("my-package-foo2", None, "my-package-foo2"),
|
||||
("my-package-foo2", "3.5", "my-package-foo2_3.5"),
|
||||
]
|
||||
)
|
||||
def test_create_compat_name(name, compat, expected):
|
||||
assert create_compat_name(name, compat) == expected
|
||||
|
||||
Reference in New Issue
Block a user