BabelDOC 0.1.18__tar.gz → 0.1.20__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.
Files changed (80) hide show
  1. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/workflows/test.yml +19 -5
  2. {babeldoc-0.1.18 → babeldoc-0.1.20}/PKG-INFO +85 -1
  3. {babeldoc-0.1.18 → babeldoc-0.1.20}/README.md +84 -0
  4. babeldoc-0.1.20/babeldoc/__init__.py +1 -0
  5. babeldoc-0.1.20/babeldoc/assets/assets.py +439 -0
  6. babeldoc-0.1.20/babeldoc/assets/embedding_assets_metadata.py +443 -0
  7. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/const.py +7 -2
  8. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/backend/pdf_creater.py +15 -15
  9. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/translator/translator.py +8 -4
  10. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/utils/fontmap.py +110 -104
  11. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/docvision/doclayout.py +8 -32
  12. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/high_level.py +2 -70
  13. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/main.py +28 -14
  14. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/pdfinterp.py +7 -1
  15. babeldoc-0.1.20/babeldoc/tools/generate_font_metadata.py +101 -0
  16. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/translation_config.py +3 -1
  17. {babeldoc-0.1.18 → babeldoc-0.1.20}/pyproject.toml +2 -2
  18. {babeldoc-0.1.18 → babeldoc-0.1.20}/uv.lock +87 -125
  19. babeldoc-0.1.18/babeldoc/__init__.py +0 -1
  20. {babeldoc-0.1.18 → babeldoc-0.1.20}/.cursorignore +0 -0
  21. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
  22. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/ISSUE_TEMPLATE/feature_request.yaml +0 -0
  23. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/dependabot.yml +0 -0
  24. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/labels.yml +0 -0
  25. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/release-drafter.yml +0 -0
  26. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/workflows/codeql.yml +0 -0
  27. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/workflows/docs.yml +0 -0
  28. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/workflows/labeler.yml +0 -0
  29. {babeldoc-0.1.18 → babeldoc-0.1.20}/.github/workflows/publish-to-pypi.yml +0 -0
  30. {babeldoc-0.1.18 → babeldoc-0.1.20}/.gitignore +0 -0
  31. {babeldoc-0.1.18 → babeldoc-0.1.20}/.pre-commit-config.yaml +0 -0
  32. {babeldoc-0.1.18 → babeldoc-0.1.20}/LICENSE +0 -0
  33. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/asynchronize/__init__.py +0 -0
  34. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/converter.py +0 -0
  35. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/__init__.py +0 -0
  36. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/backend/__init__.py +0 -0
  37. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/frontend/__init__.py +0 -0
  38. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/frontend/il_creater.py +0 -0
  39. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/il_version_1.py +0 -0
  40. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/il_version_1.rnc +0 -0
  41. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/il_version_1.rng +0 -0
  42. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/il_version_1.xsd +0 -0
  43. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/__init__.py +0 -0
  44. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/add_debug_information.py +0 -0
  45. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/il_translator.py +0 -0
  46. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/layout_parser.py +0 -0
  47. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/paragraph_finder.py +0 -0
  48. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/remove_descent.py +0 -0
  49. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/styles_and_formulas.py +0 -0
  50. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/midend/typesetting.py +0 -0
  51. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/translator/__init__.py +0 -0
  52. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/translator/cache.py +0 -0
  53. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/utils/layout_helper.py +0 -0
  54. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/utils/style_helper.py +0 -0
  55. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/document_il/xml_converter.py +0 -0
  56. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/docvision/README.md +0 -0
  57. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/docvision/__init__.py +0 -0
  58. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/docvision/rpc_doclayout.py +0 -0
  59. {babeldoc-0.1.18 → babeldoc-0.1.20}/babeldoc/progress_monitor.py +0 -0
  60. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/CODE_OF_CONDUCT.md +0 -0
  61. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/CONTRIBUTING.md +0 -0
  62. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/CONTRIBUTOR_REWARD.md +0 -0
  63. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/AsyncTranslate/AsyncTranslate.md +0 -0
  64. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/ILTranslator/ILTranslator.md +0 -0
  65. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/PDFCreation/PDFCreation.md +0 -0
  66. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/PDFParsing/PDFParsing.md +0 -0
  67. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/ParagraphFinding/ParagraphFinding.md +0 -0
  68. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/README.md +0 -0
  69. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/StylesAndFormulas/StylesAndFormulas.md +0 -0
  70. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/ImplementationDetails/Typesetting/Typesetting.md +0 -0
  71. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/README.md +0 -0
  72. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/deploy.sh +0 -0
  73. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/images/babeldoc-banner.png +0 -0
  74. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/images/babeldoc-contributor_reward_example.png +0 -0
  75. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/images/babeldoc-preview.gif +0 -0
  76. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/index.md +0 -0
  77. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/intro-to-pdf-object.md +0 -0
  78. {babeldoc-0.1.18 → babeldoc-0.1.20}/docs/requirements.txt +0 -0
  79. {babeldoc-0.1.18 → babeldoc-0.1.20}/mkdocs.yml +0 -0
  80. {babeldoc-0.1.18 → babeldoc-0.1.20}/tests/test_translation_config.py +0 -0
@@ -21,20 +21,34 @@ jobs:
21
21
  - uses: actions/checkout@v4
22
22
  with:
23
23
  persist-credentials: false
24
- - name: Cached models
25
- id: cache-mods
24
+ - name: Cached Assets
25
+ id: cache-assets
26
26
  uses: actions/cache@v4.2.0
27
27
  with:
28
- path: ~/.cache/huggingface/hub/models--wybxc--DocLayout-YOLO-DocStructBench-onnx
29
- key: ${{runner.os}}-huggingmodel-wybxc--DocLayout-YOLO-DocStructBench-onnx
28
+ path: ~/.cache/babeldoc
29
+ key: babeldoc-assets-${{ hashFiles('babeldoc/assets/embedding_assets_metadata.py') }}
30
30
  - name: Setup uv with Python ${{ matrix.python-version }}
31
31
  uses: astral-sh/setup-uv@1edb52594c857e2b5b13128931090f0640537287 # v5.3.0
32
32
  with:
33
33
  python-version: ${{ matrix.python-version }}
34
34
  enable-cache: true
35
35
  cache-dependency-glob: "uv.lock"
36
-
36
+ - name: Warm up cache
37
+ run: |
38
+ uv run babeldoc --warmup
37
39
  - name: Run tests
38
40
  run: |
39
41
  uv run babeldoc --help
40
42
  uv run babeldoc --bing --files examples/ci/test.pdf
43
+ - name: Generate offline assets package
44
+ run: |
45
+ uv run babeldoc --generate-offline-assets /tmp/offline_assets
46
+ - name: Restore offline assets package
47
+ run: |
48
+ rm -rf ~/.cache/babeldoc
49
+ uv run babeldoc --restore-offline-assets /tmp/offline_assets
50
+ - name: Clean up
51
+ run: |
52
+ rm -rf /tmp/offline_assets
53
+ rm -rf ~/.cache/babeldoc/cache.v1.db
54
+ rm -rf ~/.cache/babeldoc/working
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: BabelDOC
3
- Version: 0.1.18
3
+ Version: 0.1.20
4
4
  Summary: Yet Another Document Translator
5
5
  Project-URL: Homepage, https://github.com/funstory-ai/BabelDOC
6
6
  Project-URL: Issues, https://github.com/funstory-ai/BabelDOC/issues
@@ -134,7 +134,10 @@ uv run babeldoc --bing --files example.pdf --files example2.pdf
134
134
 
135
135
  > [!TIP]
136
136
  > Currently, this project mainly focuses on English-to-Chinese translation, and other scenarios have not been tested yet.
137
+ >
137
138
  > (2025.3.1 update): Basic English target language support has been added, primarily to minimize line breaks within words([0-9A-Za-z]+).
139
+ >
140
+ > [HELP WANTED: Collecting word regular expressions for more languages](https://github.com/funstory-ai/BabelDOC/issues/129)
138
141
 
139
142
  ### PDF Processing Options
140
143
 
@@ -188,6 +191,22 @@ uv run babeldoc --bing --files example.pdf --files example2.pdf
188
191
  - `--debug`, `-d`: Enable debug logging level and export detailed intermediate results in `~/.cache/yadt/working`.
189
192
  - `--report-interval`: Progress report interval in seconds (default: 0.1).
190
193
 
194
+ ### Offline Assets Management
195
+
196
+ - `--generate-offline-assets`: Generate an offline assets package in the specified directory. This creates a zip file containing all required models and fonts.
197
+ - `--restore-offline-assets`: Restore an offline assets package from the specified file. This extracts models and fonts from a previously generated package.
198
+
199
+ > [!TIP]
200
+ >
201
+ > 1. Offline assets packages are useful for environments without internet access or to speed up installation on multiple machines.
202
+ > 2. Generate a package once with `babeldoc --generate-offline-assets /path/to/output/dir` and then distribute it.
203
+ > 3. Restore the package on target machines with `babeldoc --restore-offline-assets /path/to/offline_assets_*.zip`.
204
+ > 4. The offline assets package name cannot be modified because the file list hash is encoded in the name.
205
+ > 5. If you provide a directory path to `--restore-offline-assets`, the tool will automatically look for the correct offline assets package file in that directory.
206
+ > 6. The package contains all necessary fonts and models required for document processing, ensuring consistent results across different environments.
207
+ > 7. The integrity of all assets is verified using SHA3-256 hashes during both packaging and restoration.
208
+ > 8. If you're deploying in an air-gapped environment, make sure to generate the package on a machine with internet access first.
209
+
191
210
  ### Configuration File
192
211
 
193
212
  - `--config`, `-c`: Configuration file path. Use the TOML format.
@@ -206,9 +225,49 @@ openai = true
206
225
  openai-model = "SOME_ALSOME_MODEL"
207
226
  openai-base-url = "https://example.example/v1"
208
227
  openai-api-key = "[KEY]"
228
+ # Offline assets management
229
+ # generate-offline-assets = "/path/to/output/dir"
230
+ # restore-offline-assets = "/path/to/offline_assets_package.zip"
209
231
  # All other options can also be set in the configuration file.
210
232
  ```
211
233
 
234
+ For a more comprehensive configuration example with offline assets management:
235
+
236
+ ```toml
237
+ [babeldoc]
238
+ # Basic settings
239
+ debug = true
240
+ lang-in = "en-US"
241
+ lang-out = "zh-CN"
242
+ qps = 10
243
+ output = "/path/to/output/dir"
244
+
245
+ # Translation service
246
+ openai = true
247
+ openai-model = "gpt-4o-mini"
248
+ openai-base-url = "https://api.openai.com/v1"
249
+ openai-api-key = "your-api-key-here"
250
+
251
+ # PDF processing options
252
+ split-short-lines = false
253
+ short-line-split-factor = 0.8
254
+ skip-clean = false
255
+ dual-translate-first = false
256
+ disable-rich-text-translate = false
257
+ use-alternating-pages-dual = false
258
+
259
+ # Output control
260
+ no-dual = false
261
+ no-mono = false
262
+ min-text-length = 5
263
+ report-interval = 0.5
264
+
265
+ # Offline assets management
266
+ # Uncomment one of these options as needed:
267
+ # generate-offline-assets = "/path/to/output/dir"
268
+ # restore-offline-assets = "/path/to/offline_assets_package.zip"
269
+ ```
270
+
212
271
  ## Python API
213
272
 
214
273
  You can refer to the example in [main.py](https://github.com/funstory-ai/yadt/blob/main/babeldoc/main.py) to use BabelDOC's Python API.
@@ -219,6 +278,31 @@ Please note:
219
278
 
220
279
  2. The current `TranslationConfig` does not fully validate input parameters, so you need to ensure the validity of input parameters
221
280
 
281
+ 3. For offline assets management, you can use the following functions:
282
+ ```python
283
+ # Generate an offline assets package
284
+ from pathlib import Path
285
+ import babeldoc.assets.assets
286
+
287
+ # Generate package to a specific directory
288
+ # path is optional, default is ~/.cache/babeldoc/assets/offline_assets_{hash}.zip
289
+ babeldoc.assets.assets.generate_offline_assets_package(Path("/path/to/output/dir"))
290
+
291
+ # Restore from a package file
292
+ # path is optional, default is ~/.cache/babeldoc/assets/offline_assets_{hash}.zip
293
+ babeldoc.assets.assets.restore_offline_assets_package(Path("/path/to/offline_assets_package.zip"))
294
+
295
+ # You can also restore from a directory containing the offline assets package
296
+ # The tool will automatically find the correct package file based on the hash
297
+ babeldoc.assets.assets.restore_offline_assets_package(Path("/path/to/directory"))
298
+ ```
299
+
300
+ > [!TIP]
301
+ >
302
+ > 1. The offline assets package name cannot be modified because the file list hash is encoded in the name.
303
+ > 2. When using in production environments, it's recommended to pre-generate the assets package and include it with your application distribution.
304
+ > 3. The package verification ensures that all required assets are intact and match their expected checksums.
305
+
222
306
  ## Background
223
307
 
224
308
  There are a lot projects and teams working on to make document editing and translating easier like:
@@ -100,7 +100,10 @@ uv run babeldoc --bing --files example.pdf --files example2.pdf
100
100
 
101
101
  > [!TIP]
102
102
  > Currently, this project mainly focuses on English-to-Chinese translation, and other scenarios have not been tested yet.
103
+ >
103
104
  > (2025.3.1 update): Basic English target language support has been added, primarily to minimize line breaks within words([0-9A-Za-z]+).
105
+ >
106
+ > [HELP WANTED: Collecting word regular expressions for more languages](https://github.com/funstory-ai/BabelDOC/issues/129)
104
107
 
105
108
  ### PDF Processing Options
106
109
 
@@ -154,6 +157,22 @@ uv run babeldoc --bing --files example.pdf --files example2.pdf
154
157
  - `--debug`, `-d`: Enable debug logging level and export detailed intermediate results in `~/.cache/yadt/working`.
155
158
  - `--report-interval`: Progress report interval in seconds (default: 0.1).
156
159
 
160
+ ### Offline Assets Management
161
+
162
+ - `--generate-offline-assets`: Generate an offline assets package in the specified directory. This creates a zip file containing all required models and fonts.
163
+ - `--restore-offline-assets`: Restore an offline assets package from the specified file. This extracts models and fonts from a previously generated package.
164
+
165
+ > [!TIP]
166
+ >
167
+ > 1. Offline assets packages are useful for environments without internet access or to speed up installation on multiple machines.
168
+ > 2. Generate a package once with `babeldoc --generate-offline-assets /path/to/output/dir` and then distribute it.
169
+ > 3. Restore the package on target machines with `babeldoc --restore-offline-assets /path/to/offline_assets_*.zip`.
170
+ > 4. The offline assets package name cannot be modified because the file list hash is encoded in the name.
171
+ > 5. If you provide a directory path to `--restore-offline-assets`, the tool will automatically look for the correct offline assets package file in that directory.
172
+ > 6. The package contains all necessary fonts and models required for document processing, ensuring consistent results across different environments.
173
+ > 7. The integrity of all assets is verified using SHA3-256 hashes during both packaging and restoration.
174
+ > 8. If you're deploying in an air-gapped environment, make sure to generate the package on a machine with internet access first.
175
+
157
176
  ### Configuration File
158
177
 
159
178
  - `--config`, `-c`: Configuration file path. Use the TOML format.
@@ -172,9 +191,49 @@ openai = true
172
191
  openai-model = "SOME_ALSOME_MODEL"
173
192
  openai-base-url = "https://example.example/v1"
174
193
  openai-api-key = "[KEY]"
194
+ # Offline assets management
195
+ # generate-offline-assets = "/path/to/output/dir"
196
+ # restore-offline-assets = "/path/to/offline_assets_package.zip"
175
197
  # All other options can also be set in the configuration file.
176
198
  ```
177
199
 
200
+ For a more comprehensive configuration example with offline assets management:
201
+
202
+ ```toml
203
+ [babeldoc]
204
+ # Basic settings
205
+ debug = true
206
+ lang-in = "en-US"
207
+ lang-out = "zh-CN"
208
+ qps = 10
209
+ output = "/path/to/output/dir"
210
+
211
+ # Translation service
212
+ openai = true
213
+ openai-model = "gpt-4o-mini"
214
+ openai-base-url = "https://api.openai.com/v1"
215
+ openai-api-key = "your-api-key-here"
216
+
217
+ # PDF processing options
218
+ split-short-lines = false
219
+ short-line-split-factor = 0.8
220
+ skip-clean = false
221
+ dual-translate-first = false
222
+ disable-rich-text-translate = false
223
+ use-alternating-pages-dual = false
224
+
225
+ # Output control
226
+ no-dual = false
227
+ no-mono = false
228
+ min-text-length = 5
229
+ report-interval = 0.5
230
+
231
+ # Offline assets management
232
+ # Uncomment one of these options as needed:
233
+ # generate-offline-assets = "/path/to/output/dir"
234
+ # restore-offline-assets = "/path/to/offline_assets_package.zip"
235
+ ```
236
+
178
237
  ## Python API
179
238
 
180
239
  You can refer to the example in [main.py](https://github.com/funstory-ai/yadt/blob/main/babeldoc/main.py) to use BabelDOC's Python API.
@@ -185,6 +244,31 @@ Please note:
185
244
 
186
245
  2. The current `TranslationConfig` does not fully validate input parameters, so you need to ensure the validity of input parameters
187
246
 
247
+ 3. For offline assets management, you can use the following functions:
248
+ ```python
249
+ # Generate an offline assets package
250
+ from pathlib import Path
251
+ import babeldoc.assets.assets
252
+
253
+ # Generate package to a specific directory
254
+ # path is optional, default is ~/.cache/babeldoc/assets/offline_assets_{hash}.zip
255
+ babeldoc.assets.assets.generate_offline_assets_package(Path("/path/to/output/dir"))
256
+
257
+ # Restore from a package file
258
+ # path is optional, default is ~/.cache/babeldoc/assets/offline_assets_{hash}.zip
259
+ babeldoc.assets.assets.restore_offline_assets_package(Path("/path/to/offline_assets_package.zip"))
260
+
261
+ # You can also restore from a directory containing the offline assets package
262
+ # The tool will automatically find the correct package file based on the hash
263
+ babeldoc.assets.assets.restore_offline_assets_package(Path("/path/to/directory"))
264
+ ```
265
+
266
+ > [!TIP]
267
+ >
268
+ > 1. The offline assets package name cannot be modified because the file list hash is encoded in the name.
269
+ > 2. When using in production environments, it's recommended to pre-generate the assets package and include it with your application distribution.
270
+ > 3. The package verification ensures that all required assets are intact and match their expected checksums.
271
+
188
272
  ## Background
189
273
 
190
274
  There are a lot projects and teams working on to make document editing and translating easier like:
@@ -0,0 +1 @@
1
+ __version__ = "0.1.20"