File python-py2pack.spec of Package python-py2pack
%define pypi_name py2pack
Name: python-%{pypi_name}
Version: 0.9.3
Release: 1
Summary: Generate distribution packages from PyPI
# Check if the automatically generated License and its spelling is correct for Fedora
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
License: GPLv3
URL: https://github.com/openSUSE/py2pack
Source: %{pypi_name}-%{version}.tar.gz
BuildArch: noarch
BuildRequires: python3-devel
%if %{defined suse_version}
BuildRequires: python-rpm-macros
BuildRequires: %{python_module hatchling}
BuildRequires: %{python_module pip}
# SECTION test requirements
# /SECTION
BuildRequires: fdupes
Requires: python-backports.entry_points_selectable
Requires: python-Jinja2
Requires: python-metaextract
Requires: python-platformdirs
Requires: python-packaging
Requires: python-requests
Requires: python-setuptools
%else
%define python_subpackages BuildRequires: python3-devel
%endif
%python_subpackages
# Fill in the actual package description to submit package to Fedora
%global _description %{expand:
This is package 'py2pack' generated automatically by pyp2spec.}
%description
%if %{defined suse_version}
%package -n py2pack-templates-directory
Summary: Template directory for py2pack
%description -n py2pack-templates-directory
Template directory for py2pack.
%else
%package -n python3-py2pack
Summary: %{summary}
%description -n python3-py2pack %_description
%endif
%prep
%autosetup -p1 -n %{pypi_name}-%{version}
%if %{defined fedora}
sed -i 's~opensuse.spec~fedora.spec~' py2pack/__init__.py
%generate_buildrequires
%pyproject_buildrequires
%endif
cat << 'EOF' | python3
path = 'py2pack/__init__.py'
with open(path, 'r') as r:
text = r.read()
with open(path, 'w') as w:
w.write(text.replace("os.path.join('/', 'usr', 'share', 'py2pack', 'templates')", "'%{_py2pack_templates}'"))
EOF
%build
%pyproject_wheel
%install
%pyproject_install
# For official Fedora packages, including files with '*' +auto is not allowed
# Replace it with a list of relevant Python modules/globs and list extra files in %%files
%if %{defined suse_version}
%python_clone -a %{buildroot}%{_bindir}/py2pack
%python_expand %fdupes %{buildroot}%{$python_sitelib}
mkdir -p %{buildroot}%{_datadir}/py2pack/templates
mkdir -p %{buildroot}%{_rpmconfigdir}/macros.d
cat<< 'EOF' > %{buildroot}%{_rpmconfigdir}/macros.d/macros.py2pack
%%_py2pack_templates %%{_datadir}/py2pack/templates
EOF
%post
%python_install_alternative py2pack
%postun
%python_uninstall_alternative py2pack
%files %{python_files}
%doc README.rst
%license LICENSE
%python_alternative %{_bindir}/py2pack
%{python_sitelib}/py2pack
%{python_sitelib}/py2pack-%{version}.dist-info
%files -n py2pack-templates-directory
%dir %{_rpmconfigdir}/macros.d
%{_rpmconfigdir}/macros.d/macros.py2pack
%dir %{_datadir}/py2pack
%dir %{_datadir}/py2pack/templates
%else
%pyproject_save_files '*' +auto
%files -n python3-py2pack -f %{pyproject_files}
%endif