mirror of
https://github.com/danieldemus/pyp2spec.git
synced 2026-07-27 21:00:37 +02:00
Bring back the legacy sdist filename processing
(Effectively revert the removals done to implement PEP 625).
The removal was too haste and broke the users.
This reverts commit 9747b76c4f
and builds on top of the changes in between.
This commit is contained in:
@@ -119,6 +119,7 @@ Configuration data is stored in a TOML file.
|
||||
| python_alt_version | specific Python version to create the spec file for, e.g. 3.9, 3.10, 3.12 | string |
|
||||
| automode | create buildable spec files that don't have to fully comply with Fedora Guidelines; useful for automatic build environments | bool |
|
||||
| license_files_present | `License-File` field was detected in the package metadata | bool |
|
||||
| archive_name | filename of the sdist | string |
|
||||
|
||||
|
||||
### Example config file generated by pyp2spec
|
||||
@@ -134,6 +135,7 @@ url = "https://github.com/bachya/aionotion"
|
||||
source = "PyPI"
|
||||
extras = []
|
||||
license_files_present = true
|
||||
archive_name = "aionotion-2.0.3.tar.gz"
|
||||
```
|
||||
|
||||
### Spec file generated using the example config
|
||||
|
||||
+38
-10
@@ -103,8 +103,31 @@ def same_as_rpm(pypi_version):
|
||||
return pypi_version == convert_version_to_rpm_scheme(pypi_version)
|
||||
|
||||
|
||||
def archive_name(config):
|
||||
return normalize_as_wheel_name(config.get_string("pypi_name"))
|
||||
def archive_basename(config, pypi_version):
|
||||
"""Return the archive basename.
|
||||
|
||||
The filename has been standardized in PEP 625, but many projects out there
|
||||
use the legacy, pre-standard, custom naming. Extract the basename the same
|
||||
way it's spelled in the archive name.
|
||||
|
||||
Example: "My-package_Archive-1.0.4-12.tar.gz" -> "My-package_Archive"
|
||||
"""
|
||||
filename = config.get_string("archive_name")
|
||||
|
||||
# First, strip the suffix
|
||||
for suffix in (".tar.gz", ".zip"):
|
||||
filename = filename.removesuffix(suffix)
|
||||
# Second, get rid of the version string and the delimiter "-"
|
||||
return filename.replace("-" + pypi_version, "")
|
||||
|
||||
|
||||
def is_zip(config):
|
||||
"""
|
||||
The archive format standardized in PEP 625 is tar.gz,
|
||||
however some projects still use the legacy zip.
|
||||
If so, it has to be explicitly declared as an argument of %{pypi_source}.
|
||||
"""
|
||||
return config.get_string("archive_name").endswith(".zip")
|
||||
|
||||
|
||||
def source(config, pypi_version):
|
||||
@@ -114,16 +137,21 @@ def source(config, pypi_version):
|
||||
<name>, <version> and <file_extension>.
|
||||
<name> is always passed: "%{pypi_source foo}".
|
||||
<version> is passed if PyPI's and RPM's version strings differ:
|
||||
"%{pypi_source foo 1.2-3}". If they're the same, version is not passed.
|
||||
Since PEP 625, the required file extension for sdists is `tar.gz`,
|
||||
which is the default <file_extension> accepted by the macro, hence
|
||||
we don't have to define it here.
|
||||
"%{pypi_source foo 1.2-3}". If they're the same and the file extension
|
||||
is not zip, version is not passed.
|
||||
If archive is a zip file, %{pypi_source} must take all three args:
|
||||
"%{pypi_source foo %{version} zip}", "{pypi_source foo 1.2-3 zip}"
|
||||
"""
|
||||
if config.get_string("source") == "PyPI":
|
||||
source_macro_args = archive_name(config)
|
||||
version_str = pypi_version_or_macro(pypi_version)
|
||||
basename = archive_basename(config, pypi_version)
|
||||
source_macro_args = basename
|
||||
|
||||
if not same_as_rpm(pypi_version):
|
||||
source_macro_args += f" {pypi_version}"
|
||||
if is_zip(config):
|
||||
source_macro_args += f" {version_str} zip"
|
||||
else:
|
||||
if version_str == pypi_version:
|
||||
source_macro_args += f" {version_str}"
|
||||
return "%{pypi_source " + source_macro_args + "}"
|
||||
|
||||
|
||||
@@ -146,7 +174,7 @@ def fill_in_template(config):
|
||||
result = spec_template.render(
|
||||
additional_build_requires=list_additional_build_requires(config),
|
||||
archful=config.get_bool("archful"),
|
||||
archive_name=archive_name(config),
|
||||
archive_name=archive_basename(config, pypi_version),
|
||||
automode=config.get_bool("automode"),
|
||||
extras=",".join(config.get_list("extras")),
|
||||
license=license,
|
||||
|
||||
+11
-1
@@ -50,7 +50,6 @@ class PypiPackage:
|
||||
# meaning we jump to the other sources package metadata data (eg. PyPI)
|
||||
self.pypi_package_data = pypi_package_data or self._get_pypi_package_version_data()
|
||||
self.core_metadata = core_metadata or self.parse_core_metadata()
|
||||
self.sdist_filename = None
|
||||
|
||||
@property
|
||||
def pypi_name(self):
|
||||
@@ -229,6 +228,16 @@ class PypiPackage:
|
||||
# all of the found wheel names had 'none' as abi_tag
|
||||
return False
|
||||
|
||||
def archive_name(self):
|
||||
"""Return the given's package version sdist name for further processing.
|
||||
Quit the script if not found (bdists can't be processed).
|
||||
"""
|
||||
for entry in self.pypi_package_data["urls"]:
|
||||
if entry["packagetype"] == "sdist":
|
||||
return entry["filename"]
|
||||
raise SdistNotFoundError("sdist not found.")
|
||||
|
||||
|
||||
def extras(self):
|
||||
"""Return the sorted list of the found extras names.
|
||||
|
||||
@@ -309,6 +318,7 @@ def create_config_contents(
|
||||
contents["python_name"] = pkg.python_name(python_alt_version=python_alt_version)
|
||||
contents["url"] = pkg.project_url()
|
||||
contents["source"] = "PyPI"
|
||||
contents["archive_name"] = pkg.archive_name()
|
||||
contents["extras"] = pkg.extras()
|
||||
contents["license_files_present"] = pkg.are_license_files_included()
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Summary: Python port of markdown-it
|
||||
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
|
||||
License: MIT
|
||||
URL: https://github.com/executablebooks/markdown-it-py
|
||||
Source: %{pypi_source markdown_it_py}
|
||||
Source: %{pypi_source markdown-it-py}
|
||||
|
||||
BuildArch: noarch
|
||||
BuildRequires: python3-devel
|
||||
@@ -27,7 +27,7 @@ Summary: %{summary}
|
||||
|
||||
|
||||
%prep
|
||||
%autosetup -p1 -n markdown_it_py-%{version}
|
||||
%autosetup -p1 -n markdown-it-py-%{version}
|
||||
|
||||
|
||||
%generate_buildrequires
|
||||
|
||||
@@ -10,7 +10,7 @@ Summary: An example Python Hello World package
|
||||
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
|
||||
License: MIT-0
|
||||
URL: https://github.com/fedora-python/Pello
|
||||
Source: %{pypi_source pello}
|
||||
Source: %{pypi_source Pello}
|
||||
|
||||
BuildArch: noarch
|
||||
BuildRequires: python%{python3_pkgversion}-devel
|
||||
@@ -29,7 +29,7 @@ This is package 'pello' generated automatically by pyp2spec.}
|
||||
|
||||
|
||||
%prep
|
||||
%autosetup -p1 -n pello-%{version}
|
||||
%autosetup -p1 -n Pello-%{version}
|
||||
|
||||
|
||||
%generate_buildrequires
|
||||
|
||||
+7
-19
@@ -131,27 +131,15 @@ def test_license_strings():
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("pypi_name", "expected"), [
|
||||
("awesome-pkg", "awesome_pkg"),
|
||||
("pkg_with_underscores-and-hyphens", "pkg_with_underscores_and_hyphens"),
|
||||
("pkg", "pkg"),
|
||||
("version", "extension", "expected"), [
|
||||
("1.2", "tar.gz", "%{pypi_source foo}"),
|
||||
("1.2", "zip", "%{pypi_source foo %{version} zip}"),
|
||||
("1.2-3", "tar.gz", "%{pypi_source foo 1.2-3}"),
|
||||
("0.0.2-beta1", "zip", "%{pypi_source foo 0.0.2-beta1 zip}"),
|
||||
]
|
||||
)
|
||||
def test_archive_names_normalized(pypi_name, expected):
|
||||
fake_config_data = {"pypi_name": pypi_name}
|
||||
fake_config = conf2spec.ConfigFile(fake_config_data)
|
||||
assert conf2spec.archive_name(fake_config) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("version", "expected"), [
|
||||
("1.2", "%{pypi_source foo}"),
|
||||
("1.2-3", "%{pypi_source foo 1.2-3}"),
|
||||
("0.0.2-beta1", "%{pypi_source foo 0.0.2-beta1}"),
|
||||
]
|
||||
)
|
||||
def test_source(version, expected):
|
||||
fake_config_data = {"pypi_name": "foo", "source": "PyPI"}
|
||||
def test_source(version, extension, expected):
|
||||
fake_config_data = {"pypi_name": "foo", "archive_name": f"foo-{version}.{extension}", "source": "PyPI"}
|
||||
fake_config = conf2spec.ConfigFile(fake_config_data)
|
||||
assert conf2spec.source(fake_config, version) == expected
|
||||
|
||||
|
||||
@@ -8,4 +8,5 @@ source = "PyPI"
|
||||
extras = []
|
||||
archful = false
|
||||
automode = true
|
||||
license_files_present = false
|
||||
license_files_present = false
|
||||
archive_name = "aionotion-2.0.3.tar.gz"
|
||||
|
||||
@@ -6,4 +6,5 @@ license = "MIT"
|
||||
url = "https://github.com/executablebooks/markdown-it-py"
|
||||
source = "PyPI"
|
||||
# customized: automode on
|
||||
automode = true
|
||||
automode = true
|
||||
archive_name = "markdown-it-py-1.1.0.tar.gz"
|
||||
|
||||
@@ -11,3 +11,4 @@ extras = [
|
||||
]
|
||||
archful = false
|
||||
license_files_present = false
|
||||
archive_name = "sphinx-8.1.0.tar.gz"
|
||||
|
||||
@@ -7,4 +7,5 @@ url = "https://github.com/bachya/aionotion"
|
||||
source = "PyPI"
|
||||
extras = []
|
||||
archful = false
|
||||
license_files_present = false
|
||||
license_files_present = false
|
||||
archive_name = "aionotion-2.0.3.tar.gz"
|
||||
|
||||
@@ -7,4 +7,5 @@ url = "https://palletsprojects.com/p/click/"
|
||||
source = "PyPI"
|
||||
extras = []
|
||||
archful = false
|
||||
license_files_present = true
|
||||
license_files_present = true
|
||||
archive_name = "click-8.1.7.tar.gz"
|
||||
|
||||
@@ -9,3 +9,4 @@ source = "PyPI"
|
||||
automode = true
|
||||
extras = []
|
||||
license_files_present = true
|
||||
archive_name = "numpy-1.25.2.tar.gz"
|
||||
|
||||
@@ -10,4 +10,5 @@ source = "PyPI"
|
||||
extras = [
|
||||
"color",
|
||||
]
|
||||
license_files_present = true
|
||||
license_files_present = true
|
||||
archive_name = "Pello-1.0.4.tar.gz"
|
||||
|
||||
Reference in New Issue
Block a user