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

# Over 75% of the tests require upstream connectivity.
%bcond_with     tests

%global         srcname     grafeas
%global         reponame    google-cloud-python

Name:           python-%{srcname}
Version:        1.9.0
Release:        %autorelease
Summary:        Python SDK for Google Cloud Grafeas API

License:        Apache-2.0
URL:            https://github.com/googleapis/google-cloud-python
Source0:        %{url}/archive/refs/tags/%{srcname}-v%{version}.tar.gz

BuildArch:      noarch

BuildRequires:  python3-devel

%if %{with tests}
BuildRequires:  python3dist(pytest)
BuildRequires:  python3dist(pytest-asyncio)
%endif

%global _description %{expand:
Grafeas API: An implementation of the Grafeas API, which stores, and enables
querying and retrieval of critical metadata about all of your software
artifacts.}

%description %{_description}


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

%description -n python3-%{srcname} %{_description}


%prep
# Upstream buries the package into a subdirectory. 😭
%setup -c -T
tar xzf %{SOURCE0} --strip-components=3 \
    %{reponame}-%{srcname}-v%{version}/packages/%{srcname}

# Allow a slightly older protobuf.
sed -i 's/"protobuf.*",/"protobuf>=3.19.4",/' setup.py

# Replace mock imports with unittest.mock.
grep -rl "^[[:space:]]*import mock" tests | \
    xargs sed -i -E 's/^([[:space:]]*)import mock/\1from unittest import mock/'


%generate_buildrequires
%pyproject_buildrequires -r


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files grafeas

# Remove unnecessary scripts.
rm -f %{buildroot}%{_bindir}/fixup*


%check
%if %{with tests}
# NOTE(mhayden): Setting PYTHONUSERBASE as a hack for PEP 420 namespaces.
# Thanks to churchyard for the fix.
PYTHONUSERBASE=%{buildroot}%{_prefix} \
    %pytest tests/unit
%endif


%files -n python3-%{srcname} -f %{pyproject_files}
%doc README.rst CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.rst SECURITY.md samples


%changelog
* Wed Dec 13 2023 Major Hayden <major@redhat.com> - 1.9.0-1
- Update to 1.9.0 rhbz#2253553

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

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

* Tue Feb 21 2023 Major Hayden <major@redhat.com> - 1.8.1-1
- Update to 1.8.1

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

* Mon Nov 14 2022 Major Hayden <major@redhat.com> - 1.6.1-1
- Update to 1.6.1 rhbz#2131894

* Tue Aug 16 2022 Major Hayden <major@redhat.com> - 1.5.1-1
- Update to 1.5.1 rhbz#2118753

* Wed Jul 27 2022 Major Hayden <major@redhat.com> - 1.5.0-1
- Update to 1.5.0 rhbz#2107234

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

* Mon Jun 13 2022 Major Hayden <major@redhat.com> - 1.4.5-2
- Add note about F35

* Mon Jun 13 2022 Major Hayden <major@redhat.com> - 1.4.5-1
- Update to 1.4.5

* Fri May 06 2022 Major Hayden <major@mhtx.net> - 1.4.4-1
- Update to 1.4.4

* Tue Mar 08 2022 Major Hayden <major@redhat.com> - 1.4.3-1
- Update to 1.4.3

* Tue Mar 01 2022 Major Hayden <major@redhat.com> - 1.4.2-1
- Update to 1.4.2

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

* Thu Jan 13 2022 Major Hayden <major@redhat.com> - 1.4.1-1
- Update to 1.4.1

* Thu Nov 04 2021 Major Hayden <major@redhat.com> - 1.4.0-1
- Update to 1.4.0

* Tue Nov 02 2021 Major Hayden <major@redhat.com> - 1.3.1-1
- Update to 1.3.1

* Thu Oct 28 2021 Major Hayden <major@redhat.com> - 1.3.0-2
- First package for version 1.3.0 🎉

* Thu Oct 28 2021 Major Hayden <major@mhtx.net> - 1.3.0-1
- Initial commit (#2012997)