|
1 | 1 | import importlib.util |
2 | 2 | import os |
3 | | -import warnings |
4 | | -from functools import partial, wraps |
5 | | -from typing import Optional |
| 3 | +from functools import wraps |
6 | 4 |
|
7 | 5 |
|
8 | 6 | def eval_env(var, default): |
@@ -60,99 +58,6 @@ def wrapped(*args, **kwargs): |
60 | 58 | return decorator |
61 | 59 |
|
62 | 60 |
|
63 | | -UNSUPPORTED = [] |
64 | | - |
65 | | - |
66 | | -def wrap_deprecated(func, name, direction: str, version: Optional[str] = None, remove: bool = False): |
67 | | - @wraps(func) |
68 | | - def wrapped(*args, **kwargs): |
69 | | - message = f"{name} has been deprecated. {direction}" |
70 | | - if remove: |
71 | | - message += f' It will be removed from {"a future" if version is None else "the " + str(version)} release. ' |
72 | | - warnings.warn(message, stacklevel=2) |
73 | | - return func(*args, **kwargs) |
74 | | - |
75 | | - return wrapped |
76 | | - |
77 | | - |
78 | | -def deprecated(direction: str, version: Optional[str] = None, remove: bool = False): |
79 | | - """Decorator to add deprecation message |
80 | | -
|
81 | | - Args: |
82 | | - direction (str): Migration steps to be given to users. |
83 | | - version (str or int): The version when the object will be removed |
84 | | - remove (bool): If enabled, append future removal message. |
85 | | - """ |
86 | | - |
87 | | - def decorator(func): |
88 | | - wrapped = wrap_deprecated(func, f"{func.__module__}.{func.__name__}", direction, version=version, remove=remove) |
89 | | - |
90 | | - message = "This function has been deprecated. " |
91 | | - if remove: |
92 | | - message += f'It will be removed from {"future" if version is None else version} release. ' |
93 | | - |
94 | | - wrapped.__doc__ = f"""DEPRECATED |
95 | | -
|
96 | | - .. warning:: |
97 | | -
|
98 | | - {message} |
99 | | - {direction} |
100 | | -
|
101 | | - {func.__doc__} |
102 | | - """ |
103 | | - |
104 | | - return wrapped |
105 | | - |
106 | | - return decorator |
107 | | - |
108 | | - |
109 | | -DEPRECATION_MSG = ( |
110 | | - "This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. " |
111 | | - "Please see https://github.com/pytorch/audio/issues/3902 for more information." |
112 | | -) |
113 | | - |
114 | | -IO_DEPRECATION_MSG = ( |
115 | | - "This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. " |
116 | | - "The decoding and encoding capabilities of PyTorch for both audio" |
117 | | - " and video are being consolidated into TorchCodec. " |
118 | | - "Please see https://github.com/pytorch/audio/issues/3902 for more information." |
119 | | -) |
120 | | - |
121 | | -dropping_support = deprecated(DEPRECATION_MSG, version="2.9", remove=True) |
122 | | - |
123 | | - |
124 | | -def dropping_class_support(c, msg=DEPRECATION_MSG): |
125 | | - c.__init__ = wrap_deprecated(c.__init__, f"{c.__module__}.{c.__name__}", msg, version="2.9", remove=True) |
126 | | - c.__doc__ = f"""DEPRECATED |
127 | | -
|
128 | | -.. warning:: |
129 | | -
|
130 | | - This class is deprecated from version 2.8. It will be removed in the 2.9 release. |
131 | | - {msg} |
132 | | -{c.__doc__} |
133 | | -""" |
134 | | - |
135 | | - UNSUPPORTED.append(c) |
136 | | - return c |
137 | | - |
138 | | - |
139 | | -def dropping_const_support(c, msg=DEPRECATION_MSG, name=None): |
140 | | - c.__doc__ = f"""[DEPRECATED] |
141 | | -
|
142 | | -.. warning:: |
143 | | -
|
144 | | - This object is deprecated deprecated from version 2.8. It will be removed in the 2.9 release. |
145 | | - {msg} |
146 | | -{c.__doc__} |
147 | | - """ |
148 | | - return c |
149 | | - |
150 | | - |
151 | | -dropping_class_io_support = partial(dropping_class_support, msg=IO_DEPRECATION_MSG) |
152 | | - |
153 | | -dropping_io_support = deprecated(IO_DEPRECATION_MSG, version="2.9", remove=True) |
154 | | - |
155 | | - |
156 | 61 | def fail_with_message(message): |
157 | 62 | """Generate decorator to give users message about missing TorchAudio extension.""" |
158 | 63 |
|
|
0 commit comments