Skip to content

Commit

Permalink
fix(integrations): remove require modules from integration init
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Dec 13, 2024
1 parent 2e2303b commit 2a29668
Show file tree
Hide file tree
Showing 78 changed files with 758 additions and 1,050 deletions.
23 changes: 10 additions & 13 deletions ddtrace/contrib/aiobotocore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
27 changes: 12 additions & 15 deletions ddtrace/contrib/aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,21 @@ async def home_handler(request):
:ref:`All HTTP tags <http-tagging>` 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"]
23 changes: 10 additions & 13 deletions ddtrace/contrib/aiohttp_jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
22 changes: 9 additions & 13 deletions ddtrace/contrib/aiomysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
21 changes: 9 additions & 12 deletions ddtrace/contrib/aiopg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
24 changes: 11 additions & 13 deletions ddtrace/contrib/aioredis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,20 @@
myaioredis = aioredis.Aioredis()
Pin.override(myaioredis, service="myaioredis")
"""
from ddtrace.internal.utils.importlib import require_modules # noqa:E402
# noqa:E402


required_modules = ["aioredis"]
# Required to allow users to import from `ddtrace.contrib.aioredis.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.aioredis.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.aioredis.patch import get_version
from ddtrace.contrib.internal.aioredis.patch import patch
from ddtrace.contrib.internal.aioredis.patch import unpatch
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"]
22 changes: 9 additions & 13 deletions ddtrace/contrib/algoliasearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
23 changes: 10 additions & 13 deletions ddtrace/contrib/anthropic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
20 changes: 8 additions & 12 deletions ddtrace/contrib/aredis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
16 changes: 4 additions & 12 deletions ddtrace/contrib/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
34 changes: 15 additions & 19 deletions ddtrace/contrib/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
This integration provides context management for tracing the execution flow
of concurrent execution of ``asyncio.Task``.
"""
from ddtrace.internal.utils.importlib import require_modules
from ddtrace._trace.provider import DefaultContextProvider


required_modules = ["asyncio"]
context_provider = DefaultContextProvider()

with require_modules(required_modules) as missing_modules:
if not missing_modules:
from ddtrace._trace.provider import DefaultContextProvider
# Required to allow users to import from `ddtrace.contrib.asyncio.patch` directly
# Expose public methods
import warnings as _w

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

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"]
23 changes: 10 additions & 13 deletions ddtrace/contrib/asyncpg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading

0 comments on commit 2a29668

Please sign in to comment.