diff --git a/ddtrace/contrib/aiobotocore/__init__.py b/ddtrace/contrib/aiobotocore/__init__.py index 8869c4647d1..47f16f51796 100644 --- a/ddtrace/contrib/aiobotocore/__init__.py +++ b/ddtrace/contrib/aiobotocore/__init__.py @@ -25,22 +25,19 @@ Default: ``False`` """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["aiobotocore.client"] +# Required to allow users to import from `ddtrace.contrib.aiobotocore.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.aiobotocore.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.aiobotocore.patch import get_version - from ddtrace.contrib.internal.aiobotocore.patch import patch +# Expose public methods +from ddtrace.contrib.internal.aiobotocore.patch import get_version +from ddtrace.contrib.internal.aiobotocore.patch import patch - __all__ = ["patch", "get_version"] + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/aiohttp/__init__.py b/ddtrace/contrib/aiohttp/__init__.py index 7ff17c21ec0..2bd88e734de 100644 --- a/ddtrace/contrib/aiohttp/__init__.py +++ b/ddtrace/contrib/aiohttp/__init__.py @@ -84,24 +84,21 @@ async def home_handler(request): :ref:`All HTTP tags ` are supported for this integration. """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["aiohttp"] +# Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.aiohttp.middlewares import trace_app - from ddtrace.contrib.internal.aiohttp.patch import get_version +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.aiohttp.middlewares import trace_app +from ddtrace.contrib.internal.aiohttp.patch import get_version - # Expose public methods - from ddtrace.contrib.internal.aiohttp.patch import patch - from ddtrace.contrib.internal.aiohttp.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.aiohttp.patch import patch +from ddtrace.contrib.internal.aiohttp.patch import unpatch - __all__ = ["patch", "unpatch", "trace_app", "get_version"] + +__all__ = ["patch", "unpatch", "trace_app", "get_version"] diff --git a/ddtrace/contrib/aiohttp_jinja2/__init__.py b/ddtrace/contrib/aiohttp_jinja2/__init__.py index fe268b6dc54..ef9c76f3da8 100644 --- a/ddtrace/contrib/aiohttp_jinja2/__init__.py +++ b/ddtrace/contrib/aiohttp_jinja2/__init__.py @@ -13,22 +13,19 @@ from ddtrace import patch patch(aiohttp_jinja2=True) """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["aiohttp_jinja2"] +# Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.aiohttp_jinja2.patch import get_version - from ddtrace.contrib.internal.aiohttp_jinja2.patch import patch - from ddtrace.contrib.internal.aiohttp_jinja2.patch import unpatch +from ddtrace.contrib.internal.aiohttp_jinja2.patch import get_version +from ddtrace.contrib.internal.aiohttp_jinja2.patch import patch +from ddtrace.contrib.internal.aiohttp_jinja2.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/aiomysql/__init__.py b/ddtrace/contrib/aiomysql/__init__.py index 485eb690fed..98f78d3f3ab 100644 --- a/ddtrace/contrib/aiomysql/__init__.py +++ b/ddtrace/contrib/aiomysql/__init__.py @@ -36,22 +36,18 @@ await cur.execute("SELECT 6*7 AS the_answer;") """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly +import warnings as _w -required_modules = ["aiomysql"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.aiomysql.patch import get_version +from ddtrace.contrib.internal.aiomysql.patch import patch +from ddtrace.contrib.internal.aiomysql.patch import unpatch - from ddtrace.contrib.internal.aiomysql.patch import get_version - from ddtrace.contrib.internal.aiomysql.patch import patch - from ddtrace.contrib.internal.aiomysql.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/aiopg/__init__.py b/ddtrace/contrib/aiopg/__init__.py index 481f9133e57..11a572d12ed 100644 --- a/ddtrace/contrib/aiopg/__init__.py +++ b/ddtrace/contrib/aiopg/__init__.py @@ -15,21 +15,18 @@ # Use a pin to specify metadata related to this connection Pin.override(db, service='postgres-users') """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["aiopg"] +# Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.aiopg.patch import get_version - from ddtrace.contrib.internal.aiopg.patch import patch +from ddtrace.contrib.internal.aiopg.patch import get_version +from ddtrace.contrib.internal.aiopg.patch import patch - __all__ = ["patch", "get_version"] + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/aioredis/__init__.py b/ddtrace/contrib/aioredis/__init__.py index 32449af6b6f..2bc3669a340 100644 --- a/ddtrace/contrib/aioredis/__init__.py +++ b/ddtrace/contrib/aioredis/__init__.py @@ -69,22 +69,17 @@ myaioredis = aioredis.Aioredis() Pin.override(myaioredis, service="myaioredis") """ -from ddtrace.internal.utils.importlib import require_modules # noqa:E402 +import warnings as _w # noqa: E402 -required_modules = ["aioredis"] +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + # Required to allow users to import from `ddtrace.contrib.aioredis.patch` directly + from . import patch as _ # noqa: F401, I001 -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.aioredis.patch` directly - import warnings as _w +from ddtrace.contrib.internal.aioredis.patch import get_version # noqa: E402 +from ddtrace.contrib.internal.aioredis.patch import patch # noqa: E402 +from ddtrace.contrib.internal.aioredis.patch import unpatch # noqa: E402 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.aioredis.patch import get_version - from ddtrace.contrib.internal.aioredis.patch import patch - from ddtrace.contrib.internal.aioredis.patch import unpatch - - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/algoliasearch/__init__.py b/ddtrace/contrib/algoliasearch/__init__.py index 4b172bca67a..b594d6238cc 100644 --- a/ddtrace/contrib/algoliasearch/__init__.py +++ b/ddtrace/contrib/algoliasearch/__init__.py @@ -22,22 +22,18 @@ .. __: https://www.algolia.com """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.algoliasearch.patch` directly +import warnings as _w -required_modules = ["algoliasearch", "algoliasearch.version"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.algoliasearch.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.algoliasearch.patch import get_version +from ddtrace.contrib.internal.algoliasearch.patch import patch +from ddtrace.contrib.internal.algoliasearch.patch import unpatch - from ddtrace.contrib.internal.algoliasearch.patch import get_version - from ddtrace.contrib.internal.algoliasearch.patch import patch - from ddtrace.contrib.internal.algoliasearch.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/anthropic/__init__.py b/ddtrace/contrib/anthropic/__init__.py index 7a55e6947c9..c43ee4bb43c 100644 --- a/ddtrace/contrib/anthropic/__init__.py +++ b/ddtrace/contrib/anthropic/__init__.py @@ -80,22 +80,19 @@ Pin.override(anthropic, service="my-anthropic-service") """ # noqa: E501 -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["anthropic"] +# Required to allow users to import from `ddtrace.contrib.anthropic.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.anthropic.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.anthropic.patch import get_version - from ddtrace.contrib.internal.anthropic.patch import patch - from ddtrace.contrib.internal.anthropic.patch import unpatch +from ddtrace.contrib.internal.anthropic.patch import get_version +from ddtrace.contrib.internal.anthropic.patch import patch +from ddtrace.contrib.internal.anthropic.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/aredis/__init__.py b/ddtrace/contrib/aredis/__init__.py index 17c1408caa5..1af4c5db664 100644 --- a/ddtrace/contrib/aredis/__init__.py +++ b/ddtrace/contrib/aredis/__init__.py @@ -66,21 +66,17 @@ async def example(): await client.get("my-key") """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.aredis.patch` directly +import warnings as _w -required_modules = ["aredis", "aredis.client"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.aredis.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.aredis.patch import get_version +from ddtrace.contrib.internal.aredis.patch import patch - from ddtrace.contrib.internal.aredis.patch import get_version - from ddtrace.contrib.internal.aredis.patch import patch - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/asgi/__init__.py b/ddtrace/contrib/asgi/__init__.py index 0bfcd1ade5b..8c30f4e609e 100644 --- a/ddtrace/contrib/asgi/__init__.py +++ b/ddtrace/contrib/asgi/__init__.py @@ -55,18 +55,10 @@ def handle_request(scope, send): .. __: https://asgi.readthedocs.io/ """ -from ddtrace.internal.utils.importlib import require_modules +from ddtrace.contrib.internal.asgi.middleware import TraceMiddleware +from ddtrace.contrib.internal.asgi.middleware import get_version +from ddtrace.contrib.internal.asgi.middleware import span_from_scope -required_modules = [] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.asgi.patch` directly - from . import middleware as _ # noqa: F401, I001 - - from ddtrace.contrib.internal.asgi.middleware import TraceMiddleware - from ddtrace.contrib.internal.asgi.middleware import get_version - from ddtrace.contrib.internal.asgi.middleware import span_from_scope - - __all__ = ["TraceMiddleware", "span_from_scope", "get_version"] +__all__ = ["TraceMiddleware", "span_from_scope", "get_version"] diff --git a/ddtrace/contrib/asyncio/__init__.py b/ddtrace/contrib/asyncio/__init__.py index 5ff3a69adee..205935222fb 100644 --- a/ddtrace/contrib/asyncio/__init__.py +++ b/ddtrace/contrib/asyncio/__init__.py @@ -2,29 +2,24 @@ This integration provides context management for tracing the execution flow of concurrent execution of ``asyncio.Task``. """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.asyncio.patch` directly +# Expose public methods +import warnings as _w # noqa:E402 -required_modules = ["asyncio"] +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 +from ddtrace._trace.provider import DefaultContextProvider +from ddtrace.contrib.internal.asyncio.helpers import ensure_future +from ddtrace.contrib.internal.asyncio.helpers import run_in_executor +from ddtrace.contrib.internal.asyncio.helpers import set_call_context +from ddtrace.contrib.internal.asyncio.patch import get_version +from ddtrace.contrib.internal.asyncio.patch import patch +from ddtrace.contrib.internal.asyncio.patch import unpatch # noqa: F401 -with require_modules(required_modules) as missing_modules: - if not missing_modules: - from ddtrace._trace.provider import DefaultContextProvider - context_provider = DefaultContextProvider() +context_provider = DefaultContextProvider() - # Required to allow users to import from `ddtrace.contrib.asyncio.patch` directly - # Expose public methods - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.asyncio.helpers import ensure_future - from ddtrace.contrib.internal.asyncio.helpers import run_in_executor - from ddtrace.contrib.internal.asyncio.helpers import set_call_context - from ddtrace.contrib.internal.asyncio.patch import get_version - from ddtrace.contrib.internal.asyncio.patch import patch - from ddtrace.contrib.internal.asyncio.patch import unpatch # noqa: F401 - - __all__ = ["context_provider", "set_call_context", "ensure_future", "run_in_executor", "patch", "get_version"] +__all__ = ["context_provider", "set_call_context", "ensure_future", "run_in_executor", "patch", "get_version"] diff --git a/ddtrace/contrib/asyncpg/__init__.py b/ddtrace/contrib/asyncpg/__init__.py index 21cc9b613a9..c8e56511469 100644 --- a/ddtrace/contrib/asyncpg/__init__.py +++ b/ddtrace/contrib/asyncpg/__init__.py @@ -43,22 +43,19 @@ conn = asyncpg.connect("postgres://localhost:5432") Pin.override(conn, service="custom-service") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["asyncpg"] +# Required to allow users to import from `ddtrace.contrib.asyncpg.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.asyncpg.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.asyncpg.patch import get_version - from ddtrace.contrib.internal.asyncpg.patch import patch - from ddtrace.contrib.internal.asyncpg.patch import unpatch +from ddtrace.contrib.internal.asyncpg.patch import get_version +from ddtrace.contrib.internal.asyncpg.patch import patch +from ddtrace.contrib.internal.asyncpg.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/avro/__init__.py b/ddtrace/contrib/avro/__init__.py index 6ca7f3c9847..328704bbfea 100644 --- a/ddtrace/contrib/avro/__init__.py +++ b/ddtrace/contrib/avro/__init__.py @@ -15,15 +15,9 @@ ~~~~~~~~~~~~~ """ -from ...internal.utils.importlib import require_modules +# Expose public methods +from ..internal.avro.patch import get_version +from ..internal.avro.patch import patch -required_modules = ["avro"] - -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Expose public methods - from ..internal.avro.patch import get_version - from ..internal.avro.patch import patch - - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/boto/__init__.py b/ddtrace/contrib/boto/__init__.py index e17db53e5ae..6b967b28b2b 100644 --- a/ddtrace/contrib/boto/__init__.py +++ b/ddtrace/contrib/boto/__init__.py @@ -28,21 +28,17 @@ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.boto.patch` directly +import warnings as _w -required_modules = ["boto.connection"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.boto.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.boto.patch import get_version +from ddtrace.contrib.internal.boto.patch import patch - from ddtrace.contrib.internal.boto.patch import get_version - from ddtrace.contrib.internal.boto.patch import patch - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/botocore/__init__.py b/ddtrace/contrib/botocore/__init__.py index 143ef70b9d7..60b01d39839 100644 --- a/ddtrace/contrib/botocore/__init__.py +++ b/ddtrace/contrib/botocore/__init__.py @@ -153,22 +153,17 @@ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.botocore.patch` directly +import warnings as _w -required_modules = ["botocore.client"] +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.botocore.patch` directly - import warnings as _w +from ddtrace.contrib.internal.botocore.patch import get_version +from ddtrace.contrib.internal.botocore.patch import patch +from ddtrace.contrib.internal.botocore.patch import patch_submodules - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.botocore.patch import get_version - from ddtrace.contrib.internal.botocore.patch import patch - from ddtrace.contrib.internal.botocore.patch import patch_submodules - - __all__ = ["patch", "patch_submodules", "get_version"] +__all__ = ["patch", "patch_submodules", "get_version"] diff --git a/ddtrace/contrib/bottle/__init__.py b/ddtrace/contrib/bottle/__init__.py index 1391f1cd667..448c709b952 100644 --- a/ddtrace/contrib/bottle/__init__.py +++ b/ddtrace/contrib/bottle/__init__.py @@ -33,22 +33,18 @@ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.bottle.patch` directly +import warnings as _w -required_modules = ["bottle"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.bottle.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.bottle.patch import get_version +from ddtrace.contrib.internal.bottle.patch import patch +from ddtrace.contrib.internal.bottle.trace import TracePlugin - from ddtrace.contrib.internal.bottle.patch import get_version - from ddtrace.contrib.internal.bottle.patch import patch - from ddtrace.contrib.internal.bottle.trace import TracePlugin - __all__ = ["TracePlugin", "patch", "get_version"] +__all__ = ["TracePlugin", "patch", "get_version"] diff --git a/ddtrace/contrib/cassandra/__init__.py b/ddtrace/contrib/cassandra/__init__.py index 9c3c1d7de6a..1d0b6ad0afd 100644 --- a/ddtrace/contrib/cassandra/__init__.py +++ b/ddtrace/contrib/cassandra/__init__.py @@ -21,22 +21,19 @@ session = cluster.connect("my_keyspace") session.execute("select id from my_table limit 10;") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["cassandra.cluster"] +# Required to allow users to import from `ddtrace.contrib.cassandra.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.cassandra.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.cassandra.patch import patch - from ddtrace.contrib.internal.cassandra.session import get_version +# Expose public methods +from ddtrace.contrib.internal.cassandra.patch import patch +from ddtrace.contrib.internal.cassandra.session import get_version - __all__ = ["patch", "get_version"] + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/celery/__init__.py b/ddtrace/contrib/celery/__init__.py index 7b63089e206..83ad7a870a3 100644 --- a/ddtrace/contrib/celery/__init__.py +++ b/ddtrace/contrib/celery/__init__.py @@ -51,25 +51,22 @@ def run(self): Default: ``'celery-worker'`` """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["celery"] +# Required to allow users to import from `ddtrace.contrib.celery.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.celery.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.celery.app import patch_app - from ddtrace.contrib.internal.celery.app import unpatch_app - from ddtrace.contrib.internal.celery.patch import get_version - from ddtrace.contrib.internal.celery.patch import patch - from ddtrace.contrib.internal.celery.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.celery.app import patch_app +from ddtrace.contrib.internal.celery.app import unpatch_app +from ddtrace.contrib.internal.celery.patch import get_version +from ddtrace.contrib.internal.celery.patch import patch +from ddtrace.contrib.internal.celery.patch import unpatch - __all__ = ["patch", "patch_app", "unpatch", "unpatch_app", "get_version"] + +__all__ = ["patch", "patch_app", "unpatch", "unpatch_app", "get_version"] diff --git a/ddtrace/contrib/cherrypy/__init__.py b/ddtrace/contrib/cherrypy/__init__.py index ff072fa426f..efd1210db6c 100644 --- a/ddtrace/contrib/cherrypy/__init__.py +++ b/ddtrace/contrib/cherrypy/__init__.py @@ -53,14 +53,9 @@ def index(self): cherrypy.quickstart(HelloWorld()) """ -from ddtrace.internal.utils.importlib import require_modules +from ddtrace.contrib.internal.cherrypy.middleware import TraceMiddleware +from ddtrace.contrib.internal.cherrypy.middleware import get_version -required_modules = ["cherrypy"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - from ddtrace.contrib.internal.cherrypy.middleware import TraceMiddleware - from ddtrace.contrib.internal.cherrypy.middleware import get_version - - __all__ = ["TraceMiddleware", "get_version"] +__all__ = ["TraceMiddleware", "get_version"] diff --git a/ddtrace/contrib/consul/__init__.py b/ddtrace/contrib/consul/__init__.py index 8b7498c80d3..a6317d0bce0 100644 --- a/ddtrace/contrib/consul/__init__.py +++ b/ddtrace/contrib/consul/__init__.py @@ -19,23 +19,19 @@ Pin.override(client, service='consul-kv') """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.consul.patch` directly +import warnings as _w -required_modules = ["consul"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.consul.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.consul.patch import get_version +from ddtrace.contrib.internal.consul.patch import patch +from ddtrace.contrib.internal.consul.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.consul.patch import get_version - from ddtrace.contrib.internal.consul.patch import patch - from ddtrace.contrib.internal.consul.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/coverage/__init__.py b/ddtrace/contrib/coverage/__init__.py index b32d27ebff4..6ae090e3fe0 100644 --- a/ddtrace/contrib/coverage/__init__.py +++ b/ddtrace/contrib/coverage/__init__.py @@ -15,26 +15,21 @@ Note: Coverage.py instrumentation is only enabled if `pytest` or `unittest` instrumentation is enabled. """ -from ddtrace.internal.logger import get_logger -from ddtrace.internal.utils.importlib import require_modules - +# Required to allow users to import from `ddtrace.contrib.internal.coverage.patch` directly +import warnings as _w # noqa:E402 -required_modules = ["coverage"] -log = get_logger(__name__) +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.internal.coverage.patch` directly - import warnings as _w +# Expose public methods +from ddtrace.contrib.internal.coverage.patch import get_version +from ddtrace.contrib.internal.coverage.patch import patch +from ddtrace.contrib.internal.coverage.patch import unpatch +from ddtrace.internal.logger import get_logger - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.coverage.patch import get_version - from ddtrace.contrib.internal.coverage.patch import patch - from ddtrace.contrib.internal.coverage.patch import unpatch +log = get_logger(__name__) - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/django/__init__.py b/ddtrace/contrib/django/__init__.py index 55a867ed560..2eeea57b2c6 100644 --- a/ddtrace/contrib/django/__init__.py +++ b/ddtrace/contrib/django/__init__.py @@ -201,25 +201,20 @@ .. __: https://www.djangoproject.com/ """ # noqa: E501 -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.django.patch` directly +import warnings as _w -required_modules = ["django"] +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.django.patch` directly - import warnings as _w +# Expose public methods +from ddtrace.contrib.internal.django.patch import get_version +from ddtrace.contrib.internal.django.patch import patch +from ddtrace.contrib.internal.django.patch import patch as _patch +from ddtrace.contrib.internal.django.patch import unpatch - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.django.patch import get_version - from ddtrace.contrib.internal.django.patch import patch - from ddtrace.contrib.internal.django.patch import patch as _patch - from ddtrace.contrib.internal.django.patch import unpatch - - __all__ = ["patch", "unpatch", "_patch", "get_version"] +__all__ = ["patch", "unpatch", "_patch", "get_version"] diff --git a/ddtrace/contrib/dogpile_cache/__init__.py b/ddtrace/contrib/dogpile_cache/__init__.py index 6e796e93320..63898aa4a5a 100644 --- a/ddtrace/contrib/dogpile_cache/__init__.py +++ b/ddtrace/contrib/dogpile_cache/__init__.py @@ -36,23 +36,20 @@ def hello(name): .. __: https://dogpilecache.sqlalchemy.org/ """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["dogpile.cache"] +# Required to allow users to import from `ddtrace.contrib.dogpile_cache.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.dogpile_cache.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.dogpile_cache.patch import get_version - from ddtrace.contrib.internal.dogpile_cache.patch import patch - from ddtrace.contrib.internal.dogpile_cache.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.dogpile_cache.patch import get_version +from ddtrace.contrib.internal.dogpile_cache.patch import patch +from ddtrace.contrib.internal.dogpile_cache.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/dramatiq/__init__.py b/ddtrace/contrib/dramatiq/__init__.py index ebf2c355743..2e5f37c4cba 100644 --- a/ddtrace/contrib/dramatiq/__init__.py +++ b/ddtrace/contrib/dramatiq/__init__.py @@ -28,23 +28,20 @@ def my_other_task(content): ddtrace-run python app.py """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["dramatiq"] +# Required to allow users to import from `ddtrace.contrib.dramatiq.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.dramatiq.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.dramatiq.patch import get_version - from ddtrace.contrib.internal.dramatiq.patch import patch - from ddtrace.contrib.internal.dramatiq.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.dramatiq.patch import get_version +from ddtrace.contrib.internal.dramatiq.patch import patch +from ddtrace.contrib.internal.dramatiq.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/falcon/__init__.py b/ddtrace/contrib/falcon/__init__.py index e8d2038ccc1..c54b58dbd9c 100644 --- a/ddtrace/contrib/falcon/__init__.py +++ b/ddtrace/contrib/falcon/__init__.py @@ -44,21 +44,18 @@ def on_falcon_request(span, request, response): :ref:`Headers tracing ` is supported for this integration. """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["falcon"] +# Required to allow users to import from `ddtrace.contrib.falcon.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.falcon.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.falcon.middleware import TraceMiddleware - from ddtrace.contrib.internal.falcon.patch import get_version - from ddtrace.contrib.internal.falcon.patch import patch +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.falcon.middleware import TraceMiddleware +from ddtrace.contrib.internal.falcon.patch import get_version +from ddtrace.contrib.internal.falcon.patch import patch - __all__ = ["TraceMiddleware", "patch", "get_version"] + +__all__ = ["TraceMiddleware", "patch", "get_version"] diff --git a/ddtrace/contrib/fastapi/__init__.py b/ddtrace/contrib/fastapi/__init__.py index 9931a2d3ea6..df989abf766 100644 --- a/ddtrace/contrib/fastapi/__init__.py +++ b/ddtrace/contrib/fastapi/__init__.py @@ -50,23 +50,20 @@ config.fastapi['request_span_name'] = 'custom-request-span-name' """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["fastapi"] +# Required to allow users to import from `ddtrace.contrib.fastapi.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.fastapi.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.fastapi.patch import get_version - from ddtrace.contrib.internal.fastapi.patch import patch - from ddtrace.contrib.internal.fastapi.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.fastapi.patch import get_version +from ddtrace.contrib.internal.fastapi.patch import patch +from ddtrace.contrib.internal.fastapi.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/flask/__init__.py b/ddtrace/contrib/flask/__init__.py index 47226eed5c6..22e90ffb604 100644 --- a/ddtrace/contrib/flask/__init__.py +++ b/ddtrace/contrib/flask/__init__.py @@ -96,21 +96,17 @@ def index(): """ -from ddtrace.internal.utils.importlib import require_modules +# DEV: We do this so we can `@mock.patch('ddtrace.contrib.flask._patch.')` in tests +import warnings as _w -required_modules = ["flask"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # DEV: We do this so we can `@mock.patch('ddtrace.contrib.flask._patch.')` in tests - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 +from ddtrace.contrib.internal.flask.patch import get_version +from ddtrace.contrib.internal.flask.patch import patch +from ddtrace.contrib.internal.flask.patch import unpatch - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.flask.patch import get_version - from ddtrace.contrib.internal.flask.patch import patch - from ddtrace.contrib.internal.flask.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/flask_cache/__init__.py b/ddtrace/contrib/flask_cache/__init__.py index 1919f55efb5..f11b006f723 100644 --- a/ddtrace/contrib/flask_cache/__init__.py +++ b/ddtrace/contrib/flask_cache/__init__.py @@ -44,18 +44,9 @@ def counter(): """ -from ddtrace.internal.utils.importlib import require_modules +# Expose public methods +from ddtrace.contrib.internal.flask_cache.tracers import get_traced_cache +from ddtrace.contrib.internal.flask_cache.tracers import get_version -required_modules = ["flask_cache", "flask_caching"] - -with require_modules(required_modules) as missing_modules: - if len(missing_modules) < len(required_modules): - # Required to allow users to import from `ddtrace.contrib.aiohttp.patch` directly - from . import tracers as _ # noqa: F401, I001 - - # Expose public methods - from ddtrace.contrib.internal.flask_cache.tracers import get_traced_cache - from ddtrace.contrib.internal.flask_cache.tracers import get_version - - __all__ = ["get_traced_cache", "get_version"] +__all__ = ["get_traced_cache", "get_version"] diff --git a/ddtrace/contrib/freezegun/__init__.py b/ddtrace/contrib/freezegun/__init__.py index 7e2df3c557c..8c072c74d5a 100644 --- a/ddtrace/contrib/freezegun/__init__.py +++ b/ddtrace/contrib/freezegun/__init__.py @@ -13,16 +13,10 @@ The freezegun integration is not configurable, but may be disabled using DD_PATCH_MODULES=freezegun:false . """ -from ...internal.utils.importlib import require_modules +# Expose public methods +from ..internal.freezegun.patch import get_version +from ..internal.freezegun.patch import patch +from ..internal.freezegun.patch import unpatch -required_modules = ["freezegun"] - -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Expose public methods - from ..internal.freezegun.patch import get_version - from ..internal.freezegun.patch import patch - from ..internal.freezegun.patch import unpatch - - __all__ = ["get_version", "patch", "unpatch"] +__all__ = ["get_version", "patch", "unpatch"] diff --git a/ddtrace/contrib/futures/__init__.py b/ddtrace/contrib/futures/__init__.py index c589912c07a..1ba8741ebe9 100644 --- a/ddtrace/contrib/futures/__init__.py +++ b/ddtrace/contrib/futures/__init__.py @@ -16,27 +16,24 @@ from ddtrace import patch patch(futures=True) """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["concurrent.futures"] +# Required to allow users to import from `ddtrace.contrib.futures.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.futures.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.futures.patch import get_version - from ddtrace.contrib.internal.futures.patch import patch - from ddtrace.contrib.internal.futures.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.futures.patch import get_version +from ddtrace.contrib.internal.futures.patch import patch +from ddtrace.contrib.internal.futures.patch import unpatch - __all__ = [ - "get_version", - "patch", - "unpatch", - ] + +__all__ = [ + "get_version", + "patch", + "unpatch", +] diff --git a/ddtrace/contrib/gevent/__init__.py b/ddtrace/contrib/gevent/__init__.py index 1b8e2811ef5..fb051e5f88b 100644 --- a/ddtrace/contrib/gevent/__init__.py +++ b/ddtrace/contrib/gevent/__init__.py @@ -36,26 +36,23 @@ def worker_function(): with tracer.trace("greenlet.child_call") as child: ... """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.gevent.patch` directly +import warnings as _w -required_modules = ["gevent"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.gevent.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.gevent.patch import get_version - from ddtrace.contrib.internal.gevent.patch import patch - from ddtrace.contrib.internal.gevent.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.gevent.patch import get_version +from ddtrace.contrib.internal.gevent.patch import patch +from ddtrace.contrib.internal.gevent.patch import unpatch - from ...provider import DefaultContextProvider as _DefaultContextProvider +from ...provider import DefaultContextProvider as _DefaultContextProvider - context_provider = _DefaultContextProvider() - __all__ = ["patch", "unpatch", "context_provider", "get_version"] +context_provider = _DefaultContextProvider() + +__all__ = ["patch", "unpatch", "context_provider", "get_version"] diff --git a/ddtrace/contrib/google_generativeai/__init__.py b/ddtrace/contrib/google_generativeai/__init__.py index 03cb35c9eae..d63a1134ab2 100644 --- a/ddtrace/contrib/google_generativeai/__init__.py +++ b/ddtrace/contrib/google_generativeai/__init__.py @@ -77,15 +77,11 @@ Pin.override(genai, service="my-gemini-service") """ # noqa: E501 -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["google.generativeai"] +from ..internal.google_generativeai.patch import get_version +from ..internal.google_generativeai.patch import patch +from ..internal.google_generativeai.patch import unpatch -with require_modules(required_modules) as missing_modules: - if not missing_modules: - from ..internal.google_generativeai.patch import get_version - from ..internal.google_generativeai.patch import patch - from ..internal.google_generativeai.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/graphql/__init__.py b/ddtrace/contrib/graphql/__init__.py index 89350191ef1..5394f243533 100644 --- a/ddtrace/contrib/graphql/__init__.py +++ b/ddtrace/contrib/graphql/__init__.py @@ -44,23 +44,20 @@ Pin.override(graphql, service="mygraphql") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["graphql"] +# Required to allow users to import from `ddtrace.contrib.graphql.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.graphql.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.graphql.patch import get_version - from ddtrace.contrib.internal.graphql.patch import patch - from ddtrace.contrib.internal.graphql.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.graphql.patch import get_version +from ddtrace.contrib.internal.graphql.patch import patch +from ddtrace.contrib.internal.graphql.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/grpc/__init__.py b/ddtrace/contrib/grpc/__init__.py index c329762316c..ff5adb86aea 100644 --- a/ddtrace/contrib/grpc/__init__.py +++ b/ddtrace/contrib/grpc/__init__.py @@ -75,23 +75,18 @@ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.grpc.patch` directly +import warnings as _w -required_modules = ["grpc"] +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.grpc.patch` directly - import warnings as _w +# Expose public methods +from ddtrace.contrib.internal.grpc.patch import get_version +from ddtrace.contrib.internal.grpc.patch import patch +from ddtrace.contrib.internal.grpc.patch import unpatch - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.grpc.patch import get_version - from ddtrace.contrib.internal.grpc.patch import patch - from ddtrace.contrib.internal.grpc.patch import unpatch - - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/httplib/__init__.py b/ddtrace/contrib/httplib/__init__.py index 509e80df270..948b885199a 100644 --- a/ddtrace/contrib/httplib/__init__.py +++ b/ddtrace/contrib/httplib/__init__.py @@ -58,22 +58,18 @@ :ref:`Headers tracing ` is supported for this integration. """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["http.client"] +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - from ddtrace.contrib.internal.httplib.patch import get_version - from ddtrace.contrib.internal.httplib.patch import patch - from ddtrace.contrib.internal.httplib.patch import unpatch +from ddtrace.contrib.internal.httplib.patch import get_version +from ddtrace.contrib.internal.httplib.patch import patch +from ddtrace.contrib.internal.httplib.patch import unpatch __all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/httpx/__init__.py b/ddtrace/contrib/httpx/__init__.py index 4575d39e7c6..118d0a738b5 100644 --- a/ddtrace/contrib/httpx/__init__.py +++ b/ddtrace/contrib/httpx/__init__.py @@ -77,23 +77,20 @@ .. __: https://www.python-httpx.org/ """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["httpx"] +# Required to allow users to import from `ddtrace.contrib.httpx.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.httpx.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.httpx.patch import get_version - from ddtrace.contrib.internal.httpx.patch import patch - from ddtrace.contrib.internal.httpx.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.httpx.patch import get_version +from ddtrace.contrib.internal.httpx.patch import patch +from ddtrace.contrib.internal.httpx.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/jinja2/__init__.py b/ddtrace/contrib/jinja2/__init__.py index af2f6580041..b10c98609a8 100644 --- a/ddtrace/contrib/jinja2/__init__.py +++ b/ddtrace/contrib/jinja2/__init__.py @@ -27,23 +27,19 @@ By default, the service name is set to None, so it is inherited from the parent span. If there is no parent span and the service name is not overridden the agent will drop the traces. """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.jinja2.patch` directly +import warnings as _w -required_modules = ["jinja2"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.jinja2.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.jinja2.patch import get_version +from ddtrace.contrib.internal.jinja2.patch import patch +from ddtrace.contrib.internal.jinja2.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.jinja2.patch import get_version - from ddtrace.contrib.internal.jinja2.patch import patch - from ddtrace.contrib.internal.jinja2.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/kafka/__init__.py b/ddtrace/contrib/kafka/__init__.py index e784e6c9e52..f3cf66f6f23 100644 --- a/ddtrace/contrib/kafka/__init__.py +++ b/ddtrace/contrib/kafka/__init__.py @@ -41,23 +41,20 @@ Pin.override(confluent_kafka, service="custom-service-name") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["confluent_kafka"] +# Required to allow users to import from `ddtrace.contrib.kafka.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.kafka.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.kafka.patch import get_version - from ddtrace.contrib.internal.kafka.patch import patch - from ddtrace.contrib.internal.kafka.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.kafka.patch import get_version +from ddtrace.contrib.internal.kafka.patch import patch +from ddtrace.contrib.internal.kafka.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/langchain/__init__.py b/ddtrace/contrib/langchain/__init__.py index ba42e44af75..9f306fe07ed 100644 --- a/ddtrace/contrib/langchain/__init__.py +++ b/ddtrace/contrib/langchain/__init__.py @@ -207,23 +207,19 @@ Default: ``0.1`` """ # noqa: E501 -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.langchain.patch` directly +import warnings as _w -required_modules = ["langchain"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.langchain.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.langchain.patch import get_version +from ddtrace.contrib.internal.langchain.patch import patch +from ddtrace.contrib.internal.langchain.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.langchain.patch import get_version - from ddtrace.contrib.internal.langchain.patch import patch - from ddtrace.contrib.internal.langchain.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/logbook/__init__.py b/ddtrace/contrib/logbook/__init__.py index 1257af21a07..d42491706f2 100644 --- a/ddtrace/contrib/logbook/__init__.py +++ b/ddtrace/contrib/logbook/__init__.py @@ -48,23 +48,19 @@ https://docs.datadoghq.com/logs/log_collection/python/ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.logbook.patch` directly +import warnings as _w -required_modules = ["logbook"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.logbook.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.logbook.patch import get_version +from ddtrace.contrib.internal.logbook.patch import patch +from ddtrace.contrib.internal.logbook.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.logbook.patch import get_version - from ddtrace.contrib.internal.logbook.patch import patch - from ddtrace.contrib.internal.logbook.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/logging/__init__.py b/ddtrace/contrib/logging/__init__.py index 137a8f1a1af..24deca593a5 100644 --- a/ddtrace/contrib/logging/__init__.py +++ b/ddtrace/contrib/logging/__init__.py @@ -61,23 +61,19 @@ def hello(): https://docs.datadoghq.com/logs/guide/logs-not-showing-expected-timestamp/ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.logging.patch` directly +import warnings as _w -required_modules = ["logging"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.logging.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.logging.patch import get_version +from ddtrace.contrib.internal.logging.patch import patch +from ddtrace.contrib.internal.logging.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.logging.patch import get_version - from ddtrace.contrib.internal.logging.patch import patch - from ddtrace.contrib.internal.logging.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/loguru/__init__.py b/ddtrace/contrib/loguru/__init__.py index ef4cf4e8cc0..4fb56886108 100644 --- a/ddtrace/contrib/loguru/__init__.py +++ b/ddtrace/contrib/loguru/__init__.py @@ -63,23 +63,19 @@ def log_format(record): https://docs.datadoghq.com/logs/log_collection/python/ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.loguru.patch` directly +import warnings as _w -required_modules = ["loguru"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.loguru.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.loguru.patch import get_version +from ddtrace.contrib.internal.loguru.patch import patch +from ddtrace.contrib.internal.loguru.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.loguru.patch import get_version - from ddtrace.contrib.internal.loguru.patch import patch - from ddtrace.contrib.internal.loguru.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/mako/__init__.py b/ddtrace/contrib/mako/__init__.py index e76fabc7e2a..2dda665270e 100644 --- a/ddtrace/contrib/mako/__init__.py +++ b/ddtrace/contrib/mako/__init__.py @@ -10,23 +10,20 @@ t = Template(filename="index.html") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["mako"] +# Required to allow users to import from `ddtrace.contrib.mako.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.mako.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.mako.patch import get_version - from ddtrace.contrib.internal.mako.patch import patch - from ddtrace.contrib.internal.mako.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.mako.patch import get_version +from ddtrace.contrib.internal.mako.patch import patch +from ddtrace.contrib.internal.mako.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/mariadb/__init__.py b/ddtrace/contrib/mariadb/__init__.py index 976514fadc9..e5c7139ee74 100644 --- a/ddtrace/contrib/mariadb/__init__.py +++ b/ddtrace/contrib/mariadb/__init__.py @@ -52,23 +52,20 @@ cursor.execute("SELECT 6*7 AS the_answer;") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["mariadb"] +# Required to allow users to import from `ddtrace.contrib.mariadb.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.mariadb.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.mariadb.patch import get_version - from ddtrace.contrib.internal.mariadb.patch import patch - from ddtrace.contrib.internal.mariadb.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.mariadb.patch import get_version +from ddtrace.contrib.internal.mariadb.patch import patch +from ddtrace.contrib.internal.mariadb.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/molten/__init__.py b/ddtrace/contrib/molten/__init__.py index 624f13ac8e7..4116e4fd8c7 100644 --- a/ddtrace/contrib/molten/__init__.py +++ b/ddtrace/contrib/molten/__init__.py @@ -34,23 +34,20 @@ def hello(name: str, age: int) -> str: :ref:`All HTTP tags ` are supported for this integration. """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["molten"] +# Required to allow users to import from `ddtrace.contrib.molten.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.molten.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.molten.patch import get_version - from ddtrace.contrib.internal.molten.patch import patch - from ddtrace.contrib.internal.molten.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.molten.patch import get_version +from ddtrace.contrib.internal.molten.patch import patch +from ddtrace.contrib.internal.molten.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/mongoengine/__init__.py b/ddtrace/contrib/mongoengine/__init__.py index a7ded2176f3..1522ac1438b 100644 --- a/ddtrace/contrib/mongoengine/__init__.py +++ b/ddtrace/contrib/mongoengine/__init__.py @@ -17,22 +17,18 @@ Pin.override(client, service="mongo-master") """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.mongoengine.patch` directly +import warnings as _w -required_modules = ["mongoengine"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.mongoengine.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.mongoengine.patch import get_version +from ddtrace.contrib.internal.mongoengine.patch import patch - # Expose public methods - from ddtrace.contrib.internal.mongoengine.patch import get_version - from ddtrace.contrib.internal.mongoengine.patch import patch - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/mysql/__init__.py b/ddtrace/contrib/mysql/__init__.py index 2c43bec69c0..1c3f6064e55 100644 --- a/ddtrace/contrib/mysql/__init__.py +++ b/ddtrace/contrib/mysql/__init__.py @@ -62,23 +62,22 @@ Help on mysql.connector can be found on: https://dev.mysql.com/doc/connector-python/en/ """ -from ddtrace.internal.utils.importlib import require_modules # check `mysql-connector` availability -required_modules = ["mysql.connector"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.mysql.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Required to allow users to import from `ddtrace.contrib.mysql.patch` directly +import warnings as _w - # Expose public methods - from ddtrace.contrib.internal.mysql.patch import get_version - from ddtrace.contrib.internal.mysql.patch import patch - __all__ = ["patch", "get_version"] +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 + +# Expose public methods +from ddtrace.contrib.internal.mysql.patch import get_version +from ddtrace.contrib.internal.mysql.patch import patch + + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/mysqldb/__init__.py b/ddtrace/contrib/mysqldb/__init__.py index 6201e7016d7..17bb76b08a8 100644 --- a/ddtrace/contrib/mysqldb/__init__.py +++ b/ddtrace/contrib/mysqldb/__init__.py @@ -75,21 +75,18 @@ https://mysqlclient.readthedocs.io/ """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["MySQLdb"] +# Required to allow users to import from `ddtrace.contrib.mysqldb.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.mysqldb.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.mysqldb.patch import get_version - from ddtrace.contrib.internal.mysqldb.patch import patch +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.mysqldb.patch import get_version +from ddtrace.contrib.internal.mysqldb.patch import patch - __all__ = ["patch", "get_version"] + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/openai/__init__.py b/ddtrace/contrib/openai/__init__.py index 0f3da05407d..79a5b488834 100644 --- a/ddtrace/contrib/openai/__init__.py +++ b/ddtrace/contrib/openai/__init__.py @@ -246,23 +246,20 @@ Pin.override(openai, service="my-openai-service") """ # noqa: E501 -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["openai"] +# Required to allow users to import from `ddtrace.contrib.openai.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.openai.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.openai.patch import get_version - from ddtrace.contrib.internal.openai.patch import patch - from ddtrace.contrib.internal.openai.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.openai.patch import get_version +from ddtrace.contrib.internal.openai.patch import patch +from ddtrace.contrib.internal.openai.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/protobuf/__init__.py b/ddtrace/contrib/protobuf/__init__.py index 4284782cdbf..dd429d3aa83 100644 --- a/ddtrace/contrib/protobuf/__init__.py +++ b/ddtrace/contrib/protobuf/__init__.py @@ -15,16 +15,10 @@ ~~~~~~~~~~~~~ """ -from ...internal.utils.importlib import require_modules +# Expose public methods +from ..internal.protobuf.patch import get_version +from ..internal.protobuf.patch import patch +from ..internal.protobuf.patch import unpatch -required_modules = ["protobuf"] - -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Expose public methods - from ..internal.protobuf.patch import get_version - from ..internal.protobuf.patch import patch - from ..internal.protobuf.patch import unpatch - - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/pylibmc/__init__.py b/ddtrace/contrib/pylibmc/__init__.py index c7d397153b7..5689fcd9070 100644 --- a/ddtrace/contrib/pylibmc/__init__.py +++ b/ddtrace/contrib/pylibmc/__init__.py @@ -19,22 +19,18 @@ Pin.override(client, service="memcached-sessions") """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.pylibmc.patch` directly +import warnings as _w -required_modules = ["pylibmc"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.pylibmc.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.pylibmc.client import TracedClient +from ddtrace.contrib.internal.pylibmc.patch import get_version +from ddtrace.contrib.internal.pylibmc.patch import patch - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.pylibmc.client import TracedClient - from ddtrace.contrib.internal.pylibmc.patch import get_version - from ddtrace.contrib.internal.pylibmc.patch import patch - __all__ = ["TracedClient", "patch", "get_version"] +__all__ = ["TracedClient", "patch", "get_version"] diff --git a/ddtrace/contrib/pymemcache/__init__.py b/ddtrace/contrib/pymemcache/__init__.py index 937b6688895..871d8ee0f6c 100644 --- a/ddtrace/contrib/pymemcache/__init__.py +++ b/ddtrace/contrib/pymemcache/__init__.py @@ -30,22 +30,19 @@ Pymemcache ``HashClient`` will also be indirectly patched as it uses ``Client`` under the hood. """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["pymemcache"] +# Required to allow users to import from `ddtrace.contrib.pymemcache.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.pymemcache.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.pymemcache.patch import get_version - from ddtrace.contrib.internal.pymemcache.patch import patch - from ddtrace.contrib.internal.pymemcache.patch import unpatch +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.pymemcache.patch import get_version +from ddtrace.contrib.internal.pymemcache.patch import patch +from ddtrace.contrib.internal.pymemcache.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/pymongo/__init__.py b/ddtrace/contrib/pymongo/__init__.py index 66174b10ff5..60394b6c2f3 100644 --- a/ddtrace/contrib/pymongo/__init__.py +++ b/ddtrace/contrib/pymongo/__init__.py @@ -35,22 +35,19 @@ Default: ``"pymongo"`` """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["pymongo"] +# Required to allow users to import from `ddtrace.contrib.pymongo.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.pymongo.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.pymongo.patch import get_version - from ddtrace.contrib.internal.pymongo.patch import patch +# Expose public methods +from ddtrace.contrib.internal.pymongo.patch import get_version +from ddtrace.contrib.internal.pymongo.patch import patch - __all__ = ["patch", "get_version"] + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/pymysql/__init__.py b/ddtrace/contrib/pymysql/__init__.py index 4e7b322c5d6..d4b24e2cd5f 100644 --- a/ddtrace/contrib/pymysql/__init__.py +++ b/ddtrace/contrib/pymysql/__init__.py @@ -55,22 +55,18 @@ cursor.execute("SELECT 6*7 AS the_answer;") """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.pymysql.patch` directly +import warnings as _w -required_modules = ["pymysql"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.pymysql.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.pymysql.patch import get_version +from ddtrace.contrib.internal.pymysql.patch import patch - # Expose public methods - from ddtrace.contrib.internal.pymysql.patch import get_version - from ddtrace.contrib.internal.pymysql.patch import patch - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/pynamodb/__init__.py b/ddtrace/contrib/pynamodb/__init__.py index 12c138f5377..3a84e603243 100644 --- a/ddtrace/contrib/pynamodb/__init__.py +++ b/ddtrace/contrib/pynamodb/__init__.py @@ -29,22 +29,17 @@ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.pynamodb.patch` directly +import warnings as _w -required_modules = ["pynamodb.connection.base"] +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.pynamodb.patch` directly - import warnings as _w +# Expose public methods +from ddtrace.contrib.internal.pynamodb.patch import get_version +from ddtrace.contrib.internal.pynamodb.patch import patch - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.pynamodb.patch import get_version - from ddtrace.contrib.internal.pynamodb.patch import patch - - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/pyodbc/__init__.py b/ddtrace/contrib/pyodbc/__init__.py index f874f561013..44605b7cdc9 100644 --- a/ddtrace/contrib/pyodbc/__init__.py +++ b/ddtrace/contrib/pyodbc/__init__.py @@ -53,22 +53,19 @@ cursor = db.cursor() cursor.execute("select * from users where id = 1") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["pyodbc"] +# Required to allow users to import from `ddtrace.contrib.pyodbc.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.pyodbc.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.pyodbc.patch import get_version - from ddtrace.contrib.internal.pyodbc.patch import patch +# Expose public methods +from ddtrace.contrib.internal.pyodbc.patch import get_version +from ddtrace.contrib.internal.pyodbc.patch import patch - __all__ = ["patch", "get_version"] + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/pyramid/__init__.py b/ddtrace/contrib/pyramid/__init__.py index b0cb0c9fcb3..72ef2613117 100644 --- a/ddtrace/contrib/pyramid/__init__.py +++ b/ddtrace/contrib/pyramid/__init__.py @@ -40,25 +40,21 @@ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.pyramid.patch` directly +import warnings as _w -required_modules = ["pyramid"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.pyramid.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.pyramid.patch import get_version +from ddtrace.contrib.internal.pyramid.patch import patch +from ddtrace.contrib.internal.pyramid.trace import includeme +from ddtrace.contrib.internal.pyramid.trace import trace_pyramid +from ddtrace.contrib.internal.pyramid.trace import trace_tween_factory - # Expose public methods - from ddtrace.contrib.internal.pyramid.patch import get_version - from ddtrace.contrib.internal.pyramid.patch import patch - from ddtrace.contrib.internal.pyramid.trace import includeme - from ddtrace.contrib.internal.pyramid.trace import trace_pyramid - from ddtrace.contrib.internal.pyramid.trace import trace_tween_factory - __all__ = ["patch", "trace_pyramid", "trace_tween_factory", "includeme", "get_version"] +__all__ = ["patch", "trace_pyramid", "trace_tween_factory", "includeme", "get_version"] diff --git a/ddtrace/contrib/redis/__init__.py b/ddtrace/contrib/redis/__init__.py index 6ab85b1a9fa..4fddef1c742 100644 --- a/ddtrace/contrib/redis/__init__.py +++ b/ddtrace/contrib/redis/__init__.py @@ -67,22 +67,18 @@ client.get("my-key") """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.redis.patch` directly +import warnings as _w -required_modules = ["redis", "redis.client"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.redis.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.redis.patch import get_version +from ddtrace.contrib.internal.redis.patch import patch - # Expose public methods - from ddtrace.contrib.internal.redis.patch import get_version - from ddtrace.contrib.internal.redis.patch import patch - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/rediscluster/__init__.py b/ddtrace/contrib/rediscluster/__init__.py index 55d20f9d933..cb14eb9aa30 100644 --- a/ddtrace/contrib/rediscluster/__init__.py +++ b/ddtrace/contrib/rediscluster/__init__.py @@ -48,22 +48,18 @@ Default: ``True`` """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.rediscluster.patch` directly +import warnings as _w -required_modules = ["rediscluster", "rediscluster.client"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.rediscluster.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.rediscluster.patch import get_version +from ddtrace.contrib.internal.rediscluster.patch import patch - # Expose public methods - from ddtrace.contrib.internal.rediscluster.patch import get_version - from ddtrace.contrib.internal.rediscluster.patch import patch - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/requests/__init__.py b/ddtrace/contrib/requests/__init__.py index e9a9e973d77..727e8219339 100644 --- a/ddtrace/contrib/requests/__init__.py +++ b/ddtrace/contrib/requests/__init__.py @@ -72,24 +72,21 @@ cfg['service_name'] = 'auth-api' cfg['distributed_tracing'] = False """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["requests"] +# Required to allow users to import from `ddtrace.contrib.requests.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.requests.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.requests.patch import get_version - from ddtrace.contrib.internal.requests.patch import patch - from ddtrace.contrib.internal.requests.patch import unpatch - from ddtrace.contrib.internal.requests.session import TracedSession +# Expose public methods +from ddtrace.contrib.internal.requests.patch import get_version +from ddtrace.contrib.internal.requests.patch import patch +from ddtrace.contrib.internal.requests.patch import unpatch +from ddtrace.contrib.internal.requests.session import TracedSession - __all__ = ["patch", "unpatch", "TracedSession", "get_version"] + +__all__ = ["patch", "unpatch", "TracedSession", "get_version"] diff --git a/ddtrace/contrib/sanic/__init__.py b/ddtrace/contrib/sanic/__init__.py index b68db2efe1c..96f47d156ac 100644 --- a/ddtrace/contrib/sanic/__init__.py +++ b/ddtrace/contrib/sanic/__init__.py @@ -55,23 +55,20 @@ def index(request): .. __: https://sanic.readthedocs.io/en/latest/ """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["sanic"] +# Required to allow users to import from `ddtrace.contrib.sanic.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.sanic.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.sanic.patch import get_version - from ddtrace.contrib.internal.sanic.patch import patch - from ddtrace.contrib.internal.sanic.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.sanic.patch import get_version +from ddtrace.contrib.internal.sanic.patch import patch +from ddtrace.contrib.internal.sanic.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/selenium/__init__.py b/ddtrace/contrib/selenium/__init__.py index d30c896fdd7..f5016ce0254 100644 --- a/ddtrace/contrib/selenium/__init__.py +++ b/ddtrace/contrib/selenium/__init__.py @@ -22,16 +22,10 @@ DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS: The time in milliseconds to wait after flushing the RUM session. """ -from ...internal.utils.importlib import require_modules +# Expose public methods +from ..internal.selenium.patch import get_version +from ..internal.selenium.patch import patch +from ..internal.selenium.patch import unpatch -required_modules = ["selenium"] - -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Expose public methods - from ..internal.selenium.patch import get_version - from ..internal.selenium.patch import patch - from ..internal.selenium.patch import unpatch - - __all__ = ["get_version", "patch", "unpatch"] +__all__ = ["get_version", "patch", "unpatch"] diff --git a/ddtrace/contrib/snowflake/__init__.py b/ddtrace/contrib/snowflake/__init__.py index c89f42cf8c4..e675ff7a067 100644 --- a/ddtrace/contrib/snowflake/__init__.py +++ b/ddtrace/contrib/snowflake/__init__.py @@ -58,23 +58,20 @@ cursor = conn.cursor() cursor.execute("SELECT current_version()") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["snowflake.connector"] +# Required to allow users to import from `ddtrace.contrib.snowflake.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.snowflake.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.snowflake.patch import get_version - from ddtrace.contrib.internal.snowflake.patch import patch - from ddtrace.contrib.internal.snowflake.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.snowflake.patch import get_version +from ddtrace.contrib.internal.snowflake.patch import patch +from ddtrace.contrib.internal.snowflake.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/sqlalchemy/__init__.py b/ddtrace/contrib/sqlalchemy/__init__.py index 15d05aa45f6..c294b8c976c 100644 --- a/ddtrace/contrib/sqlalchemy/__init__.py +++ b/ddtrace/contrib/sqlalchemy/__init__.py @@ -19,24 +19,21 @@ # Use a PIN to specify metadata related to this engine Pin.override(engine, service='replica-db') """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["sqlalchemy", "sqlalchemy.event"] +# Required to allow users to import from `ddtrace.contrib.sqlalchemy.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.sqlalchemy.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.sqlalchemy.engine import trace_engine - from ddtrace.contrib.internal.sqlalchemy.patch import get_version - from ddtrace.contrib.internal.sqlalchemy.patch import patch - from ddtrace.contrib.internal.sqlalchemy.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.sqlalchemy.engine import trace_engine +from ddtrace.contrib.internal.sqlalchemy.patch import get_version +from ddtrace.contrib.internal.sqlalchemy.patch import patch +from ddtrace.contrib.internal.sqlalchemy.patch import unpatch - __all__ = ["trace_engine", "patch", "unpatch", "get_version"] + +__all__ = ["trace_engine", "patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/sqlite3/__init__.py b/ddtrace/contrib/sqlite3/__init__.py index 02624851300..42499cf0447 100644 --- a/ddtrace/contrib/sqlite3/__init__.py +++ b/ddtrace/contrib/sqlite3/__init__.py @@ -53,22 +53,19 @@ cursor = db.cursor() cursor.execute("select * from users where id = 1") """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["sqlite3"] +# Required to allow users to import from `ddtrace.contrib.sqlite3.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.sqlite3.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.sqlite3.patch import get_version - from ddtrace.contrib.internal.sqlite3.patch import patch +# Expose public methods +from ddtrace.contrib.internal.sqlite3.patch import get_version +from ddtrace.contrib.internal.sqlite3.patch import patch - __all__ = ["patch", "get_version"] + +__all__ = ["patch", "get_version"] diff --git a/ddtrace/contrib/starlette/__init__.py b/ddtrace/contrib/starlette/__init__.py index 9413e507759..d3327feded4 100644 --- a/ddtrace/contrib/starlette/__init__.py +++ b/ddtrace/contrib/starlette/__init__.py @@ -57,23 +57,20 @@ config.starlette['request_span_name'] = 'custom-request-span-name' """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["starlette"] +# Required to allow users to import from `ddtrace.contrib.starlette.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.starlette.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.starlette.patch import get_version - from ddtrace.contrib.internal.starlette.patch import patch - from ddtrace.contrib.internal.starlette.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.starlette.patch import get_version +from ddtrace.contrib.internal.starlette.patch import patch +from ddtrace.contrib.internal.starlette.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/structlog/__init__.py b/ddtrace/contrib/structlog/__init__.py index c953b974f34..0a9bcb56395 100644 --- a/ddtrace/contrib/structlog/__init__.py +++ b/ddtrace/contrib/structlog/__init__.py @@ -38,23 +38,19 @@ https://docs.datadoghq.com/logs/log_collection/python/ """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.structlog.patch` directly +import warnings as _w -required_modules = ["structlog"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.structlog.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.structlog.patch import get_version +from ddtrace.contrib.internal.structlog.patch import patch +from ddtrace.contrib.internal.structlog.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.structlog.patch import get_version - from ddtrace.contrib.internal.structlog.patch import patch - from ddtrace.contrib.internal.structlog.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/subprocess/__init__.py b/ddtrace/contrib/subprocess/__init__.py index ea0faae85aa..2e4969648d1 100644 --- a/ddtrace/contrib/subprocess/__init__.py +++ b/ddtrace/contrib/subprocess/__init__.py @@ -19,23 +19,19 @@ ```ddtrace.contrib.subprocess.constants.SENSITIVE_WORDS_WILDCARDS```. """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.subprocess.patch` directly +import warnings as _w -required_modules = ["os", "subprocess"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.subprocess.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.subprocess.patch import get_version +from ddtrace.contrib.internal.subprocess.patch import patch +from ddtrace.contrib.internal.subprocess.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.subprocess.patch import get_version - from ddtrace.contrib.internal.subprocess.patch import patch - from ddtrace.contrib.internal.subprocess.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/tornado/__init__.py b/ddtrace/contrib/tornado/__init__.py index 9d681396810..ad0adef2dd5 100644 --- a/ddtrace/contrib/tornado/__init__.py +++ b/ddtrace/contrib/tornado/__init__.py @@ -104,33 +104,30 @@ def log_exception(self, typ, value, tb): * ``agent_port`` (default: `8126`): define the port of the APM agent. * ``settings`` (default: ``{}``): Tracer extra settings used to change, for instance, the filtering behavior. """ -from ddtrace.internal.utils.importlib import require_modules - - -required_modules = ["tornado"] - -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.tornado.patch` directly - import warnings as _w - - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 - - # Expose public methods - from ddtrace.contrib.internal.tornado.patch import get_version - from ddtrace.contrib.internal.tornado.patch import patch - from ddtrace.contrib.internal.tornado.patch import unpatch - from ddtrace.contrib.internal.tornado.stack_context import TracerStackContext - from ddtrace.contrib.internal.tornado.stack_context import context_provider - from ddtrace.contrib.internal.tornado.stack_context import run_with_trace_context - - __all__ = [ - "patch", - "unpatch", - "context_provider", - "run_with_trace_context", - "TracerStackContext", - "get_version", - ] + + +# Required to allow users to import from `ddtrace.contrib.tornado.patch` directly +import warnings as _w + + +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 + +# Expose public methods +from ddtrace.contrib.internal.tornado.patch import get_version +from ddtrace.contrib.internal.tornado.patch import patch +from ddtrace.contrib.internal.tornado.patch import unpatch +from ddtrace.contrib.internal.tornado.stack_context import TracerStackContext +from ddtrace.contrib.internal.tornado.stack_context import context_provider +from ddtrace.contrib.internal.tornado.stack_context import run_with_trace_context + + +__all__ = [ + "patch", + "unpatch", + "context_provider", + "run_with_trace_context", + "TracerStackContext", + "get_version", +] diff --git a/ddtrace/contrib/unittest/__init__.py b/ddtrace/contrib/unittest/__init__.py index cc15ea375c3..5180b59c959 100644 --- a/ddtrace/contrib/unittest/__init__.py +++ b/ddtrace/contrib/unittest/__init__.py @@ -34,15 +34,11 @@ Default: ``True`` """ -from ddtrace.internal.utils.importlib import require_modules + from .patch import get_version from .patch import patch from .patch import unpatch -required_modules = ["unittest"] - -with require_modules(required_modules) as missing_modules: - if not missing_modules: - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/urllib/__init__.py b/ddtrace/contrib/urllib/__init__.py index 8f22672d3d9..596251e99ad 100644 --- a/ddtrace/contrib/urllib/__init__.py +++ b/ddtrace/contrib/urllib/__init__.py @@ -4,23 +4,20 @@ if ``DD_IAST_ENABLED`` is set to ``True`` (for detecting sink points) and/or ``DD_ASM_ENABLED`` is set to ``True`` (for exploit prevention). """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["urllib"] +# Required to allow users to import from `ddtrace.contrib.urllib.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.urllib.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.urllib.patch import get_version - from ddtrace.contrib.internal.urllib.patch import patch - from ddtrace.contrib.internal.urllib.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.urllib.patch import get_version +from ddtrace.contrib.internal.urllib.patch import patch +from ddtrace.contrib.internal.urllib.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/urllib3/__init__.py b/ddtrace/contrib/urllib3/__init__.py index 71f6ad2eebe..0f2ebf2b12f 100644 --- a/ddtrace/contrib/urllib3/__init__.py +++ b/ddtrace/contrib/urllib3/__init__.py @@ -50,23 +50,20 @@ Default: ``False`` """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["urllib3"] +# Required to allow users to import from `ddtrace.contrib.urllib3.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.urllib3.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.urllib3.patch import get_version - from ddtrace.contrib.internal.urllib3.patch import patch - from ddtrace.contrib.internal.urllib3.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.urllib3.patch import get_version +from ddtrace.contrib.internal.urllib3.patch import patch +from ddtrace.contrib.internal.urllib3.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/vertexai/__init__.py b/ddtrace/contrib/vertexai/__init__.py index acc2417b679..f472d28790d 100644 --- a/ddtrace/contrib/vertexai/__init__.py +++ b/ddtrace/contrib/vertexai/__init__.py @@ -82,15 +82,10 @@ Pin.override(vertexai, service="my-vertexai-service") """ # noqa: E501 -from ddtrace.internal.utils.importlib import require_modules +from ddtrace.contrib.internal.vertexai.patch import get_version +from ddtrace.contrib.internal.vertexai.patch import patch +from ddtrace.contrib.internal.vertexai.patch import unpatch -required_modules = ["vertexai"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - from ddtrace.contrib.internal.vertexai.patch import get_version - from ddtrace.contrib.internal.vertexai.patch import patch - from ddtrace.contrib.internal.vertexai.patch import unpatch - - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/vertica/__init__.py b/ddtrace/contrib/vertica/__init__.py index dfafe39a79f..3ec424fbb53 100644 --- a/ddtrace/contrib/vertica/__init__.py +++ b/ddtrace/contrib/vertica/__init__.py @@ -39,23 +39,19 @@ Pin.override(conn, service='myverticaservice', tracer=custom_tracer) """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.vertica.patch` directly +import warnings as _w -required_modules = ["vertica_python"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.vertica.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.vertica.patch import get_version +from ddtrace.contrib.internal.vertica.patch import patch +from ddtrace.contrib.internal.vertica.patch import unpatch - # Expose public methods - from ddtrace.contrib.internal.vertica.patch import get_version - from ddtrace.contrib.internal.vertica.patch import patch - from ddtrace.contrib.internal.vertica.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/webbrowser/__init__.py b/ddtrace/contrib/webbrowser/__init__.py index e5123725b0c..49a251cad50 100644 --- a/ddtrace/contrib/webbrowser/__init__.py +++ b/ddtrace/contrib/webbrowser/__init__.py @@ -4,23 +4,20 @@ if ``DD_IAST_ENABLED`` is set to ``True`` (for detecting sink points) and/or ``DD_ASM_ENABLED`` is set to ``True`` (for exploit prevention). """ -from ddtrace.internal.utils.importlib import require_modules -required_modules = ["webbrowser"] +# Required to allow users to import from `ddtrace.contrib.webbrowser.patch` directly +import warnings as _w -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.webbrowser.patch` directly - import warnings as _w - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - # Expose public methods - from ddtrace.contrib.internal.webbrowser.patch import get_version - from ddtrace.contrib.internal.webbrowser.patch import patch - from ddtrace.contrib.internal.webbrowser.patch import unpatch +# Expose public methods +from ddtrace.contrib.internal.webbrowser.patch import get_version +from ddtrace.contrib.internal.webbrowser.patch import patch +from ddtrace.contrib.internal.webbrowser.patch import unpatch - __all__ = ["patch", "unpatch", "get_version"] + +__all__ = ["patch", "unpatch", "get_version"] diff --git a/ddtrace/contrib/yaaredis/__init__.py b/ddtrace/contrib/yaaredis/__init__.py index 05396dae7a3..03d76db11c0 100644 --- a/ddtrace/contrib/yaaredis/__init__.py +++ b/ddtrace/contrib/yaaredis/__init__.py @@ -66,22 +66,18 @@ async def example(): await client.get("my-key") """ -from ddtrace.internal.utils.importlib import require_modules +# Required to allow users to import from `ddtrace.contrib.yaaredis.patch` directly +import warnings as _w -required_modules = ["yaaredis", "yaaredis.client"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - # Required to allow users to import from `ddtrace.contrib.yaaredis.patch` directly - import warnings as _w +with _w.catch_warnings(): + _w.simplefilter("ignore", DeprecationWarning) + from . import patch as _ # noqa: F401, I001 - with _w.catch_warnings(): - _w.simplefilter("ignore", DeprecationWarning) - from . import patch as _ # noqa: F401, I001 +# Expose public methods +from ddtrace.contrib.internal.yaaredis.patch import get_version +from ddtrace.contrib.internal.yaaredis.patch import patch - # Expose public methods - from ddtrace.contrib.internal.yaaredis.patch import get_version - from ddtrace.contrib.internal.yaaredis.patch import patch - __all__ = ["patch", "get_version"] +__all__ = ["patch", "get_version"] diff --git a/docs/conf.py b/docs/conf.py index 84ebe856954..9a20184de0a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -140,6 +140,12 @@ def _skip(self, word): # This patterns also effect to html_static_path and html_extra_path exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +# autodoc_mock_imports contains a list of modules to be mocked up. +# This is useful when some external dependencies are installed at build time and break the building process. +# The following modules require third party packages and should be mocked when generating docs: +autodoc_mock_imports = ["ddtrace.contrib.internal"] + # The reST default role (used for this markup: `text`) to use for all # documents. # diff --git a/templates/integration/__init__.py b/templates/integration/__init__.py index 1fb943b8226..ef19d262e58 100644 --- a/templates/integration/__init__.py +++ b/templates/integration/__init__.py @@ -40,15 +40,10 @@ myfoo = foo.Foo() Pin.override(myfoo, service="myfoo") """ -from ...internal.utils.importlib import require_modules +from .patch import get_version +from .patch import patch +from .patch import unpatch -required_modules = ["foo"] -with require_modules(required_modules) as missing_modules: - if not missing_modules: - from .patch import get_version - from .patch import patch - from .patch import unpatch - - __all__ = ["patch", "unpatch", "get_version"] +__all__ = ["patch", "unpatch", "get_version"]