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

# Building the documentation requires packages not available from Fedora:
# altair, coconut, sphinx-book-theme
%bcond doc 0

%global giturl  https://github.com/executablebooks/MyST-NB

Name:           myst-nb
Version:        1.2.0
Release:        %autorelease
Summary:        Jupyter Notebook Sphinx reader

License:        BSD-3-Clause
BuildArch:      noarch
URL:            https://myst-nb.readthedocs.io/
VCS:            git:%{giturl}.git
Source:         %{giturl}/archive/v%{version}/%{name}-%{version}.tar.gz
# Ignore deprecation warnings from python-jupyter-core
Patch:          %{name}-jupyter-core-deprecation.patch

BuildRequires:  help2man
BuildRequires:  python3-devel

%if %{with doc}
BuildRequires:  make
%endif

%py_provides python3-%{name}
%py_provides python3-MyST-NB

%description
MyST is a rich and extensible flavor of Markdown meant for technical
documentation and publishing.  It is designed for simplicity, flexibility, and
extensibility.  This package contains a reference implementation of MyST
Markdown, as well as a collection of tools to support working with MyST in
Python and Sphinx.  It contains an extended CommonMark-compliant parser using
markdown-it-py, as well as a Sphinx extension that allows you to write MyST
Markdown in Sphinx.

%if %{with doc}
%package        doc
Summary:        Documentation for %{name}

%description    doc
Documentation for %{name}.
%endif

%prep
%autosetup -n MyST-NB-%{version} -p1

%generate_buildrequires
# Permit newer versions of matplotlib for testing only.  The newer version of
# matplotlib causes some changes in test output; pyproject.toml says:
#   Matplotlib outputs are sensitive to the matplotlib version
sed -i 's/==\([*.[:digit:]]*\)//' pyproject.toml
sed \
%if %{expr:v"%{python3_version}" >= v"3.14"}
    -e 's/9bc81205a14646a235d284d1b68223d17f30f7f1d3d8ed3e52cf47830b02e3bb/d49574f8a807324c77d378db39fb713662ba5b35cf819360aa37dd8ca5b14388/g' \
    -e 's/a2e637020dfe58f670ba2c942d7a55e49ba48bed09312569ee15a84f5ac680cb/28c3fde0175a875900dec4ed6171445d0c112dcb18045b0822eee7d088734655/g' \
%else
    -e 's/9bc81205a14646a235d284d1b68223d17f30f7f1d3d8ed3e52cf47830b02e3bb/6b2036253586d5fc9698aafec0292cfad0dd12c9f8fefb3f6be255409b89ed39/g' \
    -e 's/a2e637020dfe58f670ba2c942d7a55e49ba48bed09312569ee15a84f5ac680cb/b99cf76118b984ae1e1a23821dd0793a98b20eb318387e0d64e45b6d7ce14a28/g' \
%endif
    -i tests/test_execute/test_complex_outputs_unrun_{auto,cache}.xml \
       tests/test_execute/test_custom_convert_{auto,cache}.xml \
       tests/test_execute/test_custom_convert_multiple_extensions_{auto,cache}.xml
%pyproject_buildrequires -x testing%{?with_doc:,rtd}

%build
%pyproject_wheel

%if %{with doc}
# Build the documentation
PYTHONPATH=$PWD make -C docs html
rm docs/_build/html/.buildinfo
%endif

%install
%pyproject_install
%pyproject_save_files -L myst_nb

export PYTHONPATH=%{buildroot}%{python3_sitelib}
mkdir -p %{buildroot}%{_mandir}/man1
makeman() {
  help2man -N -n "$2" --version-string='%{version}' %{buildroot}%{_bindir}/$1 \
           -o %{buildroot}%{_mandir}/man1/$1.1
}
makeman mystnb-docutils-html 'Generate (X)HTML documents from MyST sources'
makeman mystnb-docutils-html5 'Generate HTML5 documents from MyST sources'
makeman mystnb-docutils-latex 'Generate LaTeX documents from MyST sources'
makeman mystnb-docutils-pseudoxml 'Generate pseudo-XML from MyST sources'
makeman mystnb-docutils-xml 'Generate docutils-native XML from MyST sources'
makeman mystnb-quickstart 'Create a basic MyST-NB project'
makeman mystnb-to-jupyter 'Convert a text-based notebook to a Jupyter notebook'

%check
%pytest -v

%files -n myst-nb -f %{pyproject_files}
%doc CHANGELOG.md README.md
%license LICENSE
%{_bindir}/mystnb-docutils-html
%{_bindir}/mystnb-docutils-html5
%{_bindir}/mystnb-docutils-latex
%{_bindir}/mystnb-docutils-pseudoxml
%{_bindir}/mystnb-docutils-xml
%{_bindir}/mystnb-quickstart
%{_bindir}/mystnb-to-jupyter
%{_mandir}/man1/mystnb-docutils-html.1*
%{_mandir}/man1/mystnb-docutils-html5.1*
%{_mandir}/man1/mystnb-docutils-latex.1*
%{_mandir}/man1/mystnb-docutils-pseudoxml.1*
%{_mandir}/man1/mystnb-docutils-xml.1*
%{_mandir}/man1/mystnb-quickstart.1*
%{_mandir}/man1/mystnb-to-jupyter.1*

%if %{with doc}
%files doc
%doc doc/_build/html
%license LICENSE
%endif

%changelog
## START: Generated by rpmautospec
* Tue Mar 18 2025 Jerry James <loganjerry@gmail.com> - 1.2.0-2
- Ignore jupyter-core warnings (rhbz#2353124)

* Fri Feb 07 2025 Jerry James <loganjerry@gmail.com> - 1.2.0-1
- Version 1.2.0

* Fri Jan 17 2025 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.2-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild

* Tue Jan 14 2025 Jerry James <loganjerry@gmail.com> - 1.1.2-3
- Update test hashes for newer matplotlib

* Wed Nov 27 2024 Richard W.M. Jones <rjones@redhat.com> - 1.1.2-2
- Rebuild for libarrow 18

* Tue Sep 24 2024 Jerry James <loganjerry@gmail.com> - 1.1.2-1
- Version 1.1.2
- Run the tests unconditionally

* Mon Jul 22 2024 Jerry James <loganjerry@gmail.com> - 1.1.1-1
- Initial RPM
## END: Generated by rpmautospec