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

# Should we re-generate the Python binding code from the .proto files, instead
# of using the pre-generated code in the source tarball? Either approach is OK
# under Fedora packaging guidelines.
%bcond_with codegen

%global srcname opencensus-proto
%global _description %{expand:
Census provides a framework to define and collect stats against metrics and to
break those stats down across user-defined dimensions.

The Census framework is natively available in many languages (e.g. C++, Go, and
Java). The API interface types are defined using protos to ensure consistency
and interoperability for the different implementations.}

Name:           python-%{srcname}
Version:        0.4.1
Release:        %autorelease
Summary:        Language Independent Interface Types For OpenCensus

License:        Apache-2.0
URL:            https://github.com/census-instrumentation/%{srcname}/
Source0:        %{url}/archive/v%{version}/%{srcname}-%{version}.tar.gz

BuildRequires:  python3-devel
%if %{with codegen}
BuildRequires:  %{py3_dist grpcio-tools}
%endif
BuildArch:      noarch

%description %{_description}


%package -n python3-%{srcname}
Summary:        Python library generated from OpenCensus cross-language protos

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


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

%if %{with codegen}
find gen-python/opencensus/proto -type f ! -name '__init__.py' -print -delete
sed -r -i 's|\bpython |%{__python3} |g' src/mkpygen.sh
%endif

sed -r -i 's/^__version__[[:blank:]]*=/# &/' gen-python/version.py
cat >> gen-python/version.py <<EOF
# Python version number is always “dev”
# https://github.com/census-instrumentation/opencensus-proto/issues/234
__version__ = '%{version}'  # Correct release version
EOF


%generate_buildrequires
cd gen-python/
%pyproject_buildrequires


%build
%if %{with codegen}
pushd src
./mkpygen.sh
popd
%endif
pushd gen-python/
%pyproject_wheel
popd


%install
pushd gen-python/
%pyproject_install
# Giving the name of the containing namespace package works acceptably.
# https://bugzilla.redhat.com/show_bug.cgi?id=1935266
%pyproject_save_files opencensus
popd


%check
# Upstream has no tests.
%pyproject_check_import -e opencensus.proto.*.*.v1.* -e opencensus.proto.*.v1.*


%files -n python3-%{srcname} -f %{pyproject_files}
%license LICENSE
%doc AUTHORS CONTRIBUTING.md gen-python/README.rst

# Excluding these files makes it easier to share ownership of the namespace
# package directory, without worrying about trivial differences in the contents
# of __init__.py—which is not needed for namespace packages in recent Python
# versions anyway.
%exclude %{python3_sitelib}/opencensus/{*.py,__pycache__/}


%changelog
## START: Generated by rpmautospec
* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.1-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Sat Jun 08 2024 Python Maint <python-maint@redhat.com> - 0.4.1-9
- Rebuilt for Python 3.13

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

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

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

* Mon Jun 26 2023 Python Maint <python-maint@redhat.com> - 0.4.1-5
- Rebuilt for Python 3.12

* Sat Feb 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.1-4
- Fix the version number in the metadata

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

* Tue Nov 29 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.1-2
- Update License to SPDX

* Mon Oct 31 2022 Major Hayden <major@redhat.com> - 0.4.1-1
- Update to 0.4.1 rhbz#2129355

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

* Thu Jun 16 2022 Python Maint <python-maint@redhat.com> - 0.3.0-20
- Rebuilt for Python 3.11

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

* Fri Oct 29 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.3.0-18
- Use the new %%%%pyproject_check_import macro

* Tue Sep 14 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.3.0-17
- Use the pyproject_save_files macro

* Sun Sep 12 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.3.0-16
- Drop BR on pyproject-rpm-macros, now implied by python3-devel

* Wed Jul 28 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.3.0-15
- Move %%generate_buildrequires after %%prep to make the spec file easier
  to follow

* Sat Jul 10 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.3.0-6
- Add a check section that “smoke-tests” imports

* Fri Jun 25 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.3.0-5
- Whitespace adjustments
- Drop obsolete %%python_provide macro
- Precisely name the egg-info directory rather than using a glob
- Use the srcname macro in the package name
- Share ownership of the opencensus namespace package directory
- Allow re-generating the Python bindings from .proto sources
- Use pyproject-rpm-macros

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

* Wed Jan 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.3.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.3.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Fri Jul 24 2020 Mohamed El Morabity <melmorabity@fedoraproject.org> - 0.3.0-1
- Update to 0.3.0

* Sun May 31 2020 Mohamed El Morabity <melmorabity@fedoraproject.org> - 0.2.1-2
- Rebuild for Python 3.9

* Fri May 29 2020 Mohamed El Morabity <melmorabity@fedoraproject.org> - 0.2.1-1
- Initial RPM release

## END: Generated by rpmautospec