## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 4;
    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

# Sphinx-generated HTML documentation is not suitable for packaging; see
# https://bugzilla.redhat.com/show_bug.cgi?id=2006555 for discussion.
#
# We generate PDF documentation as a substitute.
%bcond doc_pdf 1

Name:           python-cyipopt
Version:        1.5.0
Release:        %autorelease
Summary:        Cython interface for the interior point optimizer IPOPT

# The entire source is EPL-2.0.
#
# The GitHub project contains one file that is BSD-3-Clause:
#   - cyipopt/tests/unit/test_scipy_ipopt_from_scipy.py
# but this is excluded from the PyPI sdist.
License:        EPL-2.0
URL:            https://github.com/mechmotum/cyipopt
Source:         %{pypi_source cyipopt}

# https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval
ExcludeArch:    %{ix86}

BuildRequires:  python3-devel
BuildRequires:  tomcli

BuildRequires:  pkgconfig(ipopt) >= 3.12
# Called from setup.py:
BuildRequires:  /usr/bin/pkg-config

BuildRequires:  %{py3_dist pytest}
# Scipy is an optional dependency. Installing it allows testing the scipy
# integration.
BuildRequires:  %{py3_dist scipy} >= 1.8

BuildRequires:  gcc

%if %{with doc_pdf}
# Add examples/ and docs/requirements.txt to source distribution
# https://github.com/mechmotum/cyipopt/pull/242
# numpydoc>=1.2
BuildRequires:  %{py3_dist numpydoc} >= 1.2
# sphinx>=4.3.2
BuildRequires:  %{py3_dist sphinx} >= 4.3.2

BuildRequires:  make
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
BuildRequires:  tex(morefloats.sty)
%endif

%global common_description %{expand:
Ipopt (Interior Point OPTimizer, pronounced eye-pea-opt) is a software package
for large-scale nonlinear optimization. Ipopt is available from the COIN-OR
initiative, under the Eclipse Public License (EPL).

cyipopt is a Python wrapper around Ipopt. It enables using Ipopt from the
comfort of the Python programming language.}

%description %{common_description}


%package -n python3-cyipopt
Summary:        %{summary}

# From README.rst:
#
#   As of version 1.1.0 (2021-09-07), the distribution is released under the
#   name "cyipopt" on PyPi (https://pypi.org/project/cyipopt). Before version
#   1.1.0, it was released under the name "ipopt"
#   (https://pypi.org/project/ipopt).
#
# A compatibility shim is provided for the old package name.
%py_provides python3-ipopt
# Furthermore, the extension module is installed at the top level as
# “ipopt_wrapper”.
%py_provides python3-ipopt_wrapper

%description -n python3-cyipopt %{common_description}


%package -n python3-cyipopt-tests
Summary:        Tests for cyipopt

Requires:       python3-cyipopt = %{version}-%{release}
Requires:       %{py3_dist pytest}
Recommends:     %{py3_dist scipy} >= 1.8

%description -n python3-cyipopt-tests
This provides the “cyipopt.tests” subpackage.


%package doc
Summary:        Documentation for cyipopt

BuildArch:      noarch

%description doc %{common_description}


%prep
%autosetup -n cyipopt-%{version} -p1

# Replace zero-length files in the tests with proper empty text files, i.e.,
# just a newline. It makes sense for __init__.py files to be empty, but the
# empty test files look like a mistake, so an upstream issue was filed:
# https://github.com/mechmotum/cyipopt/issues/135
echo '' | tee $(find cyipopt/tests -type f -name '*.py' -size 0 | tr '\n' ' ')

%if %{with doc_pdf}
# Avoid:
#   ! LaTeX Error: Too deeply nested.
echo 'latex_elements["preamble"] = r"\usepackage{enumitem}\setlistdepth{99}"' \
    >> docs/source/conf.py
%endif


%generate_buildrequires
%pyproject_buildrequires


%build
%pyproject_wheel

%if %{with doc_pdf}
BLIB="${PWD}/build/lib.%{python3_platform}-cpython-%{python3_version_nodots}"
PYTHONPATH="${BLIB}" %make_build -C docs latex \
    SPHINXOPTS='-j%{?_smp_build_ncpus}'
%make_build -C docs/build/latex LATEXMKOPTS='-quiet'
%endif


%install
%pyproject_install
%pyproject_save_files -l cyipopt ipopt ipopt_wrapper


%check
%ifarch %{power64} s390x
# Arch-dependent failures of test_minimize_ipopt_jac_with_scipy_methods[cobyla]
# https://github.com/mechmotum/cyipopt/issues/237
k="${k-}${k+ and }not test_minimize_ipopt_jac_with_scipy_methods[cobyla]"
%endif

%pytest -v -rsx -k "${k-}"


%files -n python3-cyipopt -f %{pyproject_files}
%exclude %{python3_sitearch}/cyipopt/tests/


%files -n python3-cyipopt-tests
%{python3_sitearch}/cyipopt/tests/


%files doc
%license LICENSE
%doc CHANGELOG.rst
%doc README.rst
%if %{with doc_pdf}
%doc docs/build/latex/cyipopt.pdf
%endif


%changelog
## START: Generated by rpmautospec
* Wed Mar 05 2025 Benjamin A. Beasley <code@musicinmybrain.net> - 1.5.0-4
- Use %%{power64} macro for ppc64le arch. conditional

* Sat Jan 18 2025 Fedora Release Engineering <releng@fedoraproject.org> - 1.5.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild

* Mon Dec 23 2024 Sandro <devel@penguinpee.nl> - 1.5.0-2
- Rebuild for NumPy 2.x

* Sun Sep 08 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.5.0-1
- Update to 1.5.0 (close RHBZ#2310715)

* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.4.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

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

* Tue Apr 02 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.4.1-1
- Update to 1.4.1 (close RHBZ#2272705)

* Mon Apr 01 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.4.0-1
- Update to 1.4.0 (close RHBZ#2272492)

* Fri Feb 23 2024 Jerry James <loganjerry@gmail.com> - 1.3.0-10
- Rebuild for coin-or-Ipopt 3.14.14

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

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

* Sun Dec 17 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.3.0-7
- Assert that %%pyproject_files contains a license file

* Sun Nov 26 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.3.0-6
- Actually switch the source tarball to the PyPI sdist
- Handle docs/requirements.txt not appearing in the sdist

* Sun Nov 26 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.3.0-5
- Switch from the GitHub archive to the PyPI sdist

* Sun Nov 26 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.3.0-4
- Stop testing and packaging examples

* Sat Nov 04 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.3.0-3
- Patch for Cython 3

* Sat Nov 04 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.3.0-2
- F40+: Split tests into their own subpackage

* Sat Nov 04 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.3.0-1
- Update to 1.3.0 (close RHBZ#2240348)

* Wed Oct 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.2.0-2
- Use %%{py3_test_envvars} to run examples

* Sun Jul 23 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.2.0-1
- Update to 1.2.0

* Sun Jul 23 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-20
- Drop Cython/setuptools runtime dependencies as a *downstream* patch

* Fri Jul 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-19
- Follow upstreaming in restoring the runtime Cython dependency

* Thu Jul 20 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-18
- Upsteamed Cython<3 pin
- Dropped Cython from runtime dependencies

* Thu Jul 20 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-17
- Use Cython compat package until Cython 3 compatibility is fixed

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

* Tue Jun 20 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-15
- Use new (rpm 4.17.1+) bcond style

* Sat Jun 03 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-14
- Remove explicit %%set_build_flags, not needed since F36

* Fri Mar 17 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-12
- Don’t assume %%_smp_mflags is -j%%_smp_build_ncpus

* Wed Mar 08 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-11
- Drop %%pyproject_build_lib (F37+)

* Wed Mar 08 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-10
- Don’t use deprecated/removed np.float alias

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

* Wed Dec 21 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-8
- Leaf package: remove i686 support

* Wed Dec 21 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-7
- Indicate dirs. in files list with trailing slashes

* Wed Nov 30 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-6
- Drop default -r argument to pyproject_buildrequires

* Fri Oct 21 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-5
- Confirm License is SPDX EPL-1.0

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Wed Jun 15 2022 Python Maint <python-maint@redhat.com> - 1.1.0-3
- Rebuilt for Python 3.11

* Wed Apr 20 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-2
- Stop numbering patches

* Wed Feb 02 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-1
- Initial package (close RHBZ#2020886)
## END: Generated by rpmautospec