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

Name:           python-pybv
Version:        0.7.5
Release:        %autorelease
Summary:        A lightweight I/O utility for the BrainVision data format

License:        BSD-3-Clause
URL:            https://pybv.readthedocs.io/en/stable/
# A filtered source archive, obtained by (see Source1):
#
#   ./get_source %%{version}
#
# is required because specification/ contains a PDF file,
# BrainVisionCoreDataFormat_1-0.pdf, with unclear license terms.
#
# The unfiltered base source URL would be:
#
# https://github.com/bids-standard/pybv/archive/v%%{version}/pybv-%%{version}.tar.gz
#
# We have asked upstream to stop distributing the specification/ directory in
# PyPI sdists: https://github.com/bids-standard/pybv/pull/106
Source0:        pybv-%{version}-filtered.tar.zst
Source1:        get_source

# Replace deprecated mne.utils.requires_version
# https://github.com/bids-standard/pybv/pull/105
Patch:          https://github.com/bids-standard/pybv/pull/105.patch

# Fix version quote handling
# This is a partial backport of:
# https://github.com/bids-standard/pybv/commit/11b47b7a5a21230c1d7fd208e27bbd3ae721cc28
Patch:          0001-Fix-version-quote-handling.patch

BuildArch:      noarch
ExcludeArch:    %{ix86}

BuildRequires:  python3-devel

%if %{with doc_pdf}
# Extra dependencies for building PDF instead of HTML
BuildRequires:  make
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
BuildRequires:  /usr/bin/xindy
BuildRequires:  tex-xetex-bin
%endif

%global common_description %{expand:
pybv is a lightweight I/O utility for the BrainVision data format.

The BrainVision data format is a recommended data format for use in the Brain
Imaging Data Structure.}

%description %{common_description}


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

%description -n python3-pybv %{common_description}


%pyproject_extras_subpkg -n python3-pybv export


%package        doc
Summary:        Documentation for python-pybv

%description    doc %{common_description}


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

# Filter unwanted dev dependencies:
#
# - linters
# - coverage analysis and other unnecessary pytest plugins
# - formatters etc.
# - documentation dependencies (if building docs is disabled)
#
# See also:
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters
sed -r \
    -e 's/^(check-manifest|flake8(-.*)?|pycodestyle|pre-commit)\b/# &/' \
    -e 's/^(pytest-(cov|sugar))/# &/' \
    -e 's/^(black|isort)/# &/' \
    %{?!with_doc_pdf:-e 's/^(sphinx(-(copybutton))?|numpydoc)\b/# &/'} \
    requirements-dev.txt | tee requirements-dev-filtered.txt

cat >>docs/conf.py <<'EOF'
# We can’t resolve intersphinx mapping URLs in an offline build.
intersphinx_mapping.clear()
EOF
# Since pdflatex cannot handle Unicode inputs in general:
echo "latex_engine = 'xelatex'" >> docs/conf.py


%generate_buildrequires
%pyproject_buildrequires -x export -r requirements-dev-filtered.txt


%build
%pyproject_wheel
%if %{with doc_pdf}
PYTHONPATH="${PWD}" %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 pybv


%check
%{pytest}


%files -n python3-pybv -f %{pyproject_files}


%files doc
%license LICENSE
%doc CITATION.cff
%doc README.rst
# The changelog is included in the PDF documentation, but it’s useful to
# package it as a text file too.
%doc docs/changelog.rst

%if %{with doc_pdf}
%doc docs/_build/latex/pybv.pdf
%endif


%changelog
## START: Generated by rpmautospec
* Fri Apr 05 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.7.5-7
- Use zstd instead of xz for filtered source archive compression

* Fri Apr 05 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.7.5-6
- Improve reproducibility of the filtered source archive

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

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

* Mon Dec 18 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.7.5-2
- Assert that %%pyproject_files contains a license file

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.7.5-1
- Update to 0.7.5

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-22
- Stop distributing the format specification PDF
- Its license terms are unclear, so we exclude it from the lookaside cache
  and the SRPM going forward.

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-21
- Build PDF documentation and add a -doc subpackage

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-20
- Update License to SPDX

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-19
- Improved build dependency generation

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-18
- Rely on the generated BR on mne; drop the manual one

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-17
- Remove unnecessary cruft from the prep section

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-16
- Package CITATION.cff as documentation

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-15
- Drop duplicate LICENSE file

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-11
- Update the description from upstream

* Mon Oct 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.0-10
- Replace deprecated mne.utils.requires_version
- Fix RHBZ#2226287, fix RHBZ#2220423

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

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

* Sun Oct 24 2021 Aniket Pradhan <major AT fedoraproject DOT org> - 0.6.0-1
- Initial build

## END: Generated by rpmautospec