Skip to content

Commit

Permalink
Merge branch 'rl-0.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
amenezes committed Dec 6, 2023
2 parents 4021d06 + 2b5b680 commit f03de38
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 167 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ jobs:
tests:
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.8', 'pypy-3.9', 'pypy-3.10']
python-version: [
'3.8',
'3.9',
'3.10',
'3.11',
'3.12',
'pypy-3.8',
'pypy-3.9',
'pypy-3.10'
]
os: [ubuntu]
fail-fast: true
runs-on: ${{ matrix.os }}-latest
Expand Down
74 changes: 40 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,44 @@ exclude: >
)
fail_fast: false
repos:
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
- id: isort
name: isort
entry: isort
language: system
types: [python]
args: ["--profile", "black"]
- id: flake8
name: flake8
entry: flake8
language: system
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
- id: isort
name: isort
entry: isort
language: system
types: [python]
args: ["--profile", "black"]
- id: flake8
name: flake8
entry: flake8
language: system
types: [ python ]
- id: mypy
name: mypy
entry: mypy
language: system
types: [ python ]
- id: mypy
name: mypy
entry: mypy
language: system
types: [ python ]
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
hooks:
- id: forbid-crlf
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
hooks:
- id: forbid-crlf
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
additional_dependencies:
- flake8-encodings==0.5.1
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tests:
docs:
@echo "> generate project documentation..."
@cp README.md docs/index.md
mkdocs serve
mkdocs serve -a 0.0.0.0:8000

install-deps:
@echo "> installing dependencies..."
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,16 @@ async with aiopytesseract.run(
alto_file, tsv_file, txt_file = resp
```

For more details on Tesseract best practices and the aiopytesseract, see the folder: `docs`.

## Examples

If you want to test **aiopytesseract** easily, can you use some options like:

- docker
- docker-compose
- docker/docker-compose
- [streamlit](https://streamlit.io)

### Docker

Just copy and paste the following line.

```bash
docker run --rm --name aiopytesseract -p 8501:8501 amenezes/aiopytesseract
```

### docker-compose
### Docker / docker-compose

After clone this repo run the command below:

Expand All @@ -117,15 +110,21 @@ docker-compose up -d

For this option it's necessary first install `aiopytesseract` and `streamlit`, after execute:

```python
``` py
# remote option:
streamlit run https://github.com/amenezes/aiopytesseract/blob/master/examples/streamlit/app.py
```

``` py
# local option:
streamlit run examples/streamlit/app.py
```

> note: The streamlit example need **python >= 3.10**

## Links

- License: [Apache License](https://choosealicense.com/licenses/apache-2.0/)
- Code: [https://github.com/amenezes/aiopytesseract](https://github.com/amenezes/aiopytesseract)
- Issue tracker: [https://github.com/amenezes/aiopytesseract/issues](https://github.com/amenezes/aiopytesseract/issues)
- Docs: [https://aiopytesseract.amenezes.net](https://github.com/amenezes/aiopytesseract)
- Docs: [https://github.com/amenezes/aiopytesseract](https://github.com/amenezes/aiopytesseract)
2 changes: 1 addition & 1 deletion aiopytesseract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from .models import OSD, Box, Data, Parameter

__version__ = "0.12.0"
__version__ = "0.13.0"
__all__ = [
"__version__",
"OSD",
Expand Down
49 changes: 27 additions & 22 deletions aiopytesseract/base_command.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import asyncio
import shlex
from asyncio.subprocess import Process
from collections import deque
from functools import singledispatch
from pathlib import Path
from typing import Any, List, Optional, Tuple
from typing import Any, List, Tuple, Union

from ._logger import logger
from .constants import (
Expand All @@ -17,7 +18,9 @@
from .validators import file_exists, language_is_valid, oem_is_valid, psm_is_valid


async def execute_cmd(cmd_args: str, timeout: float = AIOPYTESSERACT_DEFAULT_TIMEOUT):
async def execute_cmd(
cmd_args: str, timeout: float = AIOPYTESSERACT_DEFAULT_TIMEOUT
) -> Process:
logger.debug(
f"aiopytesseract command: '{TESSERACT_CMD} {shlex.join(shlex.split(cmd_args))}'"
)
Expand All @@ -31,6 +34,8 @@ async def execute_cmd(cmd_args: str, timeout: float = AIOPYTESSERACT_DEFAULT_TIM
),
timeout=timeout,
)
if proc is None:
raise TesseractRuntimeError()
return proc


Expand All @@ -42,10 +47,10 @@ async def execute(
psm: int,
oem: int,
timeout: float,
lang: Optional[str] = None,
user_words: Optional[str] = None,
user_patterns: Optional[str] = None,
tessdata_dir: Optional[str] = None,
lang: Union[None, str] = None,
user_words: Union[None, str] = None,
user_patterns: Union[None, str] = None,
tessdata_dir: Union[None, str] = None,
) -> bytes:
raise NotImplementedError

Expand All @@ -58,10 +63,10 @@ async def _(
psm: int,
oem: int,
timeout: float,
lang: Optional[str] = None,
user_words: Optional[str] = None,
user_patterns: Optional[str] = None,
tessdata_dir: Optional[str] = None,
lang: Union[None, str] = None,
user_words: Union[None, str] = None,
user_patterns: Union[None, str] = None,
tessdata_dir: Union[None, str] = None,
) -> bytes:
await file_exists(image)
response: bytes = await execute(
Expand All @@ -84,13 +89,13 @@ async def _(
image: bytes,
output_format: str,
dpi: int,
lang: Optional[str],
lang: Union[None, str],
psm: int,
oem: int,
timeout: float,
user_words: Optional[str] = None,
user_patterns: Optional[str] = None,
tessdata_dir: Optional[str] = None,
user_words: Union[None, str] = None,
user_patterns: Union[None, str] = None,
tessdata_dir: Union[None, str] = None,
encoding: str = AIOPYTESSERACT_DEFAULT_ENCODING,
) -> bytes:
cmd_args = await _build_cmd_args(
Expand Down Expand Up @@ -134,9 +139,9 @@ async def execute_multi_output_cmd(
psm: int,
oem: int,
timeout: float,
user_words: Optional[str] = None,
user_patterns: Optional[str] = None,
tessdata_dir: Optional[str] = None,
user_words: Union[None, str] = None,
user_patterns: Union[None, str] = None,
tessdata_dir: Union[None, str] = None,
encoding: str = AIOPYTESSERACT_DEFAULT_ENCODING,
) -> Tuple[str, ...]:
cmd_args = await _build_cmd_args(
Expand Down Expand Up @@ -168,7 +173,7 @@ async def execute_multi_output_cmd(
if proc.returncode != ReturnCode.SUCCESS:
raise TesseractRuntimeError(stderr.decode(encoding))
return tuple(
[f"{output_file}{OUTPUT_FILE_EXTENSIONS[ext]}" for ext in output_format.split()] # type: ignore
[f"{output_file}{OUTPUT_FILE_EXTENSIONS[ext]}" for ext in output_format.split()]
)


Expand All @@ -177,10 +182,10 @@ async def _build_cmd_args(
dpi: int,
psm: int,
oem: int,
user_words: Optional[str] = None,
user_patterns: Optional[str] = None,
tessdata_dir: Optional[str] = None,
lang: Optional[str] = None,
user_words: Union[None, str] = None,
user_patterns: Union[None, str] = None,
tessdata_dir: Union[None, str] = None,
lang: Union[None, str] = None,
output: str = "stdout",
) -> List[str]:
await asyncio.gather(psm_is_valid(psm), oem_is_valid(oem))
Expand Down
Loading

0 comments on commit f03de38

Please sign in to comment.