Skip to content

Commit

Permalink
chore(deprecation): python 3.7 support (#11412)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufede authored Nov 22, 2024
1 parent 688fa7f commit 9f7551f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ddtrace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import sys
import warnings


LOADED_MODULES = frozenset(sys.modules.keys())

from ddtrace.internal.module import ModuleWatchdog


ModuleWatchdog.install()

# Ensure we capture references to unpatched modules as early as possible
Expand All @@ -16,18 +18,21 @@

from .settings import _config as config


# Enable telemetry writer and excepthook as early as possible to ensure we capture any exceptions from initialization
import ddtrace.internal.telemetry # noqa: E402

from ._monkey import patch # noqa: E402
from ._monkey import patch_all # noqa: E402
from .internal.compat import PYTHON_VERSION_INFO # noqa: E402
from .internal.utils.deprecations import DDTraceDeprecationWarning # noqa: E402
from .pin import Pin # noqa: E402
from ddtrace._trace.span import Span # noqa: E402
from ddtrace._trace.tracer import Tracer # noqa: E402
from ddtrace.vendor import debtcollector
from .version import get_version # noqa: E402


# DEV: Import deprecated tracer module in order to retain side-effect of package
# initialization, which added this module to sys.modules. We catch deprecation
# warnings as this is only to retain a side effect of the package
Expand Down Expand Up @@ -71,3 +76,19 @@ def __getattr__(name):
return globals()[name]

raise AttributeError("%s has no attribute %s", __name__, name)


def check_supported_python_version():
if PYTHON_VERSION_INFO < (3, 8):
deprecation_message = (
"Support for ddtrace with Python version %d.%d is deprecated and will be removed in 3.0.0."
)
if PYTHON_VERSION_INFO < (3, 7):
deprecation_message = "Support for ddtrace with Python version %d.%d was removed in 2.0.0."
debtcollector.deprecate(
(deprecation_message % (PYTHON_VERSION_INFO[0], PYTHON_VERSION_INFO[1])),
category=DDTraceDeprecationWarning,
)


check_supported_python_version()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
deprecations:
- |
Python 3.7 support is deprecated and will be removed in 3.0
1 change: 1 addition & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ def test_logging_during_tracer_init_succeeds_when_debug_logging_and_logs_injecti
), "stderr should not contain any exception logs"


@pytest.mark.skipif(sys.version_info < (3, 8), reason="Python 3.7 deprecation warning")
def test_no_warnings_when_Wall():
env = os.environ.copy()
# Have to disable sqlite3 as coverage uses it on process shutdown
Expand Down
29 changes: 29 additions & 0 deletions tests/internal/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import os
from pathlib import Path
import sys
import warnings
from warnings import warn

import mock
import pytest

from ddtrace import check_supported_python_version
from ddtrace.internal.coverage.code import ModuleCodeCollector
from ddtrace.internal.module import ModuleWatchdog
from ddtrace.internal.module import origin
Expand Down Expand Up @@ -421,6 +423,7 @@ def ns_hook(module):
ModuleWatchdog.uninstall()


@pytest.mark.skipif(sys.version_info < (3, 8), reason="Python 3.7 deprecation warning")
@pytest.mark.subprocess(
ddtrace_run=True,
env=dict(
Expand Down Expand Up @@ -588,3 +591,29 @@ def __getattr__(name):
"ddtrace.contrib.pytest_bdd.plugin",
]
)


@pytest.mark.skipif(sys.version_info >= (3, 8), reason="Python >= 3.8 is supported")
def test_deprecated_python_version():
# Test that the deprecation warning for Python 3.7 and below is printed in unsupported Python versions.
with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
# Trigger a warning.
check_supported_python_version()
# Verify some things
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert "Support for ddtrace with Python version" in str(w[-1].message)


@pytest.mark.skipif(sys.version_info < (3, 8), reason="Python < 3.8 is unsupported")
def test_non_deprecated_python_version():
# Test that the deprecation warning for Python 3.7 and below is not printed in supported Python versions.
with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
# Trigger a warning.
check_supported_python_version()
# Verify some things
assert len(w) == 0
2 changes: 2 additions & 0 deletions tests/profiling/test_profiler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import sys
import time

import mock
Expand Down Expand Up @@ -422,6 +423,7 @@ def test_profiler_serverless(monkeypatch):
assert p.tags["functionname"] == "foobar"


@pytest.mark.skipif(sys.version_info < (3, 8), reason="Python 3.7 deprecation warning")
@pytest.mark.subprocess()
def test_profiler_ddtrace_deprecation():
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/tracer/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import random
import string
import sys
import threading
from unittest import TestCase

Expand Down Expand Up @@ -871,6 +872,7 @@ def test_json_encoder_traces_bytes():
assert "\x80span.b" == span_c["name"]


@pytest.mark.skipif(sys.version_info < (3, 8), reason="Python 3.7 deprecation warning")
@pytest.mark.subprocess(env={"DD_TRACE_API_VERSION": "v0.3"})
def test_v03_trace_api_deprecation():
import warnings
Expand Down

0 comments on commit 9f7551f

Please sign in to comment.