intellireading-cli 2.1.0__tar.gz → 2.1.2__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.
@@ -0,0 +1,21 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ .venv/
5
+ *.json
6
+ !renovate.json
7
+ .debug
8
+ .coverage
9
+ coverage/
10
+ coverage.xml
11
+ htmlcov/
12
+ dist/
13
+ build/
14
+ *.egg-info/
15
+ .mypy_cache/
16
+ .pytest_cache/
17
+ .ruff_cache/
18
+ app/
19
+ .env
20
+ tests/test_files/output
21
+ bin/act
@@ -1,11 +1,13 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: intellireading-cli
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Intellireading-cli is a Python library with a set of tools to improve your reading experience
5
5
  Project-URL: Documentation, https://go.hugobatista.com/gh/intellireading-cli#readme
6
6
  Project-URL: Issues, https://go.hugobatista.com/gh/intellireading-cli/issues
7
7
  Project-URL: Source, https://go.hugobatista.com/gh/intellireading-cli
8
- Author: Hugo Batista
8
+ Project-URL: Homepage, https://go.hugobatista.com/gh/intellireading-cli
9
+ Project-URL: Repository, https://go.hugobatista.com/gh/intellireading-cli.git
10
+ Author: Hugo Batista <intellireading at hugobatista.com>
9
11
  License-Expression: GPL-3.0
10
12
  License-File: LICENSE
11
13
  Keywords: adhd,calibre,dyslexia,ebook,epub,kepub,kindle,kobo,speed-reading
@@ -32,7 +34,7 @@ Requires-Dist: lxml>=4.9.2
32
34
  Requires-Dist: regex>=2024.11.6
33
35
  Description-Content-Type: text/markdown
34
36
 
35
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/intellireading.png)
37
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/intellireading.png)
36
38
  # Standalone tool and library
37
39
 
38
40
  [![PyPI - Version](https://img.shields.io/pypi/v/intellireading-cli.svg)](https://pypi.org/project/intellireading-cli)
@@ -40,15 +42,16 @@ Description-Content-Type: text/markdown
40
42
  [![Deploy to ghcr.io](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml)
41
43
  [![Lint](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml)
42
44
  [![Test](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml)
45
+ [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen?logo=renovatebot)](https://docs.renovatebot.com)
46
+ [![GitMCP](https://img.shields.io/endpoint?url=https://gitmcp.io/badge/hugobatista/intellireading-cli)](https://gitmcp.io/hugobatista/intellireading-cli)
43
47
 
44
-
45
- Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a python library.
48
+ Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a Python library.
46
49
  Currently, it supports metaguiding an EPUB, KEPUB, XHTML, or HTML file (more features coming):
47
50
  ```console
48
51
  > intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub
49
52
  ```
50
53
  Example of a text converted to a metaguided text:
51
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/sample.png)
54
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/sample.png)
52
55
 
53
56
 
54
57
  This repo is part of the [Intellireading](https://intellireading.com/) project, which aims to help people with dyslexia, ADHD, or anyone who wants to improve their reading focus and speed.
@@ -60,7 +63,7 @@ This repo is part of the [Intellireading](https://intellireading.com/) project,
60
63
  - [Calibre Plugins](https://go.hugobatista.com/gh/intellireading-calibre-plugins). A set of plugins that can be used to metaguide epub files using Calibre.
61
64
 
62
65
 
63
- ## What is Epub Metaguiding?
66
+ ## What is EPUB Metaguiding?
64
67
  **Metagu**iding **i**s **a** **techn**ique **th**at **ca**n **b**e **us**ed **t**o **impr**ove **yo**ur **read**ing **foc**us **an**d **spe**ed **(some**times **cal**led **Bio**nic **Readi**ng). **I**t **i**s **bas**ed **o**n **th**e **id**ea **th**at **yo**u **ca**n **us**e **a** **vis**ual **gui**de **t**o **he**lp **yo**ur **ey**es **foc**us **o**n **th**e **te**xt **yo**u **ar**e **read**ing. **I**n **th**is **cas**e, **th**e **vis**ual **gui**de **i**s **do**ne **b**y **bold**ing **a** **pa**rt **o**f **th**e **tex**t, **crea**ting **vis**ual **anch**ors **th**at **yo**ur **ey**es **ca**n **us**e **t**o **foc**us **o**n **th**e **tex**t. **Th**is **i**s **simi**lar **t**o **th**e **wa**y **a** **fin**ger **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **a** **li**ne **o**f **tex**t, **whi**ch **ha**s **be**en **sho**wn **t**o **impr**ove **read**ing **spe**ed **an**d **foc**us. ([**stu**dy: **"Do**es **finger-t**racking **poi**nt **t**o **chi**ld **read**ing **strate**gies"](https://ceur-ws.org/Vol-2769/paper_60.pdf))
65
68
 
66
69
  **Howe**ver, **unl**ike **a** **fing**er, **th**e **vis**ual **gui**de **i**s **no**t **distra**cting, **an**d **i**t **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **mult**iple **lin**es **o**f **te**xt **a**t **onc**e. **Th**is **all**ows **yo**u **t**o **re**ad **fast**er, **an**d **wi**th **le**ss **effo**rt.
@@ -74,8 +77,8 @@ Intellireading commands can be used to:
74
77
  - **Metaguide an XHTML file**: Metaguide an XHTML file, transforming it into a metaguided XHTML file.
75
78
  - **Metaguide a directory**: Metaguide all files in a directory, transforming all EPUB, XHTML, and HTML files into metaguided files.
76
79
 
77
-
78
80
  ## Installation
81
+
79
82
  Intellireading is a command line tool that can be used in Windows, Linux, and MacOS. It is written in Python and can be used as a module or as a standalone tool, as long as you have Python >3.7 installed (or Docker).
80
83
 
81
84
  ### pip
@@ -93,29 +96,28 @@ You can also install it from the source code:
93
96
  > pip install .
94
97
  > intellireading --help
95
98
  ```
99
+
96
100
  ### Docker
97
101
  Alternatively, you can use the Docker image:
98
102
 
99
103
  #### Help command
100
104
  ```console
101
- > docker pull ghcr.io/0x6f677548/intellireading-cli:latest
102
- > docker run -it --rm ghcr.io/0x6f677548/intellireading-cli --help
105
+ > docker pull ghcr.io/hugobatista/intellireading-cli:latest
106
+ > docker run -it --rm ghcr.io/hugobatista/intellireading-cli --help
103
107
  ```
104
108
 
105
109
  #### Metaguide an EPUB file
106
110
  ##### Linux/MacOS
107
111
  ```console
108
- ```linux
109
- > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
112
+ > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
110
113
  ```
111
114
  ##### Windows
112
115
  ```powershell
113
- > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
116
+ > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
114
117
  ```
115
118
 
119
+ ## CLI Usage
116
120
 
117
-
118
- ## Usage
119
121
  All available commands and options can be seen by using the `--help` option.
120
122
  ```console
121
123
  > intellireading --help
@@ -128,7 +130,7 @@ To get help on a specific command, use the `--help` option with the command name
128
130
 
129
131
  Intellireading is based on [Click](https://github.com/pallets/click/), taking advantage of its features, such as chaining commands and options.
130
132
 
131
- ### Usage Examples
133
+ ### CLI Examples
132
134
 
133
135
  #### Metaguide an EPUB file
134
136
  To metaguide an EPUB file, use the `metaguide-epub` command. The command requires the path to the EPUB file and the output file. The output file will be a metaguided epub file.
@@ -177,3 +179,224 @@ To remove metaguiding from all files in a directory, use the --remove_metaguidin
177
179
  ```console
178
180
  > intellireading metaguide-dir --remove_metaguiding --input_dir mydir_metaguided --output_dir mydir
179
181
  ```
182
+
183
+ ## Python Library API
184
+
185
+ The intellireading-cli package can be used as a Python library for programmatic access to metaguiding functionality. This is useful for integrating metaguiding into web applications, batch processing scripts, or other Python projects.
186
+
187
+ ### Quick Start
188
+
189
+ ```python
190
+ from intellireading.client import (
191
+ metaguide_epub_file,
192
+ metaguide_xhtml_file,
193
+ metaguide_epub_stream,
194
+ metaguide_xhtml_stream,
195
+ metaguide_dir,
196
+ is_file_metaguided,
197
+ )
198
+
199
+ # Metaguide an EPUB file
200
+ metaguide_epub_file("input.epub", "output.epub")
201
+
202
+ # Metaguide an XHTML file
203
+ metaguide_xhtml_file("input.html", "output.html")
204
+ ```
205
+
206
+ ### Core Functions
207
+
208
+ #### EPUB Functions
209
+
210
+ **`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
211
+
212
+ Metaguides an EPUB file by applying visual anchoring to text content within all XHTML files in the EPUB.
213
+
214
+ ```python
215
+ from intellireading.client import metaguide_epub_file
216
+
217
+ # Basic metaguiding
218
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
219
+
220
+ # Remove metaguiding (experimental)
221
+ metaguide_epub_file("mybook_metaguided.epub", "mybook_original.epub", remove_metaguiding=True)
222
+ ```
223
+
224
+ **`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
225
+
226
+ Metaguides an EPUB from a byte stream, useful for in-memory processing or web applications.
227
+
228
+ ```python
229
+ from io import BytesIO
230
+ from intellireading.client import metaguide_epub_stream
231
+
232
+ # Read EPUB into memory
233
+ with open("input.epub", "rb") as f:
234
+ input_stream = BytesIO(f.read())
235
+
236
+ # Metaguide the stream
237
+ output_stream = metaguide_epub_stream(input_stream)
238
+
239
+ # Write to file
240
+ with open("output.epub", "wb") as f:
241
+ f.write(output_stream.read())
242
+ ```
243
+
244
+ #### XHTML Functions
245
+
246
+ **`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
247
+
248
+ Metaguides an XHTML/HTML file by applying visual anchoring to text content. Supports `.xhtml`, `.html`, and `.htm` files.
249
+
250
+ ```python
251
+ from intellireading.client import metaguide_xhtml_file
252
+
253
+ # Metaguide an HTML file
254
+ metaguide_xhtml_file("article.html", "article_metaguided.html")
255
+
256
+ # Remove metaguiding
257
+ metaguide_xhtml_file("article_metaguided.html", "article_restored.html", remove_metaguiding=True)
258
+ ```
259
+
260
+ **`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
261
+
262
+ Metaguides an XHTML/HTML file from a byte stream.
263
+
264
+ ```python
265
+ from io import BytesIO
266
+ from intellireading.client import metaguide_xhtml_stream
267
+
268
+ # Process HTML content from string
269
+ html_content = """
270
+ <!DOCTYPE html>
271
+ <html>
272
+ <body>
273
+ <p>This is a sample paragraph that will be metaguided.</p>
274
+ </body>
275
+ </html>
276
+ """
277
+
278
+ input_stream = BytesIO(html_content.encode("utf-8"))
279
+ output_stream = metaguide_xhtml_stream(input_stream)
280
+ metaguided_content = output_stream.read().decode("utf-8")
281
+ ```
282
+
283
+ #### Directory Functions
284
+
285
+ **`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False)`**
286
+
287
+ Metaguides all EPUB and XHTML/HTML files found in a directory recursively.
288
+
289
+ ```python
290
+ from intellireading.client import metaguide_dir
291
+
292
+ # Metaguide all books in the directory
293
+ metaguide_dir("books", "books_metaguided")
294
+
295
+ # Remove metaguiding from all files
296
+ metaguide_dir("books_metaguided", "books_restored", remove_metaguiding=True)
297
+ ```
298
+
299
+ #### Utility Functions
300
+
301
+ **`is_file_metaguided(filepath: str) -> bool`**
302
+
303
+ Checks if an EPUB file has already been metaguided.
304
+
305
+ ```python
306
+ from intellireading.client import is_file_metaguided, metaguide_epub_file
307
+
308
+ # Check if file is already metaguided
309
+ if not is_file_metaguided("mybook.epub"):
310
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
311
+ print("File metaguided successfully")
312
+ else:
313
+ print("File is already metaguided")
314
+ ```
315
+
316
+ ### Integration Examples
317
+
318
+ #### Web Application (Flask)
319
+
320
+ ```python
321
+ from flask import Flask, request, send_file
322
+ from io import BytesIO
323
+ from intellireading.client import metaguide_epub_stream
324
+
325
+ app = Flask(__name__)
326
+
327
+
328
+ @app.route("/metaguide", methods=["POST"])
329
+ def metaguide_upload():
330
+ file = request.files["epub"]
331
+ if file and file.filename.endswith(".epub"):
332
+ input_stream = BytesIO(file.read())
333
+ output_stream = metaguide_epub_stream(input_stream)
334
+
335
+ return send_file(
336
+ output_stream,
337
+ as_attachment=True,
338
+ download_name=f"metaguided_{file.filename}",
339
+ mimetype="application/epub+zip",
340
+ )
341
+ return "Invalid file", 400
342
+ ```
343
+
344
+ #### Batch Processing
345
+
346
+ ```python
347
+ import os
348
+ from intellireading.client import metaguide_dir, is_file_metaguided
349
+
350
+
351
+ def batch_process_library(library_path):
352
+ """Process an entire library of EPUB files"""
353
+ processed_path = os.path.join(library_path, "metaguided")
354
+
355
+ # Process all files
356
+ metaguide_dir(library_path, processed_path)
357
+
358
+ # Verify results
359
+ for root, dirs, files in os.walk(processed_path):
360
+ for file in files:
361
+ if file.endswith(".epub"):
362
+ filepath = os.path.join(root, file)
363
+ if is_file_metaguided(filepath):
364
+ print(f"✓ Successfully metaguided: {file}")
365
+
366
+
367
+ batch_process_library("/path/to/my/books")
368
+ ```
369
+
370
+ ### Error Handling
371
+
372
+ ```python
373
+ from intellireading.client import metaguide_epub_file
374
+
375
+ try:
376
+ metaguide_epub_file("mybook.epub", "output.epub")
377
+ except ValueError as e:
378
+ print(f"Invalid file: {e}")
379
+ except FileNotFoundError as e:
380
+ print(f"File not found: {e}")
381
+ except Exception as e:
382
+ print(f"Unexpected error: {e}")
383
+ ```
384
+
385
+ ## Dependency updates
386
+
387
+ Dependencies are updated automatically by [Renovate](https://docs.renovatebot.com).
388
+ The configuration lives in [`renovate.json`](renovate.json).
389
+
390
+ Updates that pass the 30-day minimum release age are proposed as pull requests.
391
+ Major updates are labelled `major-update`, security updates are labelled `security`,
392
+ and `ghcr.io/astral-sh/uv` version bumps wait for approval in the Dependency Dashboard.
393
+
394
+ To run Renovate locally as a dry run:
395
+
396
+ ```bash
397
+ act workflow_dispatch -W .github/workflows/renovate.yml \
398
+ --env RENOVATE_DRY_RUN=full \
399
+ --env RENOVATE_REPOSITORIES=hugobatista/intellireading-cli \
400
+ --env LOG_LEVEL=info \
401
+ -s RENOVATE_TOKEN=<token>
402
+ ```
@@ -1,4 +1,4 @@
1
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/intellireading.png)
1
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/intellireading.png)
2
2
  # Standalone tool and library
3
3
 
4
4
  [![PyPI - Version](https://img.shields.io/pypi/v/intellireading-cli.svg)](https://pypi.org/project/intellireading-cli)
@@ -6,15 +6,16 @@
6
6
  [![Deploy to ghcr.io](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml)
7
7
  [![Lint](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml)
8
8
  [![Test](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml)
9
+ [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen?logo=renovatebot)](https://docs.renovatebot.com)
10
+ [![GitMCP](https://img.shields.io/endpoint?url=https://gitmcp.io/badge/hugobatista/intellireading-cli)](https://gitmcp.io/hugobatista/intellireading-cli)
9
11
 
10
-
11
- Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a python library.
12
+ Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a Python library.
12
13
  Currently, it supports metaguiding an EPUB, KEPUB, XHTML, or HTML file (more features coming):
13
14
  ```console
14
15
  > intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub
15
16
  ```
16
17
  Example of a text converted to a metaguided text:
17
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/sample.png)
18
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/sample.png)
18
19
 
19
20
 
20
21
  This repo is part of the [Intellireading](https://intellireading.com/) project, which aims to help people with dyslexia, ADHD, or anyone who wants to improve their reading focus and speed.
@@ -26,7 +27,7 @@ This repo is part of the [Intellireading](https://intellireading.com/) project,
26
27
  - [Calibre Plugins](https://go.hugobatista.com/gh/intellireading-calibre-plugins). A set of plugins that can be used to metaguide epub files using Calibre.
27
28
 
28
29
 
29
- ## What is Epub Metaguiding?
30
+ ## What is EPUB Metaguiding?
30
31
  **Metagu**iding **i**s **a** **techn**ique **th**at **ca**n **b**e **us**ed **t**o **impr**ove **yo**ur **read**ing **foc**us **an**d **spe**ed **(some**times **cal**led **Bio**nic **Readi**ng). **I**t **i**s **bas**ed **o**n **th**e **id**ea **th**at **yo**u **ca**n **us**e **a** **vis**ual **gui**de **t**o **he**lp **yo**ur **ey**es **foc**us **o**n **th**e **te**xt **yo**u **ar**e **read**ing. **I**n **th**is **cas**e, **th**e **vis**ual **gui**de **i**s **do**ne **b**y **bold**ing **a** **pa**rt **o**f **th**e **tex**t, **crea**ting **vis**ual **anch**ors **th**at **yo**ur **ey**es **ca**n **us**e **t**o **foc**us **o**n **th**e **tex**t. **Th**is **i**s **simi**lar **t**o **th**e **wa**y **a** **fin**ger **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **a** **li**ne **o**f **tex**t, **whi**ch **ha**s **be**en **sho**wn **t**o **impr**ove **read**ing **spe**ed **an**d **foc**us. ([**stu**dy: **"Do**es **finger-t**racking **poi**nt **t**o **chi**ld **read**ing **strate**gies"](https://ceur-ws.org/Vol-2769/paper_60.pdf))
31
32
 
32
33
  **Howe**ver, **unl**ike **a** **fing**er, **th**e **vis**ual **gui**de **i**s **no**t **distra**cting, **an**d **i**t **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **mult**iple **lin**es **o**f **te**xt **a**t **onc**e. **Th**is **all**ows **yo**u **t**o **re**ad **fast**er, **an**d **wi**th **le**ss **effo**rt.
@@ -40,8 +41,8 @@ Intellireading commands can be used to:
40
41
  - **Metaguide an XHTML file**: Metaguide an XHTML file, transforming it into a metaguided XHTML file.
41
42
  - **Metaguide a directory**: Metaguide all files in a directory, transforming all EPUB, XHTML, and HTML files into metaguided files.
42
43
 
43
-
44
44
  ## Installation
45
+
45
46
  Intellireading is a command line tool that can be used in Windows, Linux, and MacOS. It is written in Python and can be used as a module or as a standalone tool, as long as you have Python >3.7 installed (or Docker).
46
47
 
47
48
  ### pip
@@ -59,29 +60,28 @@ You can also install it from the source code:
59
60
  > pip install .
60
61
  > intellireading --help
61
62
  ```
63
+
62
64
  ### Docker
63
65
  Alternatively, you can use the Docker image:
64
66
 
65
67
  #### Help command
66
68
  ```console
67
- > docker pull ghcr.io/0x6f677548/intellireading-cli:latest
68
- > docker run -it --rm ghcr.io/0x6f677548/intellireading-cli --help
69
+ > docker pull ghcr.io/hugobatista/intellireading-cli:latest
70
+ > docker run -it --rm ghcr.io/hugobatista/intellireading-cli --help
69
71
  ```
70
72
 
71
73
  #### Metaguide an EPUB file
72
74
  ##### Linux/MacOS
73
75
  ```console
74
- ```linux
75
- > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
76
+ > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
76
77
  ```
77
78
  ##### Windows
78
79
  ```powershell
79
- > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
80
+ > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
80
81
  ```
81
82
 
83
+ ## CLI Usage
82
84
 
83
-
84
- ## Usage
85
85
  All available commands and options can be seen by using the `--help` option.
86
86
  ```console
87
87
  > intellireading --help
@@ -94,7 +94,7 @@ To get help on a specific command, use the `--help` option with the command name
94
94
 
95
95
  Intellireading is based on [Click](https://github.com/pallets/click/), taking advantage of its features, such as chaining commands and options.
96
96
 
97
- ### Usage Examples
97
+ ### CLI Examples
98
98
 
99
99
  #### Metaguide an EPUB file
100
100
  To metaguide an EPUB file, use the `metaguide-epub` command. The command requires the path to the EPUB file and the output file. The output file will be a metaguided epub file.
@@ -143,3 +143,224 @@ To remove metaguiding from all files in a directory, use the --remove_metaguidin
143
143
  ```console
144
144
  > intellireading metaguide-dir --remove_metaguiding --input_dir mydir_metaguided --output_dir mydir
145
145
  ```
146
+
147
+ ## Python Library API
148
+
149
+ The intellireading-cli package can be used as a Python library for programmatic access to metaguiding functionality. This is useful for integrating metaguiding into web applications, batch processing scripts, or other Python projects.
150
+
151
+ ### Quick Start
152
+
153
+ ```python
154
+ from intellireading.client import (
155
+ metaguide_epub_file,
156
+ metaguide_xhtml_file,
157
+ metaguide_epub_stream,
158
+ metaguide_xhtml_stream,
159
+ metaguide_dir,
160
+ is_file_metaguided,
161
+ )
162
+
163
+ # Metaguide an EPUB file
164
+ metaguide_epub_file("input.epub", "output.epub")
165
+
166
+ # Metaguide an XHTML file
167
+ metaguide_xhtml_file("input.html", "output.html")
168
+ ```
169
+
170
+ ### Core Functions
171
+
172
+ #### EPUB Functions
173
+
174
+ **`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
175
+
176
+ Metaguides an EPUB file by applying visual anchoring to text content within all XHTML files in the EPUB.
177
+
178
+ ```python
179
+ from intellireading.client import metaguide_epub_file
180
+
181
+ # Basic metaguiding
182
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
183
+
184
+ # Remove metaguiding (experimental)
185
+ metaguide_epub_file("mybook_metaguided.epub", "mybook_original.epub", remove_metaguiding=True)
186
+ ```
187
+
188
+ **`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
189
+
190
+ Metaguides an EPUB from a byte stream, useful for in-memory processing or web applications.
191
+
192
+ ```python
193
+ from io import BytesIO
194
+ from intellireading.client import metaguide_epub_stream
195
+
196
+ # Read EPUB into memory
197
+ with open("input.epub", "rb") as f:
198
+ input_stream = BytesIO(f.read())
199
+
200
+ # Metaguide the stream
201
+ output_stream = metaguide_epub_stream(input_stream)
202
+
203
+ # Write to file
204
+ with open("output.epub", "wb") as f:
205
+ f.write(output_stream.read())
206
+ ```
207
+
208
+ #### XHTML Functions
209
+
210
+ **`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
211
+
212
+ Metaguides an XHTML/HTML file by applying visual anchoring to text content. Supports `.xhtml`, `.html`, and `.htm` files.
213
+
214
+ ```python
215
+ from intellireading.client import metaguide_xhtml_file
216
+
217
+ # Metaguide an HTML file
218
+ metaguide_xhtml_file("article.html", "article_metaguided.html")
219
+
220
+ # Remove metaguiding
221
+ metaguide_xhtml_file("article_metaguided.html", "article_restored.html", remove_metaguiding=True)
222
+ ```
223
+
224
+ **`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
225
+
226
+ Metaguides an XHTML/HTML file from a byte stream.
227
+
228
+ ```python
229
+ from io import BytesIO
230
+ from intellireading.client import metaguide_xhtml_stream
231
+
232
+ # Process HTML content from string
233
+ html_content = """
234
+ <!DOCTYPE html>
235
+ <html>
236
+ <body>
237
+ <p>This is a sample paragraph that will be metaguided.</p>
238
+ </body>
239
+ </html>
240
+ """
241
+
242
+ input_stream = BytesIO(html_content.encode("utf-8"))
243
+ output_stream = metaguide_xhtml_stream(input_stream)
244
+ metaguided_content = output_stream.read().decode("utf-8")
245
+ ```
246
+
247
+ #### Directory Functions
248
+
249
+ **`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False)`**
250
+
251
+ Metaguides all EPUB and XHTML/HTML files found in a directory recursively.
252
+
253
+ ```python
254
+ from intellireading.client import metaguide_dir
255
+
256
+ # Metaguide all books in the directory
257
+ metaguide_dir("books", "books_metaguided")
258
+
259
+ # Remove metaguiding from all files
260
+ metaguide_dir("books_metaguided", "books_restored", remove_metaguiding=True)
261
+ ```
262
+
263
+ #### Utility Functions
264
+
265
+ **`is_file_metaguided(filepath: str) -> bool`**
266
+
267
+ Checks if an EPUB file has already been metaguided.
268
+
269
+ ```python
270
+ from intellireading.client import is_file_metaguided, metaguide_epub_file
271
+
272
+ # Check if file is already metaguided
273
+ if not is_file_metaguided("mybook.epub"):
274
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
275
+ print("File metaguided successfully")
276
+ else:
277
+ print("File is already metaguided")
278
+ ```
279
+
280
+ ### Integration Examples
281
+
282
+ #### Web Application (Flask)
283
+
284
+ ```python
285
+ from flask import Flask, request, send_file
286
+ from io import BytesIO
287
+ from intellireading.client import metaguide_epub_stream
288
+
289
+ app = Flask(__name__)
290
+
291
+
292
+ @app.route("/metaguide", methods=["POST"])
293
+ def metaguide_upload():
294
+ file = request.files["epub"]
295
+ if file and file.filename.endswith(".epub"):
296
+ input_stream = BytesIO(file.read())
297
+ output_stream = metaguide_epub_stream(input_stream)
298
+
299
+ return send_file(
300
+ output_stream,
301
+ as_attachment=True,
302
+ download_name=f"metaguided_{file.filename}",
303
+ mimetype="application/epub+zip",
304
+ )
305
+ return "Invalid file", 400
306
+ ```
307
+
308
+ #### Batch Processing
309
+
310
+ ```python
311
+ import os
312
+ from intellireading.client import metaguide_dir, is_file_metaguided
313
+
314
+
315
+ def batch_process_library(library_path):
316
+ """Process an entire library of EPUB files"""
317
+ processed_path = os.path.join(library_path, "metaguided")
318
+
319
+ # Process all files
320
+ metaguide_dir(library_path, processed_path)
321
+
322
+ # Verify results
323
+ for root, dirs, files in os.walk(processed_path):
324
+ for file in files:
325
+ if file.endswith(".epub"):
326
+ filepath = os.path.join(root, file)
327
+ if is_file_metaguided(filepath):
328
+ print(f"✓ Successfully metaguided: {file}")
329
+
330
+
331
+ batch_process_library("/path/to/my/books")
332
+ ```
333
+
334
+ ### Error Handling
335
+
336
+ ```python
337
+ from intellireading.client import metaguide_epub_file
338
+
339
+ try:
340
+ metaguide_epub_file("mybook.epub", "output.epub")
341
+ except ValueError as e:
342
+ print(f"Invalid file: {e}")
343
+ except FileNotFoundError as e:
344
+ print(f"File not found: {e}")
345
+ except Exception as e:
346
+ print(f"Unexpected error: {e}")
347
+ ```
348
+
349
+ ## Dependency updates
350
+
351
+ Dependencies are updated automatically by [Renovate](https://docs.renovatebot.com).
352
+ The configuration lives in [`renovate.json`](renovate.json).
353
+
354
+ Updates that pass the 30-day minimum release age are proposed as pull requests.
355
+ Major updates are labelled `major-update`, security updates are labelled `security`,
356
+ and `ghcr.io/astral-sh/uv` version bumps wait for approval in the Dependency Dashboard.
357
+
358
+ To run Renovate locally as a dry run:
359
+
360
+ ```bash
361
+ act workflow_dispatch -W .github/workflows/renovate.yml \
362
+ --env RENOVATE_DRY_RUN=full \
363
+ --env RENOVATE_REPOSITORIES=hugobatista/intellireading-cli \
364
+ --env LOG_LEVEL=info \
365
+ -s RENOVATE_TOKEN=<token>
366
+ ```
@@ -11,7 +11,7 @@ requires-python = ">=3.13"
11
11
  license = "GPL-3.0"
12
12
  keywords = ["kepub","epub", "calibre", "ebook","kindle","kobo","speed-reading", "dyslexia", "adhd"]
13
13
  authors = [
14
- { name = "Hugo Batista"},
14
+ { name = "Hugo Batista <intellireading at hugobatista.com>"},
15
15
  ]
16
16
  classifiers = [
17
17
  "Operating System :: OS Independent",
@@ -41,10 +41,39 @@ dependencies = [
41
41
  [project.scripts]
42
42
  intellireading = "intellireading.client:entrypoint"
43
43
 
44
+ [tool.uv]
45
+ required-version = ">=0.11.18"
46
+ exclude-newer = "30 days"
47
+
48
+ [[tool.uv.index]]
49
+ name = "pypi"
50
+ url = "https://pypi.org/simple"
51
+ explicit = true
52
+
53
+ [dependency-groups]
54
+ lint = [
55
+ "mypy>=1.0.0",
56
+ "ruff>=0.0.243",
57
+ "types-regex",
58
+ ]
59
+ test = [
60
+ "coverage[toml]>=6.5",
61
+ "pytest",
62
+ "pytest-cov",
63
+ ]
64
+ dev = [
65
+ "hatch>=1.16.5",
66
+ {include-group = "lint"},
67
+ {include-group = "test"},
68
+ ]
69
+
44
70
  [project.urls]
45
71
  Documentation = "https://go.hugobatista.com/gh/intellireading-cli#readme"
46
72
  Issues = "https://go.hugobatista.com/gh/intellireading-cli/issues"
47
73
  Source = "https://go.hugobatista.com/gh/intellireading-cli"
74
+ Homepage = "https://go.hugobatista.com/gh/intellireading-cli"
75
+ Repository = "https://go.hugobatista.com/gh/intellireading-cli.git"
76
+
48
77
 
49
78
  [tool.hatch.version]
50
79
  path = "src/intellireading/client/__about_cli__.py"
@@ -54,61 +83,24 @@ packages = ["src/intellireading"]
54
83
  exclude = ["tests"]
55
84
 
56
85
  [tool.hatch.build.targets.sdist]
57
- packages = ["src/intellireading"]
58
- exclude = ["tests"]
86
+ only-include = ["src/intellireading", "README.md"]
59
87
 
60
88
  [tool.hatch.envs.default]
61
- installer = "uv"
62
- dependencies = [
63
- "coverage[toml]>=6.5",
64
- "pytest",
65
- ]
66
- [tool.hatch.envs.default.scripts]
67
- test = "pytest {args:tests} -v"
68
- test-cov = "coverage run -m pytest {args:tests} -v"
69
- cov-report = [
70
- "- coverage combine",
71
- "coverage report",
72
- "coverage html",
73
- ]
74
- cov = [
75
- "test-cov",
76
- "cov-report",
77
- ]
78
-
79
- [[tool.hatch.envs.all.matrix]]
80
- python = ["3.13"]
81
-
82
- [tool.hatch.envs.lint]
83
- detached = true
84
- dependencies = [
85
- "black>=23.1.0",
86
- "mypy>=1.0.0",
87
- "ruff>=0.0.243",
88
- ]
89
- [tool.hatch.envs.lint.scripts]
90
- typing = "mypy --ignore-missing-imports --install-types --non-interactive {args:src/intellireading tests}"
91
- style = [
92
- "ruff check {args:.}",
93
- "black --check --diff {args:.}",
94
- ]
95
- fmt = [
96
- "black {args:.}",
97
- "ruff --fix {args:.}",
98
- "style",
99
- ]
100
- all = [
101
- "style",
102
- "typing",
103
- ]
89
+ type = "virtual"
90
+ path = ".venv"
104
91
 
105
- [tool.black]
106
- target-version = ["py37"]
107
- line-length = 120
108
- skip-string-normalization = true
92
+ [tool.hatch.envs.default.scripts]
93
+ lint = "ruff check . --fix"
94
+ format = "ruff format ."
95
+ lint-check = "ruff check ."
96
+ format-check = "ruff format --check ."
97
+ test = "pytest"
98
+ typecheck = "mypy"
99
+ validate = ["lint", "format", "test", "typecheck"]
100
+ check = ["lint-check", "format-check", "test", "typecheck"]
109
101
 
110
102
  [tool.ruff]
111
- target-version = "py37"
103
+ target-version = "py313"
112
104
  line-length = 120
113
105
  lint.select = [
114
106
  "A",
@@ -166,6 +158,9 @@ ban-relative-imports = "all"
166
158
  # Tests can use magic values, assertions, and relative imports
167
159
  "tests/**/*" = ["PLR2004", "S101", "TID252"]
168
160
 
161
+ [tool.ruff.format]
162
+ quote-style = "double"
163
+
169
164
  [tool.coverage.run]
170
165
  source_pkgs = ["intellireading", "tests"]
171
166
  branch = true
@@ -179,8 +174,36 @@ intellireading = ["src/intellireading", "*/intellireading-cli/src/intellireading
179
174
  tests = ["tests", "*/intellireading-cli/tests"]
180
175
 
181
176
  [tool.coverage.report]
177
+ show_missing = true
178
+ skip_covered = false
179
+ fail_under = 75
182
180
  exclude_lines = [
183
- "no cov",
181
+ "pragma: no cover",
182
+ "raise AssertionError",
183
+ "raise NotImplementedError",
184
184
  "if __name__ == .__main__.:",
185
185
  "if TYPE_CHECKING:",
186
186
  ]
187
+
188
+ [tool.pytest.ini_options]
189
+ addopts = "--tb=short --strict-markers --cov --cov-report=term-missing"
190
+ pythonpath = ["src"]
191
+ testpaths = ["tests"]
192
+
193
+ [tool.mypy]
194
+ python_version = "3.13"
195
+ strict = true
196
+ incremental = false
197
+ check_untyped_defs = true
198
+ mypy_path = ["src"]
199
+ files = ["src/intellireading"]
200
+ exclude = ["tests/"]
201
+
202
+ [[tool.mypy.overrides]]
203
+ module = ["lxml.*"]
204
+ ignore_missing_imports = true
205
+
206
+ [[tool.mypy.overrides]]
207
+ module = "tests.*"
208
+ disallow_untyped_defs = false
209
+ disallow_incomplete_defs = false
@@ -0,0 +1 @@
1
+ __version__ = "2.1.2"
@@ -1,4 +1,5 @@
1
1
  import click
2
+ from intellireading.client.__about_cli__ import __version__
2
3
  from intellireading.client.commands import (
3
4
  metaguide_epub_cmd,
4
5
  metaguide_xhtml_cmd,
@@ -11,6 +12,7 @@ from intellireading.client.commands import (
11
12
  chain=True,
12
13
  help="A set of tools designed to improve your reading experience.",
13
14
  )
15
+ @click.version_option(version=__version__)
14
16
  @click.option(
15
17
  "--log_level",
16
18
  default="WARNING",
@@ -18,7 +20,7 @@ from intellireading.client.commands import (
18
20
  help="The log level to use for logging (default: INFO). Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL",
19
21
  )
20
22
  @click.pass_context
21
- def cli(ctx: click.Context, log_level: str):
23
+ def cli(ctx: click.Context, log_level: str) -> None:
22
24
  ctx.ensure_object(dict)
23
25
 
24
26
  import logging
@@ -32,7 +34,7 @@ cli.add_command(metaguide_dir_cmd)
32
34
  cli.add_command(metaguide_xhtml_cmd)
33
35
 
34
36
 
35
- def entrypoint():
37
+ def entrypoint() -> None:
36
38
  cli(obj={})
37
39
 
38
40
 
@@ -2,7 +2,8 @@ import click
2
2
  import logging
3
3
  import sys
4
4
  from intellireading.client.metaguiding import metaguide_epub_file, metaguide_dir, metaguide_xhtml_file
5
- from typing import Callable, Any
5
+ from typing import Any, cast
6
+ from collections.abc import Callable
6
7
 
7
8
  _logger = logging.getLogger(__name__)
8
9
 
@@ -52,7 +53,7 @@ _remove_metaguiding_option = click.option(
52
53
  )
53
54
 
54
55
 
55
- def _exit_with_exception(exception: Exception, exit_code: int = 1, fg: str = "red"):
56
+ def _exit_with_exception(exception: Exception, exit_code: int = 1, fg: str = "red") -> None:
56
57
  """Exit the program with an exception and exit code"""
57
58
  try:
58
59
  _logger.exception(exception)
@@ -78,9 +79,9 @@ def _get_from_ctx_if_none(
78
79
  if value:
79
80
  return value
80
81
  elif ctx.obj.get(ctx_key):
81
- return ctx.obj[ctx_key]
82
+ return cast(str, ctx.obj[ctx_key])
82
83
  else:
83
- result = ctx.invoke(invoke_func, **kwargs)
84
+ result: str = ctx.invoke(invoke_func, **kwargs)
84
85
  return result
85
86
 
86
87
 
@@ -92,7 +93,7 @@ def _get_from_ctx_if_none(
92
93
  @_input_file_option
93
94
  @_output_file_option
94
95
  @_remove_metaguiding_option
95
- def metaguide_epub_cmd(ctx: click.Context, input_file: str, output_file: str, *, remove_metaguiding: bool):
96
+ def metaguide_epub_cmd(ctx: click.Context, input_file: str, output_file: str, *, remove_metaguiding: bool) -> None:
96
97
  """Applies or removes metaguiding to the provided epub/kepub file"""
97
98
 
98
99
  try:
@@ -123,7 +124,7 @@ def metaguide_epub_cmd(ctx: click.Context, input_file: str, output_file: str, *,
123
124
  @_input_dir_option
124
125
  @_output_dir_option
125
126
  @_remove_metaguiding_option
126
- def metaguide_dir_cmd(ctx: click.Context, input_dir: str, output_dir: str, *, remove_metaguiding: bool):
127
+ def metaguide_dir_cmd(ctx: click.Context, input_dir: str, output_dir: str, *, remove_metaguiding: bool) -> None:
127
128
  """Applies metaguiding to the provided directory, recursively, for all epubs and xhtml files found in the directory
128
129
  input_dir: str
129
130
  The input directory
@@ -161,7 +162,7 @@ def metaguide_dir_cmd(ctx: click.Context, input_dir: str, output_dir: str, *, re
161
162
  @_input_file_option
162
163
  @_output_file_option
163
164
  @_remove_metaguiding_option
164
- def metaguide_xhtml_cmd(ctx: click.Context, input_file: str, output_file: str, *, remove_metaguiding: bool):
165
+ def metaguide_xhtml_cmd(ctx: click.Context, input_file: str, output_file: str, *, remove_metaguiding: bool) -> None:
165
166
  """Applies or removes metaguiding to the provided xhtml file"""
166
167
 
167
168
  try:
@@ -4,7 +4,8 @@ import os
4
4
  import sys
5
5
  import traceback
6
6
  import zipfile
7
- from typing import Generator
7
+ from collections.abc import Generator
8
+ from typing import cast
8
9
  import math
9
10
  import regex as re
10
11
 
@@ -12,7 +13,6 @@ import regex as re
12
13
  # it still works
13
14
  from .__about_cli__ import __version__ as cli_version # noqa: TID252
14
15
 
15
-
16
16
  _logger = logging.getLogger(__name__)
17
17
  _METAGUIDED_FLAG_FILENAME = "intellireading.metaguide"
18
18
  _EPUB_EXTENSIONS = [".EPUB", ".KEPUB"]
@@ -143,10 +143,13 @@ class RegExBoldMetaguider:
143
143
  def _get_encoding_using_lxml(self, xhtml_document: bytes) -> str | None:
144
144
  from lxml import etree
145
145
 
146
- parser = etree.XMLParser(resolve_entities=False)
147
- doc = etree.fromstring(xhtml_document, parser=parser).getroottree()
148
- docinfo = doc.docinfo
149
- return docinfo.encoding
146
+ try:
147
+ parser = etree.XMLParser(resolve_entities=False)
148
+ doc = etree.fromstring(xhtml_document, parser=parser).getroottree()
149
+ docinfo = doc.docinfo
150
+ return cast(str | None, docinfo.encoding)
151
+ except etree.XMLSyntaxError:
152
+ return None
150
153
 
151
154
  def _get_encoding_using_bom(self, xhtml_document: bytes) -> str | None:
152
155
  if xhtml_document.startswith(b"\xef\xbb\xbf"):
@@ -167,15 +170,17 @@ class RegExBoldMetaguider:
167
170
  if not xhtml_document.startswith(b"<?xml "):
168
171
  return None
169
172
 
170
- xml_header_end = xhtml_document.find(b"?>") + 1
171
- if xml_header_end == 0:
172
- msg = "Invalid XHTML document. Could not find closing XML element."
173
- raise ValueError(msg)
173
+ xml_header_end = xhtml_document.find(b"?>")
174
+ if xml_header_end == -1:
175
+ # a truncated XML header is invalid, but should not prevent the remaining
176
+ # encoding detectors (BOM and lxml) from running
177
+ _logger.debug("XML header has no closing '?>'. Trying other encoding detection methods.")
178
+ return None
174
179
 
175
- header = xhtml_document[:xml_header_end].decode("utf-8")
180
+ header = xhtml_document[: xml_header_end + 2].decode("utf-8")
176
181
  match = re.search(r'encoding=(["\'])([a-zA-Z][a-zA-Z0-9-]{0,38}[a-zA-Z0-9])\1', header)
177
182
  if match:
178
- return match.group(2)
183
+ return cast(str, match.group(2))
179
184
  else:
180
185
  # although the XML header is present, it does not contain an encoding
181
186
  # this is not a valid XHTML document, but we can still try to detect the encoding on a later stage
@@ -210,7 +215,6 @@ class RegExBoldMetaguider:
210
215
 
211
216
 
212
217
  class _EpubItemFile:
213
-
214
218
  def __init__(self, filename: str | None = None, content: bytes = b"") -> None:
215
219
  self.filename = filename
216
220
  self.content = content
@@ -232,7 +236,7 @@ class _EpubItemFile:
232
236
  def __str__(self) -> str:
233
237
  return f"{self.filename} ({len(self.content)} bytes)"
234
238
 
235
- def metaguide(self, metaguider: RegExBoldMetaguider, *, remove_metaguiding: bool = False):
239
+ def metaguide(self, metaguider: RegExBoldMetaguider, *, remove_metaguiding: bool = False) -> None:
236
240
  if not remove_metaguiding and self.metaguided:
237
241
  _logger.warning(f"File {self.filename} already metaguided, skipping")
238
242
  elif self.is_toc_document:
@@ -249,7 +253,7 @@ class _EpubItemFile:
249
253
  _metaguider = RegExBoldMetaguider()
250
254
 
251
255
 
252
- def _get_epub_item_files_from_zip(input_zip: zipfile.ZipFile) -> list:
256
+ def _get_epub_item_files_from_zip(input_zip: zipfile.ZipFile) -> list[_EpubItemFile]:
253
257
  def read_compressed_file(input_zip: zipfile.ZipFile, filename: str) -> _EpubItemFile:
254
258
  return _EpubItemFile(filename, input_zip.read(filename))
255
259
 
@@ -260,15 +264,15 @@ def _get_epub_item_files_from_zip(input_zip: zipfile.ZipFile) -> list:
260
264
 
261
265
  def _process_epub_item_files(
262
266
  epub_item_files: list[_EpubItemFile], *, remove_metaguiding: bool = False
263
- ) -> Generator[_EpubItemFile, None, None]:
267
+ ) -> Generator[_EpubItemFile]:
264
268
  for epub_item_file in epub_item_files:
265
269
  _logger.debug(f"Processing file '{epub_item_file.filename}' remove_metaguiding={remove_metaguiding}")
266
270
  epub_item_file.metaguide(_metaguider, remove_metaguiding=remove_metaguiding)
267
271
  yield epub_item_file
268
272
 
269
273
 
270
- def _write_item_files_to_zip(epub_item_files, output_zip):
271
- def write_compressed_file(output_zip: zipfile.ZipFile, epub_item_file: _EpubItemFile):
274
+ def _write_item_files_to_zip(epub_item_files: list[_EpubItemFile], output_zip: zipfile.ZipFile) -> None:
275
+ def write_compressed_file(output_zip: zipfile.ZipFile, epub_item_file: _EpubItemFile) -> None:
272
276
  if epub_item_file.filename is None:
273
277
  msg = "EpubItemFile.filename is None"
274
278
  raise ValueError(msg)
@@ -281,14 +285,14 @@ def _write_item_files_to_zip(epub_item_files, output_zip):
281
285
  write_compressed_file(output_zip, _epub_item_file)
282
286
 
283
287
 
284
- def _ensure_file_exists(input_file: str):
288
+ def _ensure_file_exists(input_file: str) -> None:
285
289
  if not os.path.isfile(input_file):
286
290
  exception_message = f"Input file '{input_file}' does not exist"
287
291
  _logger.error(exception_message)
288
292
  raise ValueError(exception_message)
289
293
 
290
294
 
291
- def _ensure_allowed_extension(input_file: str, extensions: list[str]):
295
+ def _ensure_allowed_extension(input_file: str, extensions: list[str]) -> None:
292
296
  file_extension = os.path.splitext(input_file)[-1].upper()
293
297
  if file_extension not in extensions:
294
298
  exception_message = f"Input file '{input_file}' extension is not in {extensions}"
@@ -324,7 +328,7 @@ def _check_flag_file(
324
328
  return is_already_metaguided, flag_file
325
329
 
326
330
 
327
- def metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False):
331
+ def metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False) -> None:
328
332
  """Metaguide an epub file
329
333
  input_file: str
330
334
  The input epub file
@@ -398,7 +402,7 @@ def metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = F
398
402
  return output_stream
399
403
 
400
404
 
401
- def metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False):
405
+ def metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False) -> None:
402
406
  """Metaguide an xhtml file
403
407
  input_file: str
404
408
  The input xhtml file
@@ -436,7 +440,7 @@ def metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bo
436
440
  return output_file_stream
437
441
 
438
442
 
439
- def metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False):
443
+ def metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False) -> None:
440
444
  """Metaguides all epubs and xhtml found in a directory (recursively)
441
445
  input_dir: str
442
446
  The input epub/xhtml directory
@@ -448,7 +452,7 @@ def metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool =
448
452
 
449
453
  # get a list of all the files in the directory, and the child directories if recursive
450
454
  # verify if the file is a file and if it has the correct extension
451
- def get_files(directory, recursive):
455
+ def get_files(directory: str, *, recursive: bool) -> Generator[str]:
452
456
  for filename in os.listdir(directory):
453
457
  input_filename = os.path.join(directory, filename)
454
458
 
@@ -456,7 +460,7 @@ def metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool =
456
460
  if os.path.isfile(input_filename) and (extension in _EPUB_EXTENSIONS or extension in _XHTML_EXTENSIONS):
457
461
  yield input_filename
458
462
  elif os.path.isdir(input_filename) and recursive:
459
- yield from get_files(input_filename, recursive)
463
+ yield from get_files(input_filename, recursive=recursive)
460
464
 
461
465
  _logger.info(f"Processing files in {input_dir} to {output_dir} (recursively)")
462
466
 
@@ -469,7 +473,7 @@ def metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool =
469
473
  _logger.info(f"Creating {output_dir}")
470
474
  os.makedirs(output_dir)
471
475
 
472
- for input_filename in get_files(input_dir, True):
476
+ for input_filename in get_files(input_dir, recursive=True):
473
477
  output_filename = os.path.join(output_dir, os.path.basename(input_filename))
474
478
  _logger.debug(f"Processing {input_filename} to {output_filename}")
475
479
 
@@ -1,8 +0,0 @@
1
- __pycache__
2
- *.venv
3
- *.json
4
- .debug
5
- .coverage
6
- dist/*
7
- app/*
8
- tests/test_files/output
@@ -1 +0,0 @@
1
- __version__ = "2.1.0"