%global python3_pkgversion 3.11
%bcond tests %{undefined rhel}

Name:           python-fasteners
Version:        0.19
Release:        2.ac16.py3.11%{?dist}
Summary:        A python package that provides useful locks

License:        Apache-2.0
URL:            https://github.com/harlowja/fasteners
# We need to use the GitHub archive instead of the PyPI sdist to get tests.
Source:         %{url}/archive/%{version}/fasteners-%{version}.tar.gz

BuildArch:      noarch

BuildRequires:  python%{python3_pkgversion}-devel

%global common_description %{expand:
Cross platform locks for threads and processes}

%description %{common_description}


%package -n python%{python3_pkgversion}-fasteners
Summary:        A python package that provides useful locks

# The mkdocs-generated HTML documentation is not suitable for packaging; see
# https://bugzilla.redhat.com/show_bug.cgi?id=2006555 for discussion.
#
# The Provides/Obsoletes can be removed after F38 reaches end-of-life.
Provides:       python-fasteners-doc = %{version}-%{release}
Obsoletes:      python-fasteners-doc < 0.18-1

%description -n python%{python3_pkgversion}-fasteners %{common_description}


%prep
%autosetup -n fasteners-%{version}


%generate_buildrequires
%pyproject_buildrequires %{?with_tests:requirements-test.txt}


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files fasteners


%check
%if %{with tests}
%pytest -v
%else
%pyproject_check_import -e 'fasteners.pywin32*'
%endif


for b in $(find %{buildroot}%{_bindir}/ -type f) ; do mv "$b" $(sed -re "s|(.*)$|\1-%{python3_pkgversion}|"<<<"$b"); done
for m in $(find %{buildroot}%{_mandir}/ -type f) ; do mv "$m" $(sed -re "s|(.*).([1-8])(.*)$|\1-%{python3_pkgversion}.\2\3|"<<<"$m"); done
for m in $(find %{buildroot}%{_datadir}/locale/* -type f) ; do mv "$m" $(sed -re "s|(.*).mo$|\1-%{python3_pkgversion}.mo|"<<<"$m"); done
for l in $(find %{buildroot}/usr/lib64/lib* -type f -o -type l) ; do mv "$l" $(sed -re "s|(.*).so(.*)$|\1-py%{python3_pkgversion}.so\2|"<<<"$l"); done
for p in $(find %{buildroot}/usr/lib64/pkgconfig/* -type f) ; do mv "$p" $(sed -re "s|(.*).pc$|\1-py%{python3_pkgversion}.pc|"<<<"$p"); done
%files -n python%{python3_pkgversion}-fasteners -f %{pyproject_files}
%doc CHANGELOG.md
%doc README.md


%changelog
* Mon May 13 2024 Ding-Yi Chen <dingyichen@gmail.com> -  0.19-2.ac16.py3.11
 - Cut corner packaging