From 41c806fda8db8fe64f8f205fd7d44ff7721f9f88 Mon Sep 17 00:00:00 2001 From: monster-zzx <149377846+monster-zzx@users.noreply.github.com> Date: Sun, 19 Jan 2025 03:59:31 +0800 Subject: [PATCH 1/3] feat(pyproject): Make the program compatible with more versions of python Make the program currently compatible with python 3.10, 3.11, and 3.12 Fix some syntax conflicts between versions --- pyproject.toml | 2 +- yadt/document_il/backend/pdf_creater.py | 15 +++++---------- yadt/document_il/translator/translator.py | 3 +-- yadt/high_level.py | 5 ++--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9e6dd57..eb3af2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/yadt/document_il/backend/pdf_creater.py b/yadt/document_il/backend/pdf_creater.py index 8eeac2e..df5b18d 100644 --- a/yadt/document_il/backend/pdf_creater.py +++ b/yadt/document_il/backend/pdf_creater.py @@ -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( @@ -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() ) # 收集所有字符 @@ -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] diff --git a/yadt/document_il/translator/translator.py b/yadt/document_il/translator/translator.py index 3f56343..c34d77d 100644 --- a/yadt/document_il/translator/translator.py +++ b/yadt/document_il/translator/translator.py @@ -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): diff --git a/yadt/high_level.py b/yadt/high_level.py index 07e644d..23c40a5 100644 --- a/yadt/high_level.py +++ b/yadt/high_level.py @@ -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" + ) From d208066c33f6fdba13548308402bd5e6fdb0c98f Mon Sep 17 00:00:00 2001 From: monster-zzx <149377846+monster-zzx@users.noreply.github.com> Date: Sun, 19 Jan 2025 22:09:29 +0800 Subject: [PATCH 2/3] ci(test): setup github actions workflow for python testing --- .github/workflows/test3.10.yml | 35 ++++++++++++++++++++ .github/workflows/test3.11.yml | 35 ++++++++++++++++++++ .github/workflows/{test.yml => test3.12.yml} | 0 3 files changed, 70 insertions(+) create mode 100644 .github/workflows/test3.10.yml create mode 100644 .github/workflows/test3.11.yml rename .github/workflows/{test.yml => test3.12.yml} (100%) diff --git a/.github/workflows/test3.10.yml b/.github/workflows/test3.10.yml new file mode 100644 index 0000000..fba62bc --- /dev/null +++ b/.github/workflows/test3.10.yml @@ -0,0 +1,35 @@ +name: Run Tests 🧪 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + name: Run Python Tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup uv + uses: yezz123/setup-uv@v4.1 + with: + uv-venv: ".venv" + + - name: Run tests + run: | + uv run yadt --help + uv run yadt --bing --files examples/pdf/il_try_1/这是一个测试文件.pdf \ No newline at end of file diff --git a/.github/workflows/test3.11.yml b/.github/workflows/test3.11.yml new file mode 100644 index 0000000..53906ff --- /dev/null +++ b/.github/workflows/test3.11.yml @@ -0,0 +1,35 @@ +name: Run Tests 🧪 + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + name: Run Python Tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup uv + uses: yezz123/setup-uv@v4.1 + with: + uv-venv: ".venv" + + - name: Run tests + run: | + uv run yadt --help + uv run yadt --bing --files examples/pdf/il_try_1/这是一个测试文件.pdf \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test3.12.yml similarity index 100% rename from .github/workflows/test.yml rename to .github/workflows/test3.12.yml From e34fa20a03e9d0bc29305103c6259ba839e848aa Mon Sep 17 00:00:00 2001 From: monster-zzx <149377846+monster-zzx@users.noreply.github.com> Date: Mon, 20 Jan 2025 10:00:59 +0800 Subject: [PATCH 3/3] ci(test): setup github actions workflow for python testing --- .coverage | Bin 0 -> 53248 bytes .github/workflows/{test3.10.yml => test.yml} | 2 +- .github/workflows/test3.11.yml | 35 ------------------- .github/workflows/test3.12.yml | 35 ------------------- 4 files changed, 1 insertion(+), 71 deletions(-) create mode 100644 .coverage rename .github/workflows/{test3.10.yml => test.yml} (93%) delete mode 100644 .github/workflows/test3.11.yml delete mode 100644 .github/workflows/test3.12.yml diff --git a/.coverage b/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..40c4687dce1b01fc6fd7344931d37f2990fc74d3 GIT binary patch literal 53248 zcmeI)O>Y}T7zgm(r1i#5A_qm073Gk*fMeBmv5-K(0RrSuQK=LnE=aiJ^*CAZ?mGLD zmjgm>ks^Wk28i#(7wL@?7oKNk*J~$n)mx?Qe-%6XGBZ2#n`dV1ZrkskKK2qNMq%X3 zM0{XvS+;F`E`()SYxLTrSH3y4b1y%j-}c=8vfVYSd;Z5}{d;Sp@~2h*aq~&Nv+>vF zd+Yyf_|@On|8`{6r3=^~009U<;O!QeKHYE{ySw)DUlKVOt0a=Hip=}wm){;89v_M0 z!!I5m33E;y)C6svjyM!icp)Y#5+iS{gcl4wS0-L?B9c>;r%q!v6y9LiyCoP^7AF3X#QSz}+jZ|>;JqP+{GM`!rb(!e`_%dU9=&b+_RgBq z*x$FW&vc+LPk-Pg@ocBM5Hz#XOG1aQFOM4@C5u7Aqi8%9;Ybe|&Mi#mP&ChvnTI)s zjCi1lFiS`^eWTIFm8Cj}!8jZ&#+r_pSkVBXxgbwAN&}aNO3ZC=!*dnM6V=VGnrY!p z2NH!&uUcsw?Jo*A!43=k}DUrIXX}{w9oLkCs(l zw&G9nv!Zz_W1fZLrWl0bSjoVw4V2?iO!xF+q3dvaRr;(bBfjD?PR^UUPWj@()BG_F zx_o@mj_=E0n5|d544YDE?&rbD_c4>FFl}uFP`ATpST^Su%7cv%Zr0628rLE@btHOYLtKZ{y{+7(&o~`M= z?KB=du%~G@7|lG>k7-f&WnS&00Izz00bZa0SG_<0uX?}O#y!X zPygv3HV8lf0uX=z1Rwwb2tWV=5P$##N-Tiq|0V8RGz|g}fB*y_009U<00Izz00bbA z3E=rZLIDC0fB*y_009U<00Izz00baVegQoHFMl7Sg%E%M1Rwwb2tWV=5P$##AOHb8 z|3?f!00Izz00bZa0SG_<0uX=z1j;Xf=l|vJW3&(g5P$##AOHafKmY;|fB*y_fam{+ z0SG_<0uX=z1Rwwb2tWV=5P(4W1@Qd8{C$iTLI45~fB*y_009U<00Izz00jOAfG!lK literal 0 HcmV?d00001 diff --git a/.github/workflows/test3.10.yml b/.github/workflows/test.yml similarity index 93% rename from .github/workflows/test3.10.yml rename to .github/workflows/test.yml index fba62bc..e03d388 100644 --- a/.github/workflows/test3.10.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/test3.11.yml b/.github/workflows/test3.11.yml deleted file mode 100644 index 53906ff..0000000 --- a/.github/workflows/test3.11.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Run Tests 🧪 - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - test: - name: Run Python Tests - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.11"] - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Setup uv - uses: yezz123/setup-uv@v4.1 - with: - uv-venv: ".venv" - - - name: Run tests - run: | - uv run yadt --help - uv run yadt --bing --files examples/pdf/il_try_1/这是一个测试文件.pdf \ No newline at end of file diff --git a/.github/workflows/test3.12.yml b/.github/workflows/test3.12.yml deleted file mode 100644 index 53995b9..0000000 --- a/.github/workflows/test3.12.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Run Tests 🧪 - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - test: - name: Run Python Tests - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.12"] - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Setup uv - uses: yezz123/setup-uv@v4.1 - with: - uv-venv: ".venv" - - - name: Run tests - run: | - uv run yadt --help - uv run yadt --bing --files examples/pdf/il_try_1/这是一个测试文件.pdf \ No newline at end of file