## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 12;
    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 can generate PDF documentation as a substitute.
%bcond_without doc_pdf

Name:           python-geomdl
Version:        5.3.1
Release:        %autorelease
Summary:        Object-oriented pure Python B-Spline and NURBS library

# From docs/citing.rst:
#   * Source code is released under the terms of the MIT License
#   * Examples are released under the terms of the MIT License
#   * Documentation is released under the terms of CC BY 4.0
#
# The examples are maintained in a separate repository,
# https://github.com/orbingol/geomdl-examples, which is not packaged here.
#
# Documentation is confined to the -doc subpackage.
#
# SPDX
License:        MIT
URL:            https://onurraufbingol.com/NURBS-Python/
# The GitHub tarball has documentation; the PyPI one does not.
%global forgeurl https://github.com/orbingol/NURBS-Python
Source0:        %{forgeurl}/archive/v%{version}/NURBS-Python-%{version}.tar.gz

Patch:          geomdl-5.3.1-unconditional-Cython.patch

# Upstream uses something like “setup.py bdist_wheel --use-cython” to turn on
# the optional Cython-generated extensions. This doesn’t fit well with the
# pyproject-rpm-macros approach (which uses “pip wheel …”), so we just patch
# setup.py to unconditionally enable Cython.

BuildRequires:  python3-devel
BuildRequires:  gcc

# Upstream uses weird tox environments for testing:
#  https://github.com/orbingol/NURBS-Python/blob/v5.3.1/tox.ini#L5
# The default py3X environment fails with InterpreterNotFound:
#  https://github.com/orbingol/NURBS-Python/pull/145
# And even when everything works, the tox environment builds the extension again.
# It also measures coverage.
# Instead, we BuildRequire the only remaining tests dependency manually:
BuildRequires:  python3dist(pytest)


%if %{with doc_pdf}
BuildRequires:  make
BuildRequires:  python3dist(sphinx)
# We don’t need python3dist(sphinx-rtd-theme) since we aren’t building HTML.
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
# For sphinx.ext.inheritance_diagram:
BuildRequires:  graphviz
# For index
# BuildRequires:  /usr/bin/xindy
%endif

%global common_description %{expand:
NURBS-Python (geomdl) is a pure Python, self-contained, object-oriented
B-Spline and NURBS spline library for Python versions 2.7.x, 3.4.x and later.

NURBS-Python (geomdl) provides convenient data structures and highly
customizable API for rational and non-rational splines along with the efficient
and extensible implementations of the following algorithms:

  • Spline evaluation
  • Derivative evaluation
  • Knot insertion
  • Knot removal
  • Knot vector refinement
  • Degree elevation
  • Degree reduction
  • Curve and surface fitting via interpolation and least squares approximation

NURBS-Python (geomdl) also provides customizable visualization and animation
options via Matplotlib, Plotly and VTK libraries. Please refer to the
documentation (http://nurbs-python.readthedocs.io/) for more details.}

%description %{common_description}


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

Suggests:       python3-geomdl-doc = %{version}-%{release}

%description -n python3-geomdl %{common_description}


%package        doc
Summary:        Documentation for geomdl
# See the comment above the base package License field.
License:        CC-BY-4.0

BuildArch:      noarch

%description    doc %{common_description}


%prep
%autosetup -n NURBS-Python-%{version} -p1
# Allow newer versions in cases where exact versions are pinned.
sed -r -i 's/==/>=/' 'requirements.txt'


%generate_buildrequires
%pyproject_buildrequires requirements.txt


%build
%pyproject_wheel

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


%install
%pyproject_install
%pyproject_save_files geomdl


%check
%pytest


%files -n python3-geomdl -f %{pyproject_files}
# pyproject-rpm-macros handles the LICENSE file—verify with “rpm -qL -p …”—but
# we also use an explicit “%%license LICENSE” because we want it in
# %%{_licensedir} alongside citing.rst
%license LICENSE docs/citing.rst


%files doc
%license LICENSE docs/citing.rst
%doc CHANGELOG.md
%doc CONTRIBUTING.md
%doc CONTRIBUTORS.rst
%doc DESCRIPTION.rst
%doc README.rst
%if %{with doc_pdf}
%doc docs/_build/latex/NURBS-Python.pdf
%endif


%changelog
* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> 5.3.1-12
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Dec 09 2022 Miro Hrončok <miro@hroncok.cz> 5.3.1-11
- Drop the remaining usage of tox for generating BuildRequires

* Fri Dec 09 2022 Benjamin A. Beasley <code@musicinmybrain.net> 5.3.1-10
- Trivial spec file typo fix

* Fri Dec 09 2022 Miro Hrončok <miro@hroncok.cz> 5.3.1-9
- Fix running tests in %%check

* Sat Oct 22 2022 Benjamin A. Beasley <code@musicinmybrain.net> 5.3.1-8
- Update License to SPDX

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

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

* Wed Apr 20 2022 Benjamin A. Beasley <code@musicinmybrain.net> 5.3.1-5
- Build LaTeX more quietly

* Wed Apr 20 2022 Benjamin A. Beasley <code@musicinmybrain.net> 5.3.1-4
- Drop “forge” macros, which aren’t doing much for us

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

* Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> 5.3.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Thu Jan 06 2022 Benjamin A. Beasley <code@musicinmybrain.net> 5.3.1-1
- Initial package (close RHBZ#2016661)