cartesia 1.0.1__tar.gz → 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cartesia-1.0.1 → cartesia-1.0.3}/PKG-INFO +1 -1
- cartesia-1.0.3/cartesia/utils/__init__.py +0 -0
- cartesia-1.0.3/cartesia/utils/deprecated.py +53 -0
- cartesia-1.0.3/cartesia/utils/retry.py +87 -0
- cartesia-1.0.3/cartesia/version.py +1 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia.egg-info/PKG-INFO +1 -1
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia.egg-info/SOURCES.txt +3 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/setup.py +9 -1
- cartesia-1.0.1/cartesia/version.py +0 -1
- {cartesia-1.0.1 → cartesia-1.0.3}/README.md +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia/__init__.py +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia/_types.py +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia/client.py +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia.egg-info/dependency_links.txt +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia.egg-info/requires.txt +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/cartesia.egg-info/top_level.txt +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/pyproject.toml +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/setup.cfg +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/tests/test_deprecated.py +0 -0
- {cartesia-1.0.1 → cartesia-1.0.3}/tests/test_tts.py +0 -0
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import os
|
2
|
+
import warnings
|
3
|
+
from typing import Any, Callable, TypeVar
|
4
|
+
|
5
|
+
TCallable = TypeVar("TCallable", bound=Callable[..., Any])
|
6
|
+
|
7
|
+
# List of statistics of deprecated functions.
|
8
|
+
# This should only be used by the test suite to find any deprecated functions
|
9
|
+
# that should be removed for this version.
|
10
|
+
_TRACK_DEPRECATED_FUNCTION_STATS = os.environ.get("CARTESIA_TEST_DEPRECATED", "").lower() == "true"
|
11
|
+
_DEPRECATED_FUNCTION_STATS = []
|
12
|
+
|
13
|
+
|
14
|
+
def deprecated(
|
15
|
+
reason=None, vdeprecated=None, vremove=None, replacement=None
|
16
|
+
) -> Callable[[TCallable], TCallable]:
|
17
|
+
local_vars = locals()
|
18
|
+
|
19
|
+
def fn(func: TCallable) -> TCallable:
|
20
|
+
msg = _get_deprecated_msg(func, reason, vdeprecated, vremove, replacement)
|
21
|
+
warnings.warn(msg, DeprecationWarning)
|
22
|
+
return func
|
23
|
+
|
24
|
+
if _TRACK_DEPRECATED_FUNCTION_STATS: # pragma: no cover
|
25
|
+
_DEPRECATED_FUNCTION_STATS.append(local_vars)
|
26
|
+
|
27
|
+
return fn
|
28
|
+
|
29
|
+
|
30
|
+
def _get_deprecated_msg(wrapped, reason, vdeprecated, vremoved, replacement=None):
|
31
|
+
fmt = "{name} is deprecated"
|
32
|
+
if vdeprecated:
|
33
|
+
fmt += " since v{vdeprecated}"
|
34
|
+
if vremoved:
|
35
|
+
fmt += " and will be removed in v{vremoved}"
|
36
|
+
fmt += "."
|
37
|
+
|
38
|
+
if reason:
|
39
|
+
fmt += " ({reason})"
|
40
|
+
if replacement:
|
41
|
+
fmt += " -- Use {replacement} instead."
|
42
|
+
|
43
|
+
return fmt.format(
|
44
|
+
name=wrapped.__name__,
|
45
|
+
reason=reason or "",
|
46
|
+
vdeprecated=vdeprecated or "",
|
47
|
+
vremoved=vremoved or "",
|
48
|
+
replacement=replacement or "",
|
49
|
+
)
|
50
|
+
|
51
|
+
|
52
|
+
# This method is taken from the following source:
|
53
|
+
# https://github.com/ad12/meddlr/blob/main/meddlr/utils/deprecated.py
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import time
|
2
|
+
|
3
|
+
from aiohttp.client_exceptions import ServerDisconnectedError
|
4
|
+
import asyncio
|
5
|
+
from functools import wraps
|
6
|
+
from http.client import RemoteDisconnected
|
7
|
+
from httpx import TimeoutException
|
8
|
+
from requests.exceptions import ConnectionError
|
9
|
+
|
10
|
+
|
11
|
+
def retry_on_connection_error(max_retries=3, backoff_factor=1, logger=None):
|
12
|
+
"""Retry a function if a ConnectionError, RemoteDisconnected, ServerDisconnectedError, or TimeoutException occurs.
|
13
|
+
|
14
|
+
Args:
|
15
|
+
max_retries (int): The maximum number of retries.
|
16
|
+
backoff_factor (int): The factor to increase the delay between retries.
|
17
|
+
logger (logging.Logger): The logger to use for logging.
|
18
|
+
"""
|
19
|
+
|
20
|
+
def decorator(func):
|
21
|
+
@wraps(func)
|
22
|
+
def wrapper(*args, **kwargs):
|
23
|
+
retry_count = 0
|
24
|
+
while retry_count < max_retries:
|
25
|
+
try:
|
26
|
+
return func(*args, **kwargs)
|
27
|
+
except (
|
28
|
+
ConnectionError,
|
29
|
+
RemoteDisconnected,
|
30
|
+
ServerDisconnectedError,
|
31
|
+
TimeoutException,
|
32
|
+
) as e:
|
33
|
+
logger.info(f"Retrying after exception: {e}")
|
34
|
+
retry_count += 1
|
35
|
+
if retry_count < max_retries:
|
36
|
+
delay = backoff_factor * (2 ** (retry_count - 1))
|
37
|
+
logger.warn(
|
38
|
+
f"Attempt {retry_count + 1}/{max_retries} in {delay} seconds..."
|
39
|
+
)
|
40
|
+
time.sleep(delay)
|
41
|
+
else:
|
42
|
+
raise Exception(f"Exception occurred after {max_retries} tries.") from e
|
43
|
+
|
44
|
+
return wrapper
|
45
|
+
|
46
|
+
return decorator
|
47
|
+
|
48
|
+
|
49
|
+
def retry_on_connection_error_async(max_retries=3, backoff_factor=1, logger=None):
|
50
|
+
"""Retry an asynchronous function if a ConnectionError, RemoteDisconnected, ServerDisconnectedError, or TimeoutException occurs.
|
51
|
+
|
52
|
+
Args:
|
53
|
+
max_retries (int): The maximum number of retries.
|
54
|
+
backoff_factor (int): The factor to increase the delay between retries.
|
55
|
+
logger (logging.Logger): The logger to use for logging.
|
56
|
+
"""
|
57
|
+
|
58
|
+
def decorator(func):
|
59
|
+
@wraps(func)
|
60
|
+
async def wrapper(*args, **kwargs):
|
61
|
+
retry_count = 0
|
62
|
+
while retry_count < max_retries:
|
63
|
+
try:
|
64
|
+
async for chunk in func(*args, **kwargs):
|
65
|
+
yield chunk
|
66
|
+
# If the function completes without raising an exception return
|
67
|
+
return
|
68
|
+
except (
|
69
|
+
ConnectionError,
|
70
|
+
RemoteDisconnected,
|
71
|
+
ServerDisconnectedError,
|
72
|
+
TimeoutException,
|
73
|
+
) as e:
|
74
|
+
logger.info(f"Retrying after exception: {e}")
|
75
|
+
retry_count += 1
|
76
|
+
if retry_count < max_retries:
|
77
|
+
delay = backoff_factor * (2 ** (retry_count - 1))
|
78
|
+
logger.warn(
|
79
|
+
f"Attempt {retry_count + 1}/{max_retries} in {delay} seconds..."
|
80
|
+
)
|
81
|
+
await asyncio.sleep(delay)
|
82
|
+
else:
|
83
|
+
raise Exception(f"Exception occurred after {max_retries} tries.") from e
|
84
|
+
|
85
|
+
return wrapper
|
86
|
+
|
87
|
+
return decorator
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "1.0.3"
|
@@ -10,5 +10,8 @@ cartesia.egg-info/SOURCES.txt
|
|
10
10
|
cartesia.egg-info/dependency_links.txt
|
11
11
|
cartesia.egg-info/requires.txt
|
12
12
|
cartesia.egg-info/top_level.txt
|
13
|
+
cartesia/utils/__init__.py
|
14
|
+
cartesia/utils/deprecated.py
|
15
|
+
cartesia/utils/retry.py
|
13
16
|
tests/test_deprecated.py
|
14
17
|
tests/test_tts.py
|
@@ -268,7 +268,15 @@ setup(
|
|
268
268
|
author_email=EMAIL,
|
269
269
|
python_requires=REQUIRES_PYTHON,
|
270
270
|
url=URL,
|
271
|
-
packages=
|
271
|
+
packages=find_packages(
|
272
|
+
exclude=[
|
273
|
+
"scratch",
|
274
|
+
"tests",
|
275
|
+
"*.tests",
|
276
|
+
"*.tests.*",
|
277
|
+
"tests.*",
|
278
|
+
]
|
279
|
+
),
|
272
280
|
install_requires=REQUIRED,
|
273
281
|
extras_require=EXTRAS,
|
274
282
|
include_package_data=True,
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "1.0.1"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|