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

Name:           pyinstrument
Version:        4.4.0
Release:        %autorelease
Summary:        Python profiler with colorful output

# The majority of code is BSD-3-Clause.
# Exceptions:
#   pyinstrument/vendor/keypath.py: BSD-2-Clause
#   pyinstrument/renderers/html_resources/app.js: MIT
License:        BSD-3-Clause AND BSD-2-Clause and MIT
URL:            https://github.com/joerick/pyinstrument
Source:         https://github.com/joerick/pyinstrument/archive/v%{version}/pyinstrument-%{version}.tar.gz

Patch0:         0001-Allow-non-vendored-deps-to-be-used.patch

BuildRequires:  python3-devel
BuildRequires:  python3-trio
BuildRequires:  python3-flaky
BuildRequires:  python3-greenlet
BuildRequires:  python3-pytest-asyncio
BuildRequires:  pytest
BuildRequires:  gcc
# for docs
BuildRequires:  make
BuildRequires:  python3-myst-parser
BuildRequires:  python3-sphinxcontrib-programoutput
BuildRequires:  python3dist(appdirs) >= 1.4.4
BuildRequires:  python3dist(decorator) >= 4.3.1
Requires:       python3dist(appdirs) >= 1.4.4
Requires:       python3dist(decorator) >= 4.3.1

Recommends:     %{name}-doc
Provides:       bundled(python-keypath)


%global _description %{expand:
This package provides a line profiler similar to cProfile, but based on
statistical sampling instead, and with a nicer and more colorful output:
    pyinstrument script.py
}

%description %_description

%package doc
Summary:       Documentation for %{name}
Requires:      %{name} = %{version}-%{release}
BuildArch:     noarch

%description doc
HTML documentation and example files for %{name}.


%prep
%autosetup -p1
# Without this, pyinstrument/low_level/stat_profile_python.py gets ignored
touch pyinstrument/low_level/__init__.py

sed -r -i '/html_theme = "furo"/d' docs/conf.py

rm pyinstrument/vendor/{appdirs.py,decorator.py}

%generate_buildrequires
%pyproject_buildrequires

%build
%pyproject_wheel

export PYTHONPATH=$(echo $PWD/build/lib.linux-*)
make -C docs man
make -C docs html

# to avoid the package getting installed
rm examples/django_example/.gitignore

%py3_shebang_fix examples/django_example/manage.py

%install
%pyproject_install
%pyproject_save_files pyinstrument

install -m0644 -Dt %{buildroot}%{_mandir}/man1/ docs/_build/man/pyinstrument.1

%check
# pytest seems to add CWD to the path, so we end up importing the module without
# the compiled parts. Let's just move it out of the way.
mv pyinstrument _pyinstrument

TESTOPTS=(
    # Those tests fail. Maybe related to greenlet version?
    --deselect=test/test_profiler_async.py::test_greenlet
    --deselect=test/test_profiler_async.py::test_strict_with_greenlet

    # Those two fail in mock…
    --deselect='test/test_cmdline.py::TestCommandLine::test_script_execution_details[pyinstrument_invocation0]'
    --deselect='test/test_cmdline.py::TestCommandLine::test_path_execution_details[pyinstrument_invocation0]'
)

%pytest -v test/ "${TESTOPTS[@]}"

%files -f %{pyproject_files}
%license LICENSE
%doc README.md
%{_bindir}/pyinstrument
%exclude %{python3_sitearch}/pyinstrument/low_level/stat_profile.c
%doc %{_mandir}/man1/pyinstrument.1*

%files doc
%doc docs/_build/html/
%doc examples/

%changelog
## START: Generated by rpmautospec
* Fri Jan 26 2024 Fedora Release Engineering <releng@fedoraproject.org> - 4.4.0-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Sun Jan 21 2024 Fedora Release Engineering <releng@fedoraproject.org> - 4.4.0-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 4.4.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Sat Jul 01 2023 Python Maint <python-maint@redhat.com> - 4.4.0-5
- Rebuilt for Python 3.12

* Mon May 15 2023 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 4.4.0-2
- Also list MIT in licenses

* Sat May 06 2023 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 4.4.0-1
- Version 4.4.0

* Sat Aug 27 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 4.3.0-1
- Initial version
## END: Generated by rpmautospec