Skip to content

Commit

Permalink
Merge branch 'main' into standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofinch committed Jan 6, 2025
2 parents 6aad353 + 79c09cd commit f4ab6a7
Show file tree
Hide file tree
Showing 31 changed files with 2,580 additions and 473 deletions.
175 changes: 175 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
.github
docs
.git
.pre-commit-config.yaml
uv.lock
pdf2zh_files
gui/pdf2zh_files
gradio_files
tmp
gui/gradio_files
gui/tmp
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
.vscode
.DS_Store
10 changes: 10 additions & 0 deletions .github/workflows/black.format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Format Code with Black

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
34 changes: 26 additions & 8 deletions .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Build Python Package
name: Test and Build Python Package

on:
push:
branches:
- main
pull_request:

jobs:
Expand All @@ -19,13 +17,33 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build flake8 black
pip3 install -U pip
pip3 install -e .[dev]
- name: Check code format
- name: Test - Code format
run: |
black --check --diff --color pdf2zh/*.py
black --check --diff --color pdf2zh/*.py test/*.py
flake8 --ignore E203,E261,E501,W503,E741
- name: Test - Unit Test
run: |
pytest .
- name: Test - Translate a PDF file with plain text only
run:
pdf2zh ./test/file/translate.cli.plain.text.pdf

- name: Test - Translate a PDF file figure
run:
pdf2zh ./test/file/translate.cli.text.with.figure.pdf

# - name: Test - Translate a PDF file with unknown font
# run:
# pdf2zh ./test/file/translate.cli.font.unknown.pdf

- name: Test - Start GUI and exit
run:
timeout 10 pdf2zh -i || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi

- name: Build package
- name: Build as a package
run: python -m build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
.vscode
.DS_Store
uv.lock
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
FROM python:3.12
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

WORKDIR /app

COPY . .

EXPOSE 7860

ENV PYTHONUNBUFFERED=1
ADD "https://github.com/satbyy/go-noto-universal/releases/download/v7.0/GoNotoKurrent-Regular.ttf" /app
RUN apt-get update && \
apt-get install --no-install-recommends -y libgl1 && \
rm -rf /var/lib/apt/lists/* && uv pip install --system --no-cache huggingface-hub && \
python3 -c "from huggingface_hub import hf_hub_download; hf_hub_download('wybxc/DocLayout-YOLO-DocStructBench-onnx','doclayout_yolo_docstructbench_imgsz1024.onnx');"

RUN apt-get update && apt-get install -y libgl1
COPY . .

RUN pip install .
RUN uv pip install --system --no-cache .

CMD ["pdf2zh", "-i"]
Loading

0 comments on commit f4ab6a7

Please sign in to comment.