refactor(utils): extract Ghostscript compression into app/pdf_compress (R5.1) - #160
Open
nelsonduarte wants to merge 2 commits into
Open
refactor(utils): extract Ghostscript compression into app/pdf_compress (R5.1)#160nelsonduarte wants to merge 2 commits into
nelsonduarte wants to merge 2 commits into
Conversation
Split the most cohesive cluster out of the app/utils.py 'junk drawer'
(R5 increment 1): the Ghostscript-backed compression pipeline.
app/pdf_compress.py now owns _find_gs, _win_short_path, _compress_pdf
plus the compression-only _COMPRESS_LEVELS and _GS_CACHE. The
implementations are copied faithfully with zero behaviour change.
Shared PDF helpers stay in app.utils and are imported by pdf_compress
(one-directional dependency, no import cycle):
- CancelledError (also used by worker.py + tools/convert.py)
- WrongPasswordError (shared error type, imported by tests)
- _is_valid_pdf (general PDF-validity helper, tested independently)
Importers updated (option a, small surface):
- app/tools/compress.py imports _compress_pdf / _find_gs from
app.pdf_compress; utils-only helpers still from app.utils
- tests/test_encrypted_pdf_tools.py, tests/test_audit_pr_j.py and
tests/test_audit_mediums_lows.py updated (imports + the two
source-reading assertions now target app/pdf_compress.py)
Full suite: 585 passed / 2 skipped. ruff (F,E9,B) clean on the three
app modules.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…_CACHE to satisfy CodeQL
Resolves 17 CodeQL alerts introduced when the Ghostscript compression
pipeline was moved verbatim from app.utils into app.pdf_compress (R5.1);
they were previously grandfathered on the old file.
- py/empty-except (16x): add an honest comment to each 'except ... : pass'
explaining why the exception is safely swallowed (best-effort temp
cleanup, optional pass fallbacks, best-effort scrub/subset/rewrite,
eager close to release Windows file handles). No exception type or
control flow changed.
- py/unused-global-variable (_GS_CACHE): the negative-result store
'_GS_CACHE = (True, None)' was flagged because its value is never read
before the immediate 'return None'. It IS meaningful across calls (it
short-circuits the slow Windows glob on machines without gs). Return
through the cache tuple instead ('return _GS_CACHE[1]', which is None
here) so the store is a read for the analyser, mirroring the other two
return paths. Behaviour is identical.
Comments-only plus one behaviour-preserving return; verified via git diff.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Deploying pdfapps with
|
| Latest commit: |
e067c37
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d483a16d.pdfapps.pages.dev |
| Branch Preview URL: | https://refactor-split-utils-compres.pdfapps.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
R5 (incremento 1) do plano de modularidade: parte o junk-drawer
utils.pyextraindo o cluster de compressao Ghostscript (_find_gs,_win_short_path,_compress_pdf,_COMPRESS_LEVELS,_GS_CACHE) para o novo moduloapp/pdf_compress.py.Detalhes
pdf_compress -> utils(sem ciclo).CancelledError/WrongPasswordError/_is_valid_pdf) ficam emutils.py.app/tools/compress.py+ 3 testes (tests/test_encrypted_pdf_tools.py,tests/test_audit_pr_j.py,tests/test_audit_mediums_lows.py)._compress_pdf).Nota
Primeiro de varios incrementos a partir de
utils.py(as UI factories virao depois). Depende de R1/R2/R3 (ja emmain).