Skip to content

Commit ba04ff0

Browse files
committed
fix: ruff it
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
1 parent 938555e commit ba04ff0

File tree

11 files changed

+22
-28
lines changed

11 files changed

+22
-28
lines changed

book_maker/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def main():
402402
options = parser.parse_args()
403403

404404
if not options.book_name:
405-
print(f"Error: please provide the path of your book using --book_name <path>")
405+
print("Error: please provide the path of your book using --book_name <path>")
406406
exit(1)
407407
if not os.path.isfile(options.book_name):
408408
print(f"Error: the book {options.book_name!r} does not exist.")

book_maker/loader/epub_loader.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _make_new_book(self, book):
137137
def _extract_paragraph(self, p):
138138
for p_exclude in self.exclude_translate_tags.split(","):
139139
# for issue #280
140-
if type(p) == NavigableString:
140+
if type(p) is NavigableString:
141141
continue
142142
for pt in p.find_all(p_exclude):
143143
pt.extract()
@@ -154,7 +154,7 @@ def _process_paragraph(self, p, new_p, index, p_to_save_len):
154154
t_text = self.translate_model.batch_translate(index)
155155
else:
156156
t_text = self.translate_model.translate(new_p.text)
157-
if type(p) == NavigableString:
157+
if type(p) is NavigableString:
158158
new_p = t_text
159159
self.p_to_save.append(new_p)
160160
else:
@@ -198,7 +198,7 @@ def _process_combined_paragraph(self, p_block, index, p_to_save_len):
198198
else:
199199
p = p_block[i]
200200

201-
if type(p) == NavigableString:
201+
if type(p) is NavigableString:
202202
p = t
203203
else:
204204
p.string = t
@@ -220,7 +220,7 @@ def translate_paragraphs_acc(self, p_list, send_num):
220220

221221
for p_exclude in self.exclude_translate_tags.split(","):
222222
# for issue #280
223-
if type(p) == NavigableString:
223+
if type(p) is NavigableString:
224224
continue
225225
for pt in temp_p.find_all(p_exclude):
226226
pt.extract()
@@ -381,7 +381,7 @@ def process_item(
381381
fixstart=None,
382382
fixend=None,
383383
):
384-
if self.only_filelist != "" and not item.file_name in self.only_filelist.split(
384+
if self.only_filelist != "" and item.file_name not in self.only_filelist.split(
385385
","
386386
):
387387
return index
@@ -587,7 +587,7 @@ def _save_temp_book(self):
587587
# PR welcome here
588588
if index < p_to_save_len:
589589
new_p = copy(p)
590-
if type(p) == NavigableString:
590+
if type(p) is NavigableString:
591591
new_p = self.p_to_save[index]
592592
else:
593593
new_p.string = self.p_to_save[index]

book_maker/loader/md_loader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def _save_progress(self):
160160
try:
161161
with open(self.bin_path, "w", encoding="utf-8") as f:
162162
f.write("\n".join(self.p_to_save))
163-
except:
164-
raise Exception("can not save resume file")
163+
except Exception as e:
164+
raise Exception("can not save resume file") from e
165165

166166
def load_state(self):
167167
try:
@@ -174,5 +174,5 @@ def save_file(self, book_path, content):
174174
try:
175175
with open(book_path, "w", encoding="utf-8") as f:
176176
f.write("\n".join(content))
177-
except:
178-
raise Exception("can not save file")
177+
except Exception as e:
178+
raise Exception("can not save file") from e

book_maker/loader/srt_loader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def make_bilingual_book(self):
215215
translated_blocks, self.blocks[begin:end]
216216
):
217217
raise Exception(
218-
f"retry failed, adjust the srt manually."
218+
"retry failed, adjust the srt manually."
219219
)
220220

221221
for i, block in enumerate(translated_blocks):
@@ -276,8 +276,8 @@ def _save_progress(self):
276276
try:
277277
with open(self.bin_path, "w", encoding="utf-8") as f:
278278
f.write("===".join(self.p_to_save))
279-
except:
280-
raise Exception("can not save resume file")
279+
except Exception as e:
280+
raise Exception("can not save resume file") from e
281281

282282
def load_state(self):
283283
try:
@@ -295,5 +295,5 @@ def save_file(self, book_path, content):
295295
try:
296296
with open(book_path, "w", encoding="utf-8") as f:
297297
f.write("\n\n".join(content))
298-
except:
299-
raise Exception("can not save file")
298+
except Exception as e:
299+
raise Exception("can not save file") from e

book_maker/loader/txt_loader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def _save_progress(self):
125125
try:
126126
with open(self.bin_path, "w", encoding="utf-8") as f:
127127
f.write("\n".join(self.p_to_save))
128-
except:
129-
raise Exception("can not save resume file")
128+
except Exception as e:
129+
raise Exception("can not save resume file") from e
130130

131131
def load_state(self):
132132
try:
@@ -139,5 +139,5 @@ def save_file(self, book_path, content):
139139
try:
140140
with open(book_path, "w", encoding="utf-8") as f:
141141
f.write("\n".join(content))
142-
except:
143-
raise Exception("can not save file")
142+
except Exception as e:
143+
raise Exception("can not save file") from e

book_maker/translator/claude_translator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import re
2-
import time
32
from rich import print
43
from anthropic import Anthropic
54

book_maker/translator/deepl_free_translator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class DeepLFree(Base):
1616

1717
def __init__(self, key, language, **kwargs) -> None:
1818
super().__init__(key, language)
19-
l = None
2019
l = language if language in LANGUAGES else TO_LANGUAGE_CODE.get(language)
2120
if l not in [
2221
"bg",

book_maker/translator/deepl_translator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def __init__(self, key, language, **kwargs) -> None:
2323
"X-RapidAPI-Key": "",
2424
"X-RapidAPI-Host": "dpl-translator.p.rapidapi.com",
2525
}
26-
l = None
2726
l = language if language in LANGUAGES else TO_LANGUAGE_CODE.get(language)
2827
if l not in [
2928
"bg",

book_maker/translator/google_translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import requests
33
from rich import print
44

5-
from book_maker.utils import TO_LANGUAGE_CODE, LANGUAGES
5+
from book_maker.utils import TO_LANGUAGE_CODE
66
from .base_translator import Base
77

88

book_maker/translator/qwen_translator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
22
import time
3-
from os import environ
43
from rich import print
54
from openai import OpenAI
65

@@ -100,7 +99,7 @@ def __init__(
10099
self.context_translated_list = []
101100
self.context_paragraph_limit = context_paragraph_limit
102101

103-
print(f"[bold blue]Qwen Translator initialized:[/bold blue]")
102+
print("[bold blue]Qwen Translator initialized:[/bold blue]")
104103
print(f" Model: {self.model}")
105104
print(f" Source Language: {self.source_lang}")
106105
print(f" Target Language: {self.target_lang}")

0 commit comments

Comments
 (0)