%global python3_pkgversion 3.11
Name:           python-pyproject-api
Version:        1.5.0
Release:        3.ac%{?dist}
Summary:        API to interact with the python pyproject.toml based projects

License:        MIT
URL:            https://pyproject-api.readthedocs.org
Source0:        https://files.pythonhosted.org/packages/source/p/pyproject-api/pyproject_api-%{version}.tar.gz
BuildArch:      noarch

BuildRequires:  python%{python3_pkgversion}-devel
BuildRequires:  pyproject-rpm-macros

%global _description %{expand:
API to interact with the python pyproject.toml based projects.}

%description %_description

%package -n     python%{python3_pkgversion}-pyproject-api
Summary:        %{summary}

%description -n python%{python3_pkgversion}-pyproject-api %_description

%prep
%autosetup -n pyproject_api-%{version}
# Remove unneeded testing deps
sed -i "/covdefaults/d;/pytest-cov/d" pyproject.toml

%generate_buildrequires
%pyproject_buildrequires -w -x testing

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files pyproject_api

for b in $(find %{buildroot}%{_bindir}/ -type f) ; do mv "$b" $(sed -re "s/(.*)?)$/\1%{python3_pkgversion}/"<<<"$m"); done
for m in $(find %{buildroot}%{_mandir}/ -type f) ; do mv "$m" $(sed -re "s/(.*).([1-8]([^.]+)?)$/\1%{python3_pkgversion}.\2/"<<<"$m"); done
for m in $(find %{buildroot}%{_datadir}/locale/* -type f) ; do mv "$m" $(sed -re "s/(.*).mo$/\1%{python3_pkgversion}.mo/"<<<"$m"); done
%check
# We don't want to depend on Python 2
%pytest -k "not test_can_build_on_python_2"

%files -n python%{python3_pkgversion}-pyproject-api -f %{pyproject_files}
%doc README.md

%changelog
* Thu Mar 21 2024 Ding-Yi Chen <dingyichen@gmail.com> -  1.5.0-3.ac
 - Bruteforce packaging