Skip to content

Commit a4a7a24

Browse files
authored
chore: add ruff linting rules and fix violations (#109)
* feat: configure ruff linting rules and ignore settings in pyproject.toml * fix: update import statements and formatting across multiple files * fix: replace os.path with pathlib for file handling and improve readability * fix: update test cases in test_utils.py for improved file handling and readability * fix: add flake8-type-checking configuration and reorder imports in schemas.py
1 parent ae406e3 commit a4a7a24

39 files changed

Lines changed: 225 additions & 164 deletions

examples/getting-started/01_simple_tts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
- Audio file contains the spoken text
1919
"""
2020

21-
import os
21+
from pathlib import Path
22+
2223
from fishaudio import FishAudio
2324
from fishaudio.utils import save
2425

@@ -43,7 +44,7 @@ def main():
4344
save(audio, output_file)
4445

4546
print(f"✓ Audio saved to {output_file}")
46-
print(f" File size: {os.path.getsize(output_file) / 1024:.2f} KB")
47+
print(f" File size: {Path(output_file).stat().st_size / 1024:.2f} KB")
4748

4849

4950
if __name__ == "__main__":

examples/getting_started.ipynb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@
3939
}
4040
},
4141
"outputs": [],
42-
"source": "from dotenv import load_dotenv\nfrom fishaudio import FishAudio\nfrom fishaudio.utils import play\n# from fishaudio.utils import save # Uncomment if saving audio to file\n\nload_dotenv()\n\nclient = FishAudio()"
42+
"source": [
43+
"from dotenv import load_dotenv\n",
44+
"\n",
45+
"from fishaudio import FishAudio\n",
46+
"from fishaudio.utils import play\n",
47+
"\n",
48+
"# from fishaudio.utils import save # Uncomment if saving audio to file\n",
49+
"\n",
50+
"load_dotenv()\n",
51+
"\n",
52+
"client = FishAudio()"
53+
]
4354
},
4455
{
4556
"cell_type": "markdown",

pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,34 @@ pages = [
8383
{title = "Exceptions", name="fishaudio/exceptions", contents = ["fishaudio.exceptions.*"] },
8484
]
8585

86+
[tool.ruff.lint]
87+
extend-select = [
88+
"F", # Pyflakes rules
89+
"W", # PyCodeStyle warnings
90+
"E", # PyCodeStyle errors
91+
"I", # Sort imports properly
92+
"UP", # Warn if certain things can changed due to newer Python versions
93+
"C4", # Catch incorrect use of comprehensions, dict, list, etc
94+
"FA", # Enforce from __future__ import annotations
95+
"ISC", # Good use of string concatenation
96+
"ICN", # Use common import conventions
97+
"RET", # Good return practices
98+
"SIM", # Common simplification rules
99+
"TID", # Some good import practices
100+
"TC", # Enforce importing certain types in a TYPE_CHECKING block
101+
"PTH", # Use pathlib instead of os.path
102+
"TD", # Be diligent with TODO comments
103+
"NPY", # Some numpy-specific things
104+
]
105+
ignore = [
106+
"E501", # Line too long (handled by ruff format)
107+
]
108+
109+
[tool.ruff.lint.flake8-type-checking]
110+
runtime-evaluated-base-classes = ["pydantic.BaseModel"]
111+
112+
[tool.ruff.lint.pyupgrade]
113+
keep-runtime-typing = true
114+
86115
[tool.uv.sources]
87116
fish-audio-sdk = { workspace = true }

scripts/copy_docs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
python scripts/copy_docs.py sdk docs # In CI context
1111
"""
1212

13+
from __future__ import annotations
14+
1315
import argparse
1416
import shutil
1517
from pathlib import Path

src/fish_audio_sdk/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
from .apis import Session
22
from .exceptions import HttpCodeErr, WebSocketErr
33
from .schemas import (
4+
APICreditEntity,
45
ASRRequest,
5-
TTSRequest,
6-
ReferenceAudio,
7-
Prosody,
8-
PaginatedResponse,
6+
CloseEvent,
97
ModelEntity,
10-
APICreditEntity,
8+
PaginatedResponse,
9+
Prosody,
10+
ReferenceAudio,
1111
StartEvent,
1212
TextEvent,
13-
CloseEvent,
13+
TTSRequest,
1414
)
15-
from .websocket import WebSocketSession, AsyncWebSocketSession
15+
from .websocket import AsyncWebSocketSession, WebSocketSession
1616

1717
__all__ = [
1818
"Session",

src/fish_audio_sdk/apis.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Generator, Literal
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Literal
24

35
import ormsgpack
46

@@ -7,13 +9,16 @@
79
APICreditEntity,
810
ASRRequest,
911
ASRResponse,
10-
ModelEntity,
1112
Backends,
13+
ModelEntity,
1214
PackageEntity,
1315
PaginatedResponse,
1416
TTSRequest,
1517
)
1618

19+
if TYPE_CHECKING:
20+
from collections.abc import Generator
21+
1722

1823
class Session(RemoteCall):
1924
@convert_stream

src/fish_audio_sdk/io.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
from __future__ import annotations
2+
13
import dataclasses
24
import typing
5+
from collections.abc import AsyncGenerator, Awaitable, Generator
36
from http.client import responses as http_responses
47
from typing import (
58
Any,
6-
AsyncGenerator,
7-
Awaitable,
89
Callable,
9-
Generator,
1010
Generic,
1111
TypeVar,
1212
)
1313

14-
from typing_extensions import Concatenate, ParamSpec
15-
1614
import httpx
1715
import httpx._client
1816
import httpx._types
17+
from typing_extensions import Concatenate, ParamSpec
1918

2019
from .exceptions import HttpCodeErr
2120

@@ -194,8 +193,7 @@ def sync_wrapper(self: RemoteCall, *args: P.args, **kwargs: P.kwargs) -> R:
194193
return exc.value
195194
raise RuntimeError("Generator did not stop")
196195

197-
call = IOCallDescriptor(async_wrapper, sync_wrapper)
198-
return call
196+
return IOCallDescriptor(async_wrapper, sync_wrapper)
199197

200198

201199
GStream = G[Generator[bytes, bytes, None]]
@@ -257,5 +255,4 @@ def sync_wrapper(
257255

258256
raise RuntimeError("Generator did not stop")
259257

260-
call = StreamIOCallDescriptor(async_wrapper, sync_wrapper)
261-
return call
258+
return StreamIOCallDescriptor(async_wrapper, sync_wrapper)

src/fish_audio_sdk/schemas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from __future__ import annotations
2+
13
import datetime
24
import decimal
35
from typing import Annotated, Generic, Literal, TypeVar
46

57
from pydantic import BaseModel, Field
68

7-
89
Backends = Literal["speech-1.5", "speech-1.6", "agent-x0", "s1", "s1-mini"]
910

1011
Item = TypeVar("Item")

src/fish_audio_sdk/websocket.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import asyncio
2+
from collections.abc import AsyncGenerator, AsyncIterable, Generator, Iterable
23
from concurrent.futures import ThreadPoolExecutor
3-
from typing import AsyncGenerator, AsyncIterable, Generator, Iterable
44

55
import httpx
66
import ormsgpack
7-
from httpx_ws import WebSocketDisconnect, connect_ws, aconnect_ws
7+
from httpx_ws import WebSocketDisconnect, aconnect_ws, connect_ws
88

99
from .exceptions import WebSocketErr
10-
11-
from .schemas import Backends, CloseEvent, StartEvent, TTSRequest, TextEvent
10+
from .schemas import Backends, CloseEvent, StartEvent, TextEvent, TTSRequest
1211

1312

1413
class WebSocketSession:

src/fishaudio/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from .core import AsyncClientWrapper, ClientWrapper
88
from .resources import (
9-
ASRClient,
109
AccountClient,
10+
ASRClient,
1111
AsyncAccountClient,
1212
AsyncASRClient,
1313
AsyncTTSClient,

0 commit comments

Comments
 (0)