python-sentry-sdk/python-sentry-sdk.spec
Roman Inflianskas d4ac9b43ba
Rename tox env: rediscluster -> redis_py_cluster_legacy
The tox environment's name was changed in the commit:
121aa0e7a5

This change was not reflected in commit `987e25d`; the tests did not run
because they were disabled in commit `7501b73`.

[skip changelog]
2024-08-20 07:47:43 +03:00

450 lines
18 KiB
RPMSpec

# Excluded extras/integrations
# Lines below are in `code: comment` format, where `code` is used for
# easier navigation in text editors and linking
# no_anthropic: anthropic not packaged yet
# no_ariadne: ariadne not packaged yet
# no_arq: arq not packaged yet
# no_beam: beam not packaged yet
# no_celery_redbeat: celery-redbeat not packaged yet
# no_chalice: chalice not packaged yet
# no_clickhouse_driver: clickhouse_driver not packaged yet
# no_cohere: cohere is not packaged
# no_fakeredis: fakeredis is not packaged
# no_gql: gql not packaged yet
# no_huey: huey not packaged yet
# no_huggingface_hub: huggingface_hub not packaged yet
# no_langchain: langchain not packaged yet
# no_loguru: loguru not packaged yet
# no_openai: openai not packaged yet
# no_pyspark: pyspark not packaged yet
# no_quart: quart not packaged yet
# no_sanic: sanic not packaged yet
# no_starlite: starlite not packaged yet
# no_strawberry: strawberry not packaged yet
# no_trytond: trytond not packaged yet
# Conditionally excluded extras
# opentelemetry-experimental requires opentelemetry-contrib libraries of 0.40b0 version
%bcond opentelemetry_experimental %[%{?fedora} >= 40]
%bcond tests 1
%bcond network_tests 0
%global forgeurl https://github.com/getsentry/sentry-python
Version: 2.7.1
%global tag %{version}
%forgemeta
Name: python-sentry-sdk
Release: %autorelease
Summary: The new Python SDK for Sentry.io
License: MIT
URL: https://sentry.io/for/python/
Source0: %{forgesource}
# Tests fail with:
# `AssertionError: previous item was not torn down properly`
# because of the bug in pytest-forked, reorder them to make them pass.
# See https://github.com/pytest-dev/pytest-forked/issues/67#issuecomment-1964718720
# for the explanation.
# Upstream issue: https://github.com/getsentry/sentry-python/issues/3035
Patch0: 0001-Reorder-forked-tests.patch
# Tests fail because they are expected to be executed in a clean environment.
# Upstream PR: https://github.com/getsentry/sentry-python/pull/3240
Patch1: 0002-ref-tests-Unhardcode-integration-list.patch
BuildArch: noarch
BuildRequires: python3-devel
%if %{with tests}
BuildRequires: python3dist(botocore)
BuildRequires: python3dist(certifi)
BuildRequires: python3dist(djangorestframework)
BuildRequires: python3dist(gevent)
BuildRequires: python3dist(graphene)
BuildRequires: python3dist(jsonschema)
BuildRequires: python3dist(protobuf)
BuildRequires: python3dist(psycopg2)
BuildRequires: python3dist(pyramid)
BuildRequires: python3dist(pysocks)
BuildRequires: python3dist(pytest)
BuildRequires: python3dist(pytest-aiohttp)
BuildRequires: python3dist(pytest-asyncio)
BuildRequires: python3dist(pytest-django)
BuildRequires: python3dist(pytest-forked)
BuildRequires: python3dist(pytest-localserver)
BuildRequires: python3dist(python-multipart)
BuildRequires: python3dist(requests)
BuildRequires: python3dist(responses)
BuildRequires: python3dist(wheel)
%if %{with network_tests}
BuildRequires: python3dist(boto3)
BuildRequires: python3dist(httpx)
BuildRequires: python3dist(pytest-httpx)
%endif
%endif
# For re-generating protobuf bindings
BuildRequires: protobuf-compiler
%global _description %{expand:
Python Error and Performance Monitoring. Actionable insights to resolve Python
performance bottlenecks and errors. See the full picture of any Python exception
so you can diagnose, fix, and optimize performance in the Python debugging
process.}
%description %_description
%package -n python3-sentry-sdk
Summary: %{summary}
%description -n python3-sentry-sdk %_description
%global default_toxenv py%{python3_version}
# List of names of extras & toxenvs included
%global components %{shrink:
aiohttp
celery
django
falcon
fastapi
opentelemetry
pure_eval
sqlalchemy
starlette
tornado
%{nil}}
# List of names of extras & toxenvs excluded
# anthropic: no_anthropic
# arq: no_arq
# beam: no_beam
# chalice: no_chalice
# huey: no_huey
# huggingface_hub: no_huggingface_hub
# langchain: no_langchain
# loguru: no_loguru
# openai: no_openai
# quart: no_quart
# sanic: no_sanic
# starlite: no_starlite
%global components_excluded %{shrink:
anthropic
arq
beam
chalice
huey
huggingface_hub
langchain
loguru
openai
quart
sanic
starlite
%{nil}}
# List of names of extras included (if not present in components)
%global extras %{shrink:
%{components}
asyncpg
bottle
flask
grpcio
httpx
pymongo
rq
%{?with_opentelemetry_experimental:opentelemetry-experimental}
%{nil}}
# List of names of extras excluded (if not present in components_excluded)
# celery-redbeat: no_celery_redbeat
# clickhouse-driver: no_clickhouse_driver
# pyspark: no_pyspark
%global extras_excluded %{shrink:
%{components_excluded}
celery-redbeat
clickhouse-driver
pyspark
%{!?with_opentelemetry_experimental:opentelemetry-experimental}
%{nil}}
%define toxenvs_by_components %{expand:%(echo %{components} | sed "s/^/%{toxenv}-/;s/ / %{toxenv}-/g")}
# List of names of toxenvs included (if not present in components)
%global toxenvs %{shrink:
%{toxenvs_by_components}
%{toxenv}-common
%{toxenv}-cloud_resource_context
%{toxenv}-gevent
%{nil}
}
%define toxenvs_excluded_by_components %{expand:%(echo %{components_excluded} | sed "s/^/%{toxenv}-/;s/ / %{toxenv}-/g")}
# List of names of toxenvs excluded (if not present in components_excluded)
# ariadne: no_ariadne
# asgi: async_asgi_testclient is unpackaged yet
# asyncpg: require a local PostgreSQL instance running
# aws_lambda: aws_lambda requires credentials
# boto3: require network
# bottle: werkzeug in Fedora 38 is too new, see: https://github.com/getsentry/sentry-python/issues/1398
# clickhouse_driver: no_clickhouse_driver
# flask: werkzeug in Fedora 38 is too new, see: https://github.com/getsentry/sentry-python/issues/1398
# cohere: no_cohere
# gcp: python 3.7 only
# gql: no_gql
# graphene: graphene is too old (min version: 3.3)
# grpc: protobuf is too old
# httpx: require network
# pymongo: mockupdb is unpackaged because it appears unmaintained
# pyramid: werkzeug is too new (version < 2.1.0)
# redis: no_fakeredis
# redis_py_cluster_legacy: no_fakeredis
# requests: require network
# rq: no_fakeredis
# socket: require network
# starberry: no_strawberry
# trytond: no_trytond
%global toxenvs_excluded %{shrink:
%{toxenvs_excluded_by_components}
%{toxenv}-ariadne
%{toxenv}-asgi
%{toxenv}-asyncpg
%{toxenv}-aws_lambda
%{toxenv}-boto3
%{toxenv}-bottle
%{toxenv}-clickhouse_driver
%{toxenv}-cohere
%{toxenv}-flask
%{toxenv}-gcp
%{toxenv}-gql
%{toxenv}-graphene
%{toxenv}-grpc
%{toxenv}-httpx
%{toxenv}-pymongo
%{toxenv}-pyramid
%{toxenv}-redis
%{toxenv}-redis_py_cluster_legacy
%{toxenv}-rq
%{toxenv}-requests
%{toxenv}-socket
%{toxenv}-strawberry
%{toxenv}-trytond
%{nil}}
%define toxenvs_csv %{expand:%(echo %{toxenvs} | sed "s/ /,/g")}
%define extras_csv %{expand:%(echo %{extras} | sed "s/ /,/g")}
%pyproject_extras_subpkg -n python3-sentry-sdk %{extras}
%prep
%forgeautosetup -p1
# Verify all extras defined against setup.py
defined_extra=$(echo "%extras_excluded" "%extras" | xargs -n1 | sort -u)
setup_py_extra=$(cat setup.py | sed -n '/extras_require/,/}/p' | sed 's/ //g' | sed '$ s/.$/\nprint("\\n".join(extras_require))/' | python3 -)
diff <(echo "$defined_extra") <(echo "$setup_py_extra")
sed -r -i 's/psycopg2-binary/psycopg2/' tox.ini
# Unpin all test dependencies to make installation happen
sed -r -i 's/(pytest)<7\.0\.0/\1/' tox.ini
sed -r -i 's/(Werkzeug)<2\.1\.0/\1/' tox.ini
sed -r -i 's/(gevent)>=22\.10\.0, <22\.11\.0/\1/' tox.ini
sed -r -i 's/(anyio)<4\.0\.0/\1/' tox.ini
# newrelic is unpackaged yet, remove it
sed -r -i '/(newrelic)/d' tox.ini
%generate_buildrequires
%pyproject_buildrequires -x %{extras_csv} -e %{toxenvs_csv}
%build
# Re-generate the protobuf bindings for compatibility with the packaged
# protobuf version.
pushd tests/integrations/grpc/protos/
protoc --python_out="${PWD}" grpc_test_service.proto
popd
%pyproject_wheel
%install
%pyproject_install
%pyproject_save_files sentry_sdk
%check
# Import check
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.anthropic" # no_anthropic
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.ariadne" # no_ariadne
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.arq" # no_arq
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.celery_redbeat" # no_celery_redbeat
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.chalice" # no_chalice
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.clickhouse_driver" # no_clickhouse_driver
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.cohere" # no_cohere
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.gql" # no_gql
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.huey" # no_huey
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.huggingface_hub" # no_huggingface_hub
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.langchain" # no_langchain
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.loguru" # no_loguru
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.openai" # no_openai
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.quart" # no_quart
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.sanic" # no_sanic
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.starlite" # no_starlite
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.strawberry" # no_strawberry
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.trytond" # no_trytond
%if %{without tests}
skip_import_check="${skip_import_check-} -e sentry_sdk.db.explain_plan.sqlalchemy"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.aiohttp"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.asyncpg"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.boto3"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.bottle"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.celery*"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.django*"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.executing"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.falcon"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.fastapi"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.flask"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.graphene"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.grpc*"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.httpx"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.opentelemetry*"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.pure_eval"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.pymongo"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.pyramid"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.rq"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.sqlalchemy"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.starlette"
skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.tornado"
%endif
%{!?with_opentelemetry_experimental:skip_import_check="${skip_import_check-} -e sentry_sdk.integrations.opentelemetry.integration"}
%pyproject_check_import ${skip_import_check}
%if %{with tests}
# Tests
# Deselect/ignore:
# not in tox.ini, probably broken
ignore="${ignore-} --ignore=tests/integrations/wsgi"
# python 2 only
deselect="${deselect-} --deselect=tests/integrations/threading/test_threading.py::test_wrapper_attributes_no_qualname"
# python 3.7 only
ignore="${ignore-} --ignore=tests/integrations/gcp"
# require network
%if %{without network_tests}
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_cache_spans_decorator"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_cache_spans_disabled_decorator"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_cache_spans_disabled_middleware"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_cache_spans_disabled_templatetag"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_cache_spans_middleware"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_cache_spans_templatetag"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_db_connection_span_data"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_django_connect_breadcrumbs"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_django_connect_trace"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_queryset_repr"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_response_trace"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_sql_dict_query_params"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_sql_psycopg2_placeholders"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_sql_psycopg2_string_composition"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_sql_queries"
deselect="${deselect-} --deselect=tests/integrations/django/test_basic.py::test_user_captured"
deselect="${deselect-} --deselect=tests/integrations/django/test_data_scrubbing.py::test_scrub_django_custom_session_cookies_filtered"
deselect="${deselect-} --deselect=tests/integrations/django/test_data_scrubbing.py::test_scrub_django_session_cookies_filtered"
deselect="${deselect-} --deselect=tests/integrations/django/test_data_scrubbing.py::test_scrub_django_session_cookies_removed"
deselect="${deselect-} --deselect=tests/integrations/django/test_db_query_data.py"
deselect="${deselect-} --deselect=tests/integrations/requests/test_requests.py::test_omit_url_data_if_parsing_fails"
deselect="${deselect-} --deselect=tests/integrations/requests/test_requests.py::test_crumb_capture"
ignore="${ignore-} --ignore=tests/integrations/boto3"
ignore="${ignore-} --ignore=tests/integrations/httpx"
ignore="${ignore-} --ignore=tests/integrations/socket"
%endif
# TODO: investigate
ignore="${ignore-} --ignore=tests/integrations/fastapi"
# require credentials
ignore="${ignore-} --ignore=tests/integrations/aws_lambda/"
# require a local PostgreSQL instance running
ignore="${ignore-} --ignore=tests/integrations/asyncpg"
# testing suite relies on the test to be executed in clean env
deselect="${deselect-} --deselect=tests/test_basics.py::test_auto_enabling_integrations_catches_import_error"
# currently will always fail: there is no env vars or git repository
deselect="${deselect-} --deselect=tests/test_utils.py::test_default_release"
# tests cannot be run during Fedora build because of the version of pytest:
# https://github.com/pytest-dev/pytest/issues/9621
# https://github.com/pytest-dev/pytest-forked/issues/67
deselect="${deselect-} --deselect=tests/utils/test_contextvars.py"
# TODO: relies on django testing, incompatible with pytest macro (see above)
deselect="${deselect-} --deselect=tests/test_transport.py::test_transport_works"
ignore="${ignore-} --ignore=tests/integrations/django"
# no_fakeredis
deselect="${deselect-} --deselect=tests/test_basics.py::test_redis_disabled_when_not_installed"
ignore="${ignore-} --ignore=tests/integrations/redis"
ignore="${ignore-} --ignore=tests/integrations/rq"
# graphene is too old (min version: 3.3)
ignore="${ignore-} --ignore=tests/integrations/graphene"
# mockupdb is unpackaged because it appears unmaintained
ignore="${ignore-} --ignore=tests/integrations/pymongo"
# protobuf is too old
ignore="${ignore-} --ignore=tests/integrations/grpc"
# werkzeug is too new (version < 2.1.0)
ignore="${ignore-} --ignore=tests/integrations/pyramid"
# newrelic is unpackaged yet
deselect="${deselect-} --deselect=tests/integrations/celery/test_celery.py::test_newrelic_interference"
# werkzeug in Fedora 38 is too new, see: https://github.com/getsentry/sentry-python/issues/1398
ignore="${ignore-} --ignore=tests/integrations/bottle"
ignore="${ignore-} --ignore=tests/integrations/flask"
ignore="${ignore-} %{!?with_opentelemetry_experimental:--ignore=tests/integrations/opentelemetry/test_experimental.py}"
defined_toxenvs=$(echo "%toxenvs_excluded" "%toxenvs" | xargs -n1 | sort -u)
tox_ini_toxenvs=$(cat tox.ini | sed -r -n 's/[[:blank:]]*(.*):[[:blank:]]*TESTPATH=.*/%{default_toxenv}-\1/p' | xargs -n1 | sort -u)
diff <(echo "$defined_toxenvs") <(echo "$tox_ini_toxenvs")
# TODO:
# sqlalchemy installed during tests causes many failures.
# It is used by sentry_sdk/db/explain_plan/sqlalchemy.py and is optional, drop it.
# Test sqlalchemy separately.
%tox -e %{default_toxenv}-sqlalchemy -- -- ${deselect-} ${ignore-}
# Make `import sqlalchemy` fail
echo "raise ImportError()" > sqlalchemy.py
%define toxenvs_csv_without_sqlalchemy %{expand:%(echo %{toxenvs_csv} | sed "s/%{default_toxenv}-sqlalchemy,//")}
# TODO:
# By some reason, some tests fail because of django plugin, run them separately.
%define toxenvs_csv_without_django_and_sqlalchemy %{expand:%(echo %{toxenvs_csv} | sed "s/%{default_toxenv}-django,//")}
tests_no_django="test_link_trace_context_to_error_event or test_on_end_sentry_span or test_on_end_sentry_transaction or test_pruning_old_spans_on_end or test_transaction_style or test_user_information_error or test_circular_references"
%tox -e %{toxenvs_csv_without_django_and_sqlalchemy} -- -- -p no:django ${deselect-} ${ignore-} tests/integrations/opentelemetry tests/integrations/starlette/test_starlette.py tests/integrations/threading/test_threading.py -k "$tests_no_django"
%tox -e %{toxenvs_csv_without_sqlalchemy} -- -- ${deselect-} ${ignore-} -k "not ($tests_no_django)"
%endif
%files -n python3-sentry-sdk -f %{pyproject_files}
%doc README.md
%changelog
%autochangelog