## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%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

%global srcname asv

%global jquery_version 3.3.1

# Testing using conda requires the network to install packages.
%bcond_with network

Name:           %{srcname}
Version:        0.5.1
Release:        %autorelease
Summary:        Airspeed Velocity: A simple Python history benchmarking tool

# Mostly BSD-3-Clause; MIT for extern & www/vendor/*.{css,js}
License:        BSD-3-Clause and MIT
URL:            https://github.com/airspeed-velocity/asv
Source0:        %{pypi_source}
# Not needed upstream.
Patch0001:      0001-Don-t-allow-extension-build-errors-to-be-ignored.patch
# Not wanted upstream: https://github.com/airspeed-velocity/asv/pull/762
Patch0002:      0002-Unbundle-JSON-minify.patch
# Fedora-specific.
Patch0003:      0003-Remove-unnecessary-shebang.patch
Patch0004:      0004-Fix-pypy-version-environment-test-on-latest-pypy.patch

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

BuildRequires:  python3-devel
BuildRequires:  web-assets-devel
BuildRequires:  (js-jquery >= %{jquery_version} with js-jquery < 4)

BuildRequires:  python3dist(sphinx)
BuildRequires:  python3-sphinx-bootstrap-theme

%if %{with network}
BuildRequires:  conda
BuildRequires:  python3dist(selenium)
%endif
%ifarch x86_64 aarch64
BuildRequires:  chromedriver
BuildRequires:  chromium
%endif
BuildRequires:  gcc-c++
BuildRequires:  git-core
BuildRequires:  hg
%ifnarch aarch64 %{power64} %{ix86}
BuildRequires:  pypy
%endif
BuildRequires:  python3dist(feedparser)
BuildRequires:  python3dist(numpy)
BuildRequires:  python3dist(pip)
BuildRequires:  python3dist(pytest)
BuildRequires:  python3dist(rpy2)
BuildRequires:  python3dist(scipy)
BuildRequires:  python3dist(virtualenv)
BuildRequires:  python3dist(wheel)

%py_provides python3-%{srcname}
Provides:       bundled(python-asizeof) = 5.10
Provides:       bundled(nodejs-blueimp-md5) = 2.10.0
Provides:       bundled(nodejs-flot) = 0.8.3
Provides:       bundled(nodejs-flot-axislabels) = 0.20120405ga0d11e5
Provides:       bundled(nodejs-flot-orderbars) = 0.20100920
Provides:       bundled(nodejs-stupid-table) = 1.0.1

Requires:       (js-jquery >= %{jquery_version} with js-jquery < 4)
Suggests:       conda
Suggests:       python3-virtualenv
Suggests:       python3-hglib >= 1.5
Suggests:       hg
Suggests:       git

# Recommend "all the Pythons", like tox.
Recommends:     python27
Recommends:     python34
Recommends:     python35
Recommends:     python36
Recommends:     python37
Recommends:     python38
Recommends:     python39
Recommends:     pypy
Recommends:     pypy3
Recommends:     python2
Recommends:     python3

%description
Airspeed Velocity (asv) is a tool for benchmarking Python packages over
their lifetime. It is primarily designed to benchmark a single project
over its lifetime using a given suite of benchmarks. The results are
displayed in an interactive web frontend that requires only a basic static
webserver to host.


%package -n %{srcname}-doc
Summary:        asv documentation
%description -n %{srcname}-doc
Documentation for asv


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

# Remove useless shebang
sed -i -e '/^#!\//, 1d' asv/extern/asizeof.py

%generate_buildrequires
%pyproject_buildrequires -r -x hg

%build
%pyproject_wheel

# generate html docs
PYTHONPATH="$PWD/build/lib.%{python3_platform}-cpython-%{python3_version_nodots}" \
    sphinx-build-3 docs/source html
# remove the sphinx-build leftovers
rm -rf html/.{doctrees,buildinfo}


%install
%pyproject_install

# Unbundle jQuery
pushd %{buildroot}%{python3_sitearch}/asv/www/vendor
rm jquery-%{jquery_version}.min.js
ln -s %{_jsdir}/jquery/3/jquery.min.js jquery-%{jquery_version}.min.js
popd

%pyproject_save_files asv


%check
# Must do this to load from buildroot
rm -rf asv

# Without this, test_git_submodule fails on git 2.38.1 and later due to
# mitigations for CVE-2022-39253. See:
#
# https://github.blog/2022-10-18-git-security-vulnerabilities-announced/#cve-2022-39253
# https://bugzilla.redhat.com/show_bug.cgi?id=2137127
git config --global protocol.file.allow always

%ifarch x86_64 aarch64
WEBDRIVER="--webdriver=ChromeHeadless"
%endif
# Since Python 3.12, virtualenv no longer installs the setuptools and wheel
# packages which are needed to run the tests. The following environment
# variables restore the old behaviour
export VIRTUALENV_SETUPTOOLS=bundle VIRTUALENV_WHEEL=bundle
%{pytest} -ra $WEBDRIVER \
%if %{fedora} >= 34
    -k 'not test_web' \
%endif
    %{nil}


%files -n %{srcname} -f %{pyproject_files}
%doc README.rst
%{_bindir}/asv


%files -n %{srcname}-doc
%doc html
%license LICENSE.rst


%changelog
* Fri Aug 18 2023 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.5.1-12
- Fix build issues with Python 3.12

* Wed Jul 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.5.1-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Thu Jun 29 2023 Python Maint <python-maint@redhat.com> - 0.5.1-10
- Rebuilt for Python 3.12

* Sun Apr 09 2023 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.5.1-9
- Switch to SPDX license

* Wed Jan 18 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.5.1-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Mon Dec 19 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.5.1-7
- Drop support for i686

* Mon Oct 24 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.5.1-6
- Fix RHBZ#2137127
- Set git option protocol.file.allow to “always” for the tests, working
  around changes in git 2.38.1 due to CVE-2022-39253.

* Wed Jul 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.5.1-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

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

* Wed Mar 30 2022 Miro Hrončok <miro@hroncok.cz> - 0.5.1-3
- Stop BuildRequiring pypy on ix86

* Sun Feb 20 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.5.1-2
- Fix PYTHONPATH when building docs

* Sun Feb 20 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.5.1-1
- Update to latest version

* Sun Feb 20 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.2-14
- Switch to latest Python macros

* Sat Jan 29 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.2-9
- Drop i686 dependency on Chromium
- Fix test for pypy environment setup

* Wed Jan 19 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.2-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Wed Jul 21 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.2-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 0.4.2-7
- Rebuilt for Python 3.10

* Sun May 16 2021 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.2-6
- Fix incorrect bundled Provides

* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.2-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Mon Jan 18 2021 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.2-4
- Skip web test on Fedora 34 temporarily

* Mon Jul 27 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Tue May 26 2020 Miro Hrončok <mhroncok@redhat.com> - 0.4.2-2
- Rebuilt for Python 3.9

* Sat May 16 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.2-1
- Update to latest version

* Mon May 11 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.1-8
- Loosen up jQuery dependency

* Sun Feb 23 2020 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.1-7
- Re-bundle flot
- Small cleanups to spec

* Tue Jan 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.1-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 0.4.1-5
- Rebuilt for Python 3.8.0rc1 (#1748018)

* Mon Aug 19 2019 Miro Hrončok <mhroncok@redhat.com> - 0.4.1-4
- Rebuilt for Python 3.8

* Wed Jul 24 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Mon Jul 22 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.1-2
- Fix tests against latest Chrome webdriver

* Tue Jun 04 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4.1-1
- Update to latest version

* Sun May 26 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.4-1
- Update to latest version

* Sat Feb 09 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.3.1-7
- Rebuild against jQuery 3.3.1

* Thu Jan 31 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.3.1-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Fri Dec 07 2018 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.3.1-5
- Improve testing of web app
- Fix jQuery unbundling

* Wed Dec 05 2018 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.3.1-4
- Add missing json-minify Requires

* Tue Nov 13 2018 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.3.1-3
- Mark bundled JS libraries

* Mon Nov 12 2018 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.3.1-2
- Unbundle json-minify, jQuery, and flot

* Sun Oct 21 2018 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.3.1-1
- Update to latest version

* Sat Oct 20 2018 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.3-1
- Update to latest version

* Sun Nov 19 2017 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.2.1-1
- Initial package.