Blob Blame History Raw
# 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_without 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.3.0
Release:        %autorelease
Summary:        Language Independent Interface Types For OpenCensus

License:        ASL 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


%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.
#
# We choose just to test importing the “leaf” modules (.py files), which
# implicitly tests importing all of the packages with their __init__.py’s (e.g.
# “opencensus.proto.agent”).
%{py3_check_import opencensus.proto.agent.common.v1.common_pb2
    opencensus.proto.agent.metrics.v1.metrics_service_pb2
    opencensus.proto.agent.metrics.v1.metrics_service_pb2_grpc
    opencensus.proto.agent.trace.v1.trace_service_pb2
    opencensus.proto.agent.trace.v1.trace_service_pb2_grpc
    opencensus.proto.metrics.v1.metrics_pb2
    opencensus.proto.resource.v1.resource_pb2
    opencensus.proto.stats.v1.stats_pb2
    opencensus.proto.trace.v1.trace_config_pb2
    opencensus.proto.trace.v1.trace_pb2}


%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
%autochangelog