BabelDOC 0.3.17__tar.gz → 0.3.18__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.
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/workflows/docs.yml +1 -1
- babeldoc-0.3.18/.github/workflows/lint.yml +17 -0
- babeldoc-0.3.18/.github/workflows/pr-lint.yml +46 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/workflows/publish-to-pypi.yml +1 -1
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/workflows/test.yml +1 -1
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.gitignore +1 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/PKG-INFO +1 -1
- babeldoc-0.3.18/babeldoc/__init__.py +1 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/const.py +1 -1
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/backend/pdf_creater.py +4 -4
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/frontend/il_creater.py +16 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/paragraph_finder.py +1 -1
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/styles_and_formulas.py +2 -2
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/typesetting.py +3 -3
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/docvision/rpc_doclayout.py +2 -2
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/high_level.py +2 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/main.py +1 -1
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/translation_config.py +1 -1
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/CONTRIBUTING.md +6 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/pyproject.toml +4 -3
- {babeldoc-0.3.17 → babeldoc-0.3.18}/uv.lock +1252 -1161
- babeldoc-0.3.17/babeldoc/__init__.py +0 -1
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.cursorignore +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/ISSUE_TEMPLATE/feature_request.yaml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/PULL_REQUEST_TEMPLATE/pr_form.yml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/dependabot.yml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/labels.yml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/release-drafter.yml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/workflows/codeql.yml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.github/workflows/labeler.yml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/.pre-commit-config.yaml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/LICENSE +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/README.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/assets/assets.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/assets/embedding_assets_metadata.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/asynchronize/__init__.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/converter.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/__init__.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/babeldoc_exception/BabelDOCException.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/backend/__init__.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/frontend/__init__.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/il_version_1.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/il_version_1.rnc +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/il_version_1.rng +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/il_version_1.xsd +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/__init__.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/add_debug_information.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/detect_scanned_file.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/il_translator.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/il_translator_llm_only.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/layout_parser.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/remove_descent.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/midend/table_parser.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/translator/__init__.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/translator/cache.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/translator/translator.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/utils/atomic_integer.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/utils/fontmap.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/utils/layout_helper.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/utils/priority_thread_pool_executor.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/utils/style_helper.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/document_il/xml_converter.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/docvision/README.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/docvision/__init__.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/docvision/doclayout.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/docvision/table_detection/rapidocr.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/pdfinterp.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/progress_monitor.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/result_merger.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/split_manager.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/tools/generate_font_metadata.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/tools/italic_assistance.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/babeldoc/tools/italic_recognize_tool.py +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/CODE_OF_CONDUCT.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/CONTRIBUTOR_REWARD.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/AsyncTranslate/AsyncTranslate.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/ILTranslator/ILTranslator.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/PDFCreation/PDFCreation.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/PDFParsing/PDFParsing.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/ParagraphFinding/ParagraphFinding.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/README.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/StylesAndFormulas/StylesAndFormulas.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/ImplementationDetails/Typesetting/Typesetting.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/README.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/deploy.sh +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-banner.png +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.png +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.svg +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-big-logo-with-transparent-background.png +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-big-logo-with-transparent-background.svg +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-big-logo.png +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-contributor_reward_example.png +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-preview.gif +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-small-logo-with-transparent-background.png +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-small-logo-with-transparent-background.svg +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/images/babeldoc-small-logo.png +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/index.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/intro-to-pdf-object.md +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/docs/requirements.txt +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/mkdocs.yml +0 -0
- {babeldoc-0.3.17 → babeldoc-0.3.18}/tests/test_translation_config.py +0 -0
|
@@ -17,7 +17,7 @@ jobs:
|
|
|
17
17
|
git config user.name github-actions[bot]
|
|
18
18
|
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
|
19
19
|
- name: Setup uv with Python 3.12
|
|
20
|
-
uses: astral-sh/setup-uv@
|
|
20
|
+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
|
21
21
|
with:
|
|
22
22
|
python-version: "3.12"
|
|
23
23
|
enable-cache: true
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: Lint Code
|
|
2
|
+
permissions:
|
|
3
|
+
contents: read
|
|
4
|
+
pull-requests: write
|
|
5
|
+
on: [push]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
lint:
|
|
9
|
+
strategy:
|
|
10
|
+
fail-fast: false
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- name: Ruff
|
|
15
|
+
uses: astral-sh/ruff-action@v3
|
|
16
|
+
- name: AutoCorrect
|
|
17
|
+
uses: huacnlee/autocorrect-action@main
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: Lint Code and Review Dog Report
|
|
2
|
+
|
|
3
|
+
on: [pull_request]
|
|
4
|
+
permissions:
|
|
5
|
+
contents: read
|
|
6
|
+
pull-requests: write
|
|
7
|
+
jobs:
|
|
8
|
+
ruff:
|
|
9
|
+
name: runner / ruff
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- name: Install Python
|
|
15
|
+
uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: '3.11'
|
|
18
|
+
|
|
19
|
+
- name: Install ruff
|
|
20
|
+
run: pip install ruff
|
|
21
|
+
|
|
22
|
+
- name: Install reviewdog
|
|
23
|
+
uses: reviewdog/action-setup@e04ffabe3898a0af8d0fb1af00c188831c4b5893 # v1.3.2
|
|
24
|
+
with:
|
|
25
|
+
reviewdog_version: latest
|
|
26
|
+
|
|
27
|
+
- name: Run ruff with reviewdog
|
|
28
|
+
env:
|
|
29
|
+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
30
|
+
run: |
|
|
31
|
+
ruff check . --output-format=rdjson | reviewdog -f=rdjson -reporter=github-pr-review -fail-on-error
|
|
32
|
+
|
|
33
|
+
autocorrect:
|
|
34
|
+
name: runner / autocorrect
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- name: AutoCorrect
|
|
39
|
+
uses: huacnlee/autocorrect-action@bf91ab3904c2908dd8e71312a8a83ed1eb632997 # v2.13.3
|
|
40
|
+
- name: Report ReviewDog
|
|
41
|
+
if: failure()
|
|
42
|
+
uses: huacnlee/autocorrect-action@bf91ab3904c2908dd8e71312a8a83ed1eb632997 # v2.13.3
|
|
43
|
+
env:
|
|
44
|
+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
45
|
+
with:
|
|
46
|
+
reviewdog: true
|
|
@@ -35,7 +35,7 @@ jobs:
|
|
|
35
35
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
36
36
|
|
|
37
37
|
- name: Setup uv with Python 3.12
|
|
38
|
-
uses: astral-sh/setup-uv@
|
|
38
|
+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
|
39
39
|
with:
|
|
40
40
|
python-version: "3.12"
|
|
41
41
|
enable-cache: true
|
|
@@ -28,7 +28,7 @@ jobs:
|
|
|
28
28
|
path: ~/.cache/babeldoc
|
|
29
29
|
key: babeldoc-assets-${{ hashFiles('babeldoc/assets/embedding_assets_metadata.py') }}
|
|
30
30
|
- name: Setup uv with Python ${{ matrix.python-version }}
|
|
31
|
-
uses: astral-sh/setup-uv@
|
|
31
|
+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
|
|
32
32
|
with:
|
|
33
33
|
python-version: ${{ matrix.python-version }}
|
|
34
34
|
enable-cache: true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.18"
|
|
@@ -31,11 +31,11 @@ def _subset_fonts_process(pdf_path, output_path):
|
|
|
31
31
|
pdf = pymupdf.open(pdf_path)
|
|
32
32
|
pdf.subset_fonts(fallback=False)
|
|
33
33
|
pdf.save(output_path)
|
|
34
|
-
# 返回0表示成功
|
|
34
|
+
# 返回 0 表示成功
|
|
35
35
|
os._exit(0)
|
|
36
36
|
except Exception as e:
|
|
37
37
|
logger.error(f"Error in font subsetting subprocess: {e}")
|
|
38
|
-
# 返回1表示失败
|
|
38
|
+
# 返回 1 表示失败
|
|
39
39
|
os._exit(1)
|
|
40
40
|
|
|
41
41
|
|
|
@@ -69,11 +69,11 @@ def _save_pdf_clean_process(
|
|
|
69
69
|
deflate_fonts=deflate_fonts,
|
|
70
70
|
linear=linear,
|
|
71
71
|
)
|
|
72
|
-
# 返回0表示成功
|
|
72
|
+
# 返回 0 表示成功
|
|
73
73
|
os._exit(0)
|
|
74
74
|
except Exception as e:
|
|
75
75
|
logger.error(f"Error in save PDF with clean=True subprocess: {e}")
|
|
76
|
-
# 返回1表示失败
|
|
76
|
+
# 返回 1 表示失败
|
|
77
77
|
os._exit(1)
|
|
78
78
|
|
|
79
79
|
|
|
@@ -479,6 +479,7 @@ class ILCreater:
|
|
|
479
479
|
self.current_page_font_name_id_map = {}
|
|
480
480
|
self.current_page_font_char_bounding_box_map = {}
|
|
481
481
|
self.mupdf_font_map: dict[int, pymupdf.Font] = {}
|
|
482
|
+
self.graphic_state_pool = {}
|
|
482
483
|
|
|
483
484
|
def on_finish(self):
|
|
484
485
|
self.progress.__exit__(None, None, None)
|
|
@@ -797,6 +798,21 @@ class ILCreater:
|
|
|
797
798
|
f"{arg} {op}" for op, arg in gs.passthrough_instruction
|
|
798
799
|
)
|
|
799
800
|
|
|
801
|
+
# 可能会影响部分 graphic state 准确度。不过 BabelDOC 仅使用 passthrough_per_char_instruction
|
|
802
|
+
# 所以应该是没啥影响
|
|
803
|
+
# 但是池化 graphic state 后可以减少内存占用
|
|
804
|
+
if (
|
|
805
|
+
graphic_state.passthrough_per_char_instruction
|
|
806
|
+
not in self.graphic_state_pool
|
|
807
|
+
):
|
|
808
|
+
self.graphic_state_pool[graphic_state.passthrough_per_char_instruction] = (
|
|
809
|
+
graphic_state
|
|
810
|
+
)
|
|
811
|
+
else:
|
|
812
|
+
graphic_state = self.graphic_state_pool[
|
|
813
|
+
graphic_state.passthrough_per_char_instruction
|
|
814
|
+
]
|
|
815
|
+
|
|
800
816
|
return graphic_state
|
|
801
817
|
|
|
802
818
|
def on_lt_char(self, char: LTChar):
|
|
@@ -237,7 +237,7 @@ class ParagraphFinder:
|
|
|
237
237
|
is_small_char = char_area < median_char_area * 0.1
|
|
238
238
|
|
|
239
239
|
# 检查是否需要开始新段落
|
|
240
|
-
# 如果字符面积小于中位数面积的10
|
|
240
|
+
# 如果字符面积小于中位数面积的 10% 且当前段落已有字符,则跳过新段落检测
|
|
241
241
|
if not (is_small_char and current_line_chars) and (
|
|
242
242
|
current_layout is None
|
|
243
243
|
or char_layout.id != current_layout.id
|
|
@@ -395,7 +395,7 @@ class StylesAndFormulas:
|
|
|
395
395
|
right_line = comp.pdf_line
|
|
396
396
|
break
|
|
397
397
|
|
|
398
|
-
# 计算与左右文本的y轴交集
|
|
398
|
+
# 计算与左右文本的 y 轴交集
|
|
399
399
|
left_intersection = 0
|
|
400
400
|
right_intersection = 0
|
|
401
401
|
|
|
@@ -413,7 +413,7 @@ class StylesAndFormulas:
|
|
|
413
413
|
if intersection_end > intersection_start:
|
|
414
414
|
right_intersection = intersection_end - intersection_start
|
|
415
415
|
|
|
416
|
-
# 如果有两个文本段落,将交集较小的设为none
|
|
416
|
+
# 如果有两个文本段落,将交集较小的设为 none
|
|
417
417
|
if left_line and right_line:
|
|
418
418
|
if left_intersection < right_intersection:
|
|
419
419
|
left_line = None
|
|
@@ -221,8 +221,8 @@ class TypesettingUnit:
|
|
|
221
221
|
# 连接号
|
|
222
222
|
"~", # 全角波浪号
|
|
223
223
|
"-", # 连字符减号
|
|
224
|
-
"–", # 短破折号(EN DASH)
|
|
225
|
-
"—", # 长破折号(EM DASH)
|
|
224
|
+
"–", # 短破折号 (EN DASH)
|
|
225
|
+
"—", # 长破折号 (EM DASH)
|
|
226
226
|
# 间隔号
|
|
227
227
|
"·", # 中间点
|
|
228
228
|
"・", # 片假名中间点
|
|
@@ -767,7 +767,7 @@ class Typesetting:
|
|
|
767
767
|
line_spacing = 1.7 # 初始行距为 1.7
|
|
768
768
|
min_scale = 0.1 # 最小缩放因子
|
|
769
769
|
min_line_spacing = 1.4 # 最小行距
|
|
770
|
-
expand_space_flag = 0 # 0:
|
|
770
|
+
expand_space_flag = 0 # 0: 未扩展,1: 已向下扩展,2: 已向右扩展
|
|
771
771
|
|
|
772
772
|
while scale >= min_scale:
|
|
773
773
|
# 尝试布局排版单元
|
|
@@ -43,10 +43,10 @@ def encode_image(image) -> bytes:
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
@retry(
|
|
46
|
-
stop=stop_after_attempt(3), # 最多重试3次
|
|
46
|
+
stop=stop_after_attempt(3), # 最多重试 3 次
|
|
47
47
|
wait=wait_exponential(
|
|
48
48
|
multiplier=1, min=1, max=10
|
|
49
|
-
), # 指数退避策略,初始1秒,最大10秒
|
|
49
|
+
), # 指数退避策略,初始 1 秒,最大 10 秒
|
|
50
50
|
retry=retry_if_exception_type((httpx.HTTPError, Exception)), # 针对哪些异常重试
|
|
51
51
|
before_sleep=lambda retry_state: logger.warning(
|
|
52
52
|
f"Request failed, retrying in {retry_state.next_action.sleep} seconds... "
|
|
@@ -586,6 +586,7 @@ def _do_translate_single(
|
|
|
586
586
|
logger.debug(f"finish parse il from {temp_pdf_path}")
|
|
587
587
|
docs = il_creater.create_il()
|
|
588
588
|
logger.debug(f"finish create il from {temp_pdf_path}")
|
|
589
|
+
del il_creater
|
|
589
590
|
if translation_config.debug:
|
|
590
591
|
xml_converter.write_json(
|
|
591
592
|
docs,
|
|
@@ -657,6 +658,7 @@ def _do_translate_single(
|
|
|
657
658
|
il_translator = ILTranslator(translate_engine, translation_config)
|
|
658
659
|
|
|
659
660
|
il_translator.translate(docs)
|
|
661
|
+
del il_translator
|
|
660
662
|
logger.debug(f"finish ILTranslator from {temp_pdf_path}")
|
|
661
663
|
if translation_config.debug:
|
|
662
664
|
xml_converter.write_json(
|
|
@@ -60,7 +60,7 @@ class TranslationConfig:
|
|
|
60
60
|
enhance_compatibility: bool = False,
|
|
61
61
|
report_interval: float = 0.1,
|
|
62
62
|
min_text_length: int = 5,
|
|
63
|
-
use_side_by_side_dual: bool = True, # Deprecated: 是否使用拼版式双语 PDF
|
|
63
|
+
use_side_by_side_dual: bool = True, # Deprecated: 是否使用拼版式双语 PDF(并排显示原文和译文)向下兼容选项,已停用。
|
|
64
64
|
use_alternating_pages_dual: bool = False,
|
|
65
65
|
watermark_output_mode: WatermarkOutputMode = WatermarkOutputMode.Watermarked,
|
|
66
66
|
# Add split-related parameters
|
|
@@ -181,3 +181,9 @@ trang babeldoc/document_il/il_version_1.rnc babeldoc/document_il/il_version_1.xs
|
|
|
181
181
|
# Generate Python classes from XSD
|
|
182
182
|
xsdata generate babeldoc/document_il/il_version_1.xsd --package babeldoc.document_il
|
|
183
183
|
```
|
|
184
|
+
|
|
185
|
+
##### Profile memory usage
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
uv run memray run --native --aggregate babeldoc/main.py -c yadt.toml
|
|
189
|
+
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "BabelDOC"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.18"
|
|
4
4
|
description = "Yet Another Document Translator"
|
|
5
5
|
license = "AGPL-3.0"
|
|
6
6
|
readme = "README.md"
|
|
@@ -140,7 +140,8 @@ dev = [
|
|
|
140
140
|
"pre-commit>=4.1.0",
|
|
141
141
|
"pygments>=2.19.1",
|
|
142
142
|
"ruff>=0.9.2",
|
|
143
|
-
"pytest>=8.3.4"
|
|
143
|
+
"pytest>=8.3.4",
|
|
144
|
+
"memray>=1.17.1",
|
|
144
145
|
]
|
|
145
146
|
|
|
146
147
|
[tool.pytest.ini_options]
|
|
@@ -148,7 +149,7 @@ pythonpath = [".", "src"]
|
|
|
148
149
|
testpaths = ["tests"]
|
|
149
150
|
|
|
150
151
|
[bumpver]
|
|
151
|
-
current_version = "0.3.
|
|
152
|
+
current_version = "0.3.18"
|
|
152
153
|
version_pattern = "MAJOR.MINOR.PATCH[.PYTAGNUM]"
|
|
153
154
|
|
|
154
155
|
[bumpver.file_patterns]
|