Skip to content

Commit

Permalink
FIXUP: Various CI-related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
apyrgio committed Jun 17, 2024
1 parent 91963c0 commit 3125a59
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install poetry
- run: poetry install
- name: Restore cached tessdata
uses: actions/cache/restore@v4
with:
path: share/tessdata/
enableCrossOsArchive: true
fail-on-cache-miss: true
key: v1-tessdata-${{ hashFiles('./install/common/download-tessdata.py') }}
- run: pip install poetry
- run: poetry install
- name: Run CLI tests
run: poetry run make test
# Taken from: https://github.com/orgs/community/discussions/27149#discussioncomment-3254829
Expand Down
37 changes: 24 additions & 13 deletions dangerzone/isolation_provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@ def pixels_to_pdf_page(
page_pdf_bytes = self.ocr_page(pixmap, ocr_lang)
else: # Don't OCR
page_doc = fitz.Document()
page_doc.insert_file(pixmap)
page_pdf_bytes = page_doc.tobytes(deflate_images=True)
# Added in PyMuPDF 1.22.0 (commit 6a9c9d8175c307f7f3baf605c8632745f69a8b1b)
if hasattr(page_doc, "insert_file"):
page_doc.insert_file(pixmap)
page_pdf_bytes = page_doc.tobytes(deflate_images=True)
else:
page = page_doc.newPage()
page.insertImage(page.rect, pixmap=pixmap)
page_pdf_bytes = page_doc.write(deflate=True)

return fitz.open("pdf", page_pdf_bytes)

Expand Down Expand Up @@ -240,12 +246,27 @@ def _convert(
# Ensure nothing else is read after all bitmaps are obtained
p.stdout.close()

safe_doc.save(document.output_filename)
if hasattr(safe_doc, "tobytes"):
pdf_bytes = safe_doc.tobytes()
else:
pdf_bytes = safe_doc.write()
with open(document.output_filename, "wb+") as f:
f.write(pdf_bytes)

# TODO handle leftover code input
text = "Converted document"
self.print_progress(document, False, text, percentage)

if getattr(sys, "dangerzone_dev", False):
assert p.stderr
debug_log = read_debug_text(p.stderr, MAX_CONVERSION_LOG_CHARS)
log.info(
"Conversion output (doc to pixels)\n"
f"{DOC_TO_PIXELS_LOG_START}\n"
f"{debug_log}" # no need for an extra newline here
f"{DOC_TO_PIXELS_LOG_END}"
)

def print_progress(
self, document: Document, error: bool, text: str, percentage: float
) -> None:
Expand Down Expand Up @@ -354,13 +375,3 @@ def doc_to_pixels_proc(
self.ensure_stop_doc_to_pixels_proc(
document, p, timeout_grace=timeout_grace, timeout_force=timeout_force
)

if getattr(sys, "dangerzone_dev", False):
assert p.stderr
debug_log = read_debug_text(p.stderr, MAX_CONVERSION_LOG_CHARS)
log.info(
"Conversion output (doc to pixels)\n"
f"{DOC_TO_PIXELS_LOG_START}\n"
f"{debug_log}" # no need for an extra newline here
f"{DOC_TO_PIXELS_LOG_END}"
)
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python = ">=3.9,<3.13"
click = "*"
appdirs = "*"
PySide6 = "^6.7.1"
PyMuPDF = "^1.23.8"
PyMuPDF = "^1.16.11"
colorama = "*"
pyxdg = {version = "*", platform = "linux"}
requests = "*"
Expand Down
2 changes: 1 addition & 1 deletion stdeb.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[DEFAULT]
Package3: dangerzone
Depends3: podman, python3, python3-pyside2.qtcore, python3-pyside2.qtgui, python3-pyside2.qtwidgets, python3-pyside2.qtsvg, python3-appdirs, python3-click, python3-xdg, python3-colorama, python3-requests, python3-markdown, python3-packaging, python3-fitz (>= 1.19.0) | pyocr
Depends3: podman, python3, python3-pyside2.qtcore, python3-pyside2.qtgui, python3-pyside2.qtwidgets, python3-pyside2.qtsvg, python3-appdirs, python3-click, python3-xdg, python3-colorama, python3-requests, python3-markdown, python3-packaging, python3-fitz (>= 1.19.0) | python3-pyocr
Build-Depends: dh-python, python3, python3-setuptools, python3-stdeb
Suite: bionic
X-Python3-Version: >= 3.8
Expand Down

0 comments on commit 3125a59

Please sign in to comment.