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

# Tests don't currently run:
# using hatch requires setting up a local dev environment
# using pytest breaks as sources are split between src/fixit and legacy
%bcond_with tests

%global pypi_name fixit

%global common_description %{expand:
Fixit is a lint framework that complements Flake8. It’s based on LibCST
which makes it possible to provide auto-fixes. Lint rules are made easy to
build through pattern matching, a test toolkit, and utility helpers (e.g.
scope analysis) for non-trivial boilerplate. It is optimized for efficiency,
easy to customize and comes with many builtin lint rules.}

%global date 20230223
%global commit d2b59da3f822555e433eb6776e1f40f4b92c18d5
%global shortcommit %(c=%{commit}; echo ${c:0:7})

Name:           python-%{pypi_name}
Version:        0.1.5~%{date}g%{shortcommit}
Release:        %autorelease
Summary:        A lint framework that writes better Python code for you

License:        MIT
URL:            https://github.com/Instagram/Fixit
# PyPI tarball doesn't include docs
# Source:         %%{url}/archive/v%%{version}/Fixit-%%{version}.tar.gz
Source:         %{url}/archive/%{commit}/%{pypi_name}-%{shortcommit}.tar.gz
Patch:          %{name}-pregenerate_version.diff
Patch:          %{name}-rm-unused-inventories.diff
BuildArch:      noarch

BuildRequires:  sed
BuildRequires:  python3-devel
BuildRequires:  python3-docs
BuildRequires:  python3dist(sphinx)
BuildRequires:  python3dist(sphinx-mdinclude)

%description
%{common_description}

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

%description -n python3-%{pypi_name}
%{common_description}

%package        doc
Summary:        %{name} documentation
Requires:       python3-docs

%description    doc
Documentation for %{name}

%prep
%autosetup -n Fixit-%{commit} -p1
# Remove bundled egg-info
rm -rf %{pypi_name}.egg-info
# Use local intersphinx inventory
sed -r \
    -e 's|https://docs.python.org/3|%{_docdir}/python3-docs/html|' \
    -i docs/conf.py

%generate_buildrequires
%pyproject_buildrequires


%build
%pyproject_wheel

# generate html docs
PYTHONPATH=${PWD}/src sphinx-build-3 docs html
# remove the sphinx-build leftovers
rm -rf html/.{doctrees,buildinfo}


%install
%pyproject_install
%pyproject_save_files %{pypi_name}


%check
%pyproject_check_import
%if %{with tests}
hatch run test
%endif


%files -n python3-%{pypi_name} -f %{pyproject_files}
%license LICENSE
%doc README.rst CHANGELOG.md
%{_bindir}/fixit


%files doc
%doc html
%license LICENSE


%changelog
* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.5~20230223gd2b59da-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Thu Jun 15 2023 Python Maint <python-maint@redhat.com> - 0.1.5~20230223gd2b59da-2
- Rebuilt for Python 3.12

* Fri Mar 17 2023 Michel Alexandre Salim <salimma@fedoraproject.org> - 0.1.5~20230223gd2b59da-1
- Update to snapshot for flake8 >= 5 compatibility

* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.4-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

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

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

* Sat Nov 20 2021 Michel Alexandre Salim <salimma@fedoraproject.org> - 0.1.4-3
- Update patch to gate importlib-resources on python_version <= '3.7'

* Thu Nov 11 2021 Michel Alexandre Salim <salimma@fedoraproject.org> - 0.1.4-2
- Strip importlib-resources from requirements.txt

* Sun Nov 07 2021 Davide Cavalca <dcavalca@fedoraproject.org> - 0.1.4-1
- Update to 0.1.4; Fixes: RHBZ#1988570

* Sun Nov 07 2021 Davide Cavalca <dcavalca@fedoraproject.org> - 0.1.3-5
- Drop logic for Fedora 32

* Tue Jul 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.3-3
- Second attempt - Rebuilt for
  https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

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

* Wed Apr 07 2021 Davide Cavalca <dcavalca@fedoraproject.org> - 0.1.3-1
- Initial package.