## START: Set by rpmautospec
## (rpmautospec version 0.6.0)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 9;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global desc %{expand: \
A collection of Benchmark functions for numerical optimization problems.

Current information can always be found from the repository - https://github.com/thieu1995/opfunu}

# enable when new Sphinx stack is available on all platforms
%bcond_with docs

%bcond_without tests

%global forgeurl https://github.com/thieu1995/opfunu

Name:           python-opfunu
Version:        1.0.0
Release:        %autorelease
Summary:        Benchmark functions for numerical optimization problems

%forgemeta

License:        GPL-3.0-only
URL:            https://github.com/thieu1995/opfunu
Source0:        %forgesource

# This patch is intended not to package tests.
# It was not submitted to the upstream since this is optional
# for the upstream to apply this.
Patch:          0001-do-not-package-tests-examples.patch
# Do not import numpy.int, which was deprecated and removed
# https://github.com/thieu1995/opfunu/pull/12
Patch:          %{url}/pull/12.patch

BuildArch:      noarch

%description
%{desc}

%package -n python3-opfunu
Summary:        %{summary}
BuildRequires:      python3-devel
BuildRequires:      %{py3_dist requests}

%if %{with tests}
BuildRequires:      %{py3_dist pytest}
%endif

%if %{with docs}
BuildRequires:  make
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
BuildRequires:  %{py3_dist sphinx}
BuildRequires:  %{py3_dist sphinx-rtd-theme}
%endif

# scipy, Pillow, requests and pandas are missing in setup file
BuildRequires: %{py3_dist scipy}
BuildRequires: %{py3_dist Pillow}
BuildRequires: %{py3_dist pandas}
Requires:      %{py3_dist Pillow}
Requires:      %{py3_dist pandas}
Requires:      %{py3_dist requests}
Requires:      %{py3_dist scipy}
BuildRequires:  hardlink

%description -n python3-opfunu
%{desc}

%package doc
BuildArch:      noarch
Summary:        %{summary}

%description doc
Documentation for %{name}.

%prep
%forgeautosetup -p1

# Adjust shebangs and executable permissions
# https://github.com/thieu1995/opfunu/pull/9
find examples -type f -name '*.py' ! -name '__init__.py' \
    -execdir chmod +x '{}' '+'
find opfunu tests -type f -name '*.py' \
    -execdir sed -r -i '1{/^#!/d}' '{}' '+'

%py3_shebang_fix examples

%generate_buildrequires
%pyproject_buildrequires -r

%build
%pyproject_wheel

%if %{with docs}
%make_build -C docs latex SPHINXOPTS='%{?_smp_mflags}'
%make_build -C docs/_build/latex LATEXMKOPTS='-quiet'
%endif

%install
%pyproject_install
%pyproject_save_files opfunu

hardlink '%{buildroot}%{python3_sitelib}/opfunu'

%check

%if %{with tests}
%pytest
%endif

%files -n python3-opfunu -f %{pyproject_files}
%doc README.md ChangeLog.md
%doc examples/

%files doc
%license LICENSE
%doc CODE_OF_CONDUCT.md
%if %{with docs}
%doc docs/_build/latex/opfunu.pdf
%endif

%changelog
## START: Generated by rpmautospec
* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.0-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Sat Jun 08 2024 Python Maint <python-maint@redhat.com> - 1.0.0-8
- Rebuilt for Python 3.13

* Fri Jan 26 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.0-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Jan 22 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Wed Jun 28 2023 Python Maint <python-maint@redhat.com> - 1.0.0-4
- Rebuilt for Python 3.12

* Sat Feb 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.0.0-3
- Do not import numpy.int, which was deprecated and removed

* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Nov 25 2022 Iztok Fister Jr <iztok@iztok-jr-fister.eu> - 1.0.0-1
- Initial import (fedora#2123760).
## END: Generated by rpmautospec