Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
b8225807
"docs/git@developer.sourcefind.cn:OpenDAS/mmcv.git" did not exist on "d00b0cec744df6fca29c67cc5f94d236596c43ba"
Unverified
Commit
b8225807
authored
Jun 11, 2020
by
moto
Committed by
GitHub
Jun 11, 2020
Browse files
Add deprecation warning to initialize/shutdown_sox (#709)
parent
08217121
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
10 deletions
+61
-10
torchaudio/__init__.py
torchaudio/__init__.py
+27
-2
torchaudio/_internal/module_utils.py
torchaudio/_internal/module_utils.py
+21
-0
torchaudio/sox_effects/sox_effects.py
torchaudio/sox_effects/sox_effects.py
+13
-8
No files found.
torchaudio/__init__.py
View file @
b8225807
...
@@ -2,6 +2,7 @@ from pathlib import Path
...
@@ -2,6 +2,7 @@ from pathlib import Path
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
,
Union
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
,
Union
from
torch
import
Tensor
from
torch
import
Tensor
from
torchaudio._internal
import
module_utils
as
_mod_utils
from
torchaudio
import
(
from
torchaudio
import
(
compliance
,
compliance
,
datasets
,
datasets
,
...
@@ -24,8 +25,8 @@ from torchaudio.backend import (
...
@@ -24,8 +25,8 @@ from torchaudio.backend import (
EncodingInfo
,
EncodingInfo
,
)
)
from
torchaudio.sox_effects
import
(
from
torchaudio.sox_effects
import
(
init_sox_effects
as
init
ialize_sox
,
init_sox_effects
as
_
init
_sox_effects
,
shutdown_sox_effects
as
shutdown_sox
,
shutdown_sox_effects
as
_
shutdown_sox
_effects
,
)
)
try
:
try
:
...
@@ -34,6 +35,30 @@ except ImportError:
...
@@ -34,6 +35,30 @@ except ImportError:
pass
pass
@
_mod_utils
.
deprecated
(
"Please remove the function call to initialize_sox. "
"Resource initialization is now automatically handled."
)
def
initialize_sox
()
->
int
:
"""Initialize sox effects.
This function is deprecated. See ``torchaudio.sox_effects.init_sox_effects``
"""
_init_sox_effects
()
@
_mod_utils
.
deprecated
(
"Please remove the function call to torchaudio.shutdown_sox. "
"Resource clean up is now automatically handled. "
"In the unlikely event that you need to manually shutdown sox, "
"please use torchaudio.sox_effects.shutdown_sox_effects."
)
def
shutdown_sox
():
"""Shutdown sox effects.
This function is deprecated. See ``torchaudio.sox_effects.shutdown_sox_effects``
"""
_shutdown_sox_effects
()
def
load
(
filepath
:
Union
[
str
,
Path
],
def
load
(
filepath
:
Union
[
str
,
Path
],
out
:
Optional
[
Tensor
]
=
None
,
out
:
Optional
[
Tensor
]
=
None
,
normalization
:
Union
[
bool
,
float
,
Callable
]
=
True
,
normalization
:
Union
[
bool
,
float
,
Callable
]
=
True
,
...
...
torchaudio/_internal/module_utils.py
View file @
b8225807
import
warnings
import
importlib.util
import
importlib.util
from
typing
import
Optional
from
functools
import
wraps
from
functools
import
wraps
...
@@ -33,3 +35,22 @@ def requires_module(*modules: str):
...
@@ -33,3 +35,22 @@ def requires_module(*modules: str):
raise
RuntimeError
(
f
'
{
func
.
__module__
}
.
{
func
.
__name__
}
requires
{
req
}
'
)
raise
RuntimeError
(
f
'
{
func
.
__module__
}
.
{
func
.
__name__
}
requires
{
req
}
'
)
return
wrapped
return
wrapped
return
decorator
return
decorator
def
deprecated
(
direction
:
str
,
version
:
Optional
[
str
]
=
None
):
"""Decorator to add deprecation message
Args:
direction: Migration steps to be given to users.
"""
def
decorator
(
func
):
@
wraps
(
func
)
def
wrapped
(
*
args
,
**
kwargs
):
message
=
(
f
'
{
func
.
__module__
}
.
{
func
.
__name__
}
has been deprecated '
f
'and will be removed from
{
"future"
if
version
is
None
else
version
}
release.'
f
'
{
direction
}
'
)
warnings
.
warn
(
message
,
stacklevel
=
2
)
return
func
(
*
args
,
**
kwargs
)
return
wrapped
return
decorator
torchaudio/sox_effects/sox_effects.py
View file @
b8225807
...
@@ -26,12 +26,15 @@ _SOX_SUCCESS_CODE = 0
...
@@ -26,12 +26,15 @@ _SOX_SUCCESS_CODE = 0
@
_mod_utils
.
requires_module
(
'torchaudio._torchaudio'
)
@
_mod_utils
.
requires_module
(
'torchaudio._torchaudio'
)
def
init_sox_effects
()
->
int
:
def
init_sox_effects
()
->
int
:
"""Initialize
sox for use with e
ffects
c
hain
s.
"""Initialize
resources required to use ``SoxE
ffects
C
hain
``
You only need to call this function once to use SoX effects chains multiple times.
You do not need to call this function manually. It is called automatically.
It is safe to call this function multiple times as long as ``shutdown_sox`` is not yet called.
Once ``shutdown_sox`` is called, you can no longer use SoX effects and calling this function
Once initialized, you do not need to call this function again across the multiple call of
results in `RuntimeError`.
``SoxEffectsChain.sox_build_flow_effects``, though it is safe to do so as long as
``shutdown_sox_effects`` is not called yet.
Once ``shutdown_sox_effects`` is called, you can no longer use SoX effects and calling
this function results in `RuntimeError`.
Note:
Note:
This function is not required for simple loading.
This function is not required for simple loading.
...
@@ -54,12 +57,14 @@ def init_sox_effects() -> int:
...
@@ -54,12 +57,14 @@ def init_sox_effects() -> int:
@
_mod_utils
.
requires_module
(
"torchaudio._torchaudio"
)
@
_mod_utils
.
requires_module
(
"torchaudio._torchaudio"
)
def
shutdown_sox_effects
()
->
int
:
def
shutdown_sox_effects
()
->
int
:
"""
Showdown sox for e
ffects
c
hain
.
"""
Clean up resources required to use ``SoxE
ffects
C
hain
``
You do not need to call this function as it will be called automatically
You do not need to call this function manually. It is called automatically.
at the end of program execution, if ``initialize_sox`` was called.
It is safe to call this function multiple times.
It is safe to call this function multiple times.
Once ``shutdown_sox_effects`` is called, you can no longer use SoX effects and calling
this function results in `RuntimeError`.
Returns:
Returns:
int: Code corresponding to sox_error_t enum. See
int: Code corresponding to sox_error_t enum. See
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment