Skip to content

Commit 69ecf70

Browse files
author
Emanuele Palazzetti
committed
[core] deprecation for ddtrace.util, ddtrace.contrib.util and safe_patch; they will note be used anymore
* `ddtrace.util` is replaced with `ddtrace.utils` package * `ddtrace.contrib.util` is replaced with `ddtrace.utils.importlib` * `safe_patch` will be removed because not used anymore
1 parent 1ed86e7 commit 69ecf70

File tree

4 files changed

+56
-34
lines changed

4 files changed

+56
-34
lines changed

ddtrace/contrib/util.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
from importlib import import_module
2-
3-
4-
class require_modules(object):
5-
"""
6-
Context manager to check the availability of required modules.
7-
"""
8-
def __init__(self, modules):
9-
self._missing_modules = []
10-
for module in modules:
11-
try:
12-
import_module(module)
13-
except ImportError:
14-
self._missing_modules.append(module)
15-
16-
def __enter__(self):
17-
return self._missing_modules
18-
19-
def __exit__(self, exc_type, exc_value, traceback):
20-
return False
21-
22-
23-
def func_name(f):
24-
"""
25-
Return a human readable version of the function's name.
26-
"""
27-
if hasattr(f, '__module__'):
28-
return "%s.%s" % (f.__module__, getattr(f, '__name__', f.__class__.__name__))
29-
return getattr(f, '__name__', f.__class__.__name__)
30-
31-
32-
def module_name(instance):
33-
return instance.__class__.__module__.split('.')[0]
1+
# [Backward compatibility]: keep importing modules functions
2+
from ..utils.deprecation import deprecation
3+
from ..utils.importlib import require_modules, func_name, module_name
4+
5+
6+
deprecation(
7+
name='ddtrace.contrib.util',
8+
message='Use `ddtrace.utils.importlib` module instead',
9+
version='1.0.0',
10+
)
11+
12+
__all__ = [
13+
'require_modules',
14+
'func_name',
15+
'module_name',
16+
]

ddtrace/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# [Backward compatibility]: keep importing modules functions
2-
from .utils.deprecation import deprecated
2+
from .utils.deprecation import deprecated, deprecation
33
from .utils.formats import asbool, deep_getattr, get_env
44
from .utils.wrappers import safe_patch, unwrap
55

66

7+
deprecation(
8+
name='ddtrace.util',
9+
message='Use `ddtrace.utils` package instead',
10+
version='1.0.0',
11+
)
12+
713
__all__ = [
814
'deprecated',
915
'asbool',

ddtrace/utils/importlib.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from importlib import import_module
2+
3+
4+
class require_modules(object):
5+
"""Context manager to check the availability of required modules."""
6+
def __init__(self, modules):
7+
self._missing_modules = []
8+
for module in modules:
9+
try:
10+
import_module(module)
11+
except ImportError:
12+
self._missing_modules.append(module)
13+
14+
def __enter__(self):
15+
return self._missing_modules
16+
17+
def __exit__(self, exc_type, exc_value, traceback):
18+
return False
19+
20+
21+
def func_name(f):
22+
"""Return a human readable version of the function's name."""
23+
if hasattr(f, '__module__'):
24+
return "%s.%s" % (f.__module__, getattr(f, '__name__', f.__class__.__name__))
25+
return getattr(f, '__name__', f.__class__.__name__)
26+
27+
28+
def module_name(instance):
29+
"""Return the instance module name."""
30+
return instance.__class__.__module__.split('.')[0]

ddtrace/utils/wrappers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import wrapt
22
import inspect
33

4+
from .deprecation import deprecated
5+
46

57
def unwrap(obj, attr):
68
f = getattr(obj, attr, None)
79
if f and isinstance(f, wrapt.ObjectProxy) and hasattr(f, '__wrapped__'):
810
setattr(obj, attr, f.__wrapped__)
911

1012

13+
@deprecated('`wrapt` library is used instead', version='1.0.0')
1114
def safe_patch(patchable, key, patch_func, service, meta, tracer):
1215
""" takes patch_func (signature: takes the orig_method that is
1316
wrapped in the monkey patch == UNBOUND + service and meta) and

0 commit comments

Comments
 (0)