Skip to content

Commit

Permalink
Merge pull request #21 from monster-zzx/compatibility
Browse files Browse the repository at this point in the history
feat(compatibility): Supports Python 3.10 and 3.11
  • Loading branch information
awwaawwa authored Jan 20, 2025
2 parents 840b944 + e34fa20 commit 1fe2297
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
Binary file added .coverage
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.1a19"
description = "Yet Another Document Translator"
license = "AGPL-3.0"
readme = "README.md"
requires-python = ">=3.12,<3.13"
requires-python = ">=3.10,<3.13"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
Expand Down
15 changes: 5 additions & 10 deletions yadt/document_il/backend/pdf_creater.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ def render_graphic_state(
draw_op.append(f"{graphic_state.ncolor[0]} g \n".encode())
elif len(graphic_state.ncolor) == 3:
draw_op.append(
f"{' '.join((str(x)
for x in graphic_state.ncolor))} sc \n".encode()
f"{' '.join((str(x) for x in graphic_state.ncolor))} sc \n".encode()
)
if graphic_state.scolor is not None:
if len(graphic_state.scolor) == 1:
draw_op.append(f"{graphic_state.scolor[0]} G \n".encode())
elif len(graphic_state.scolor) == 3:
draw_op.append(
f"{' '.join((str(x)
for x in graphic_state.scolor))} SC \n".encode()
f"{' '.join((str(x) for x in graphic_state.scolor))} SC \n".encode()
)

def render_paragraph_to_char(
Expand Down Expand Up @@ -175,8 +173,7 @@ def write(self, translation_config: TranslationConfig):
draw_op.append(page.base_operations.value.encode())
draw_op.append(b" Q ")
draw_op.append(
f"q Q 1 0 0 1 {page.cropbox.box.x} {
page.cropbox.box.y} cm \n".encode()
f"q Q 1 0 0 1 {page.cropbox.box.x} {page.cropbox.box.y} cm \n".encode()
)

# 收集所有字符
Expand Down Expand Up @@ -205,13 +202,11 @@ def write(self, translation_config: TranslationConfig):
)
if char.vertical:
draw_op.append(
f"BT /{font_id} {char_size:f} Tf 0 1 -1 0 {
char.box.x2:f} {char.box.y:f} Tm ".encode()
f"BT /{font_id} {char_size:f} Tf 0 1 -1 0 {char.box.x2:f} {char.box.y:f} Tm ".encode()
)
else:
draw_op.append(
f"BT /{font_id} {char_size:f} Tf 1 0 0 1 {
char.box.x:f} {char.box.y:f} Tm ".encode()
f"BT /{font_id} {char_size:f} Tf 1 0 0 1 {char.box.x:f} {char.box.y:f} Tm ".encode()
)

encoding_length = encoding_length_map[font_id]
Expand Down
3 changes: 1 addition & 2 deletions yadt/document_il/translator/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def __init__(self, lang_in, lang_out, ignore_cache):
def __del__(self):
print(f"{self.name} translate call count: {self.translate_call_count}")
print(
f"{self.name} translate cache call count: {
self.translate_cache_call_count}"
f"{self.name} translate cache call count: {self.translate_cache_call_count}"
)

def add_cache_impact_parameters(self, k: str, v):
Expand Down
5 changes: 2 additions & 3 deletions yadt/high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,5 @@ def translate(translation_config: TranslationConfig):
finish_time = time.time()

logger.info(
f"finish translate: {original_pdf_path}, cost: {
finish_time - start_time} s"
)
f"finish translate: {original_pdf_path}, cost: {finish_time - start_time} s"
)

0 comments on commit 1fe2297

Please sign in to comment.