refactor: replace deprecated PyPDF2 with pypdf - #480
Conversation
- Replace deprecated PyPDF2 (unmaintained since 2022) with pypdf >= 4.0.0 - Update core PDF extraction, metadata readers, and token counters - Update Flash parser_pdfium_charlevel adapter and parallel worker - Keep backwards-compatible alias for pdf_parser='PyPDF2' in get_page_tokens - Fix DependencyError crash on AES permission-only encrypted PDFs - Update test suite and add regression test for AES-encrypted PDFs Closes VectifyAI#478 Closes VectifyAI#426
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00bdd03844
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| openai-agents = ">=0.18.1" | ||
| litellm = ">=1.97.0" | ||
| PyPDF2 = ">=3.0.0" | ||
| pypdf = ">=4.0.0" |
There was a problem hiding this comment.
Install pypdf's crypto extra for AES documents
On a clean pageindex installation, pypdf does not include its optional AES backend, so opening the permission-only AES PDFs described in #426 can still raise DependencyError; depend on the crypto extra in both package manifests. The new regression test does not expose this because PdfWriter.encrypt(..., algorithm=None) defaults to RC4 rather than AES, despite the test name and docstring.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch! Updated pyproject.toml and requirements.txt to require pypdf[crypto], and parametrized test_permission_only_encrypted_pdf_does_not_crash_on_aes to explicitly test both AES-128 and AES-256 encryption algorithms.
Summary
PyPDF2library with modernpypdf(>= 4.0.0) across the entire repository.DeprecationWarning: PyPDF2 is deprecated. Please move to the pypdf library instead.across test and runtime runs.pageindex.utils.get_page_tokens(..., pdf_parser="PyPDF2")as an alias to thepypdfreader.Changes
PyPDF2==3.0.1/PyPDF2 = ">=3.0.0"withpypdf>=4.0.0inrequirements.txtandpyproject.toml.pageindex/utils.py: ReplacedPyPDF2.PdfReaderwithpypdf.PdfReaderfor text extraction, token counting, and metadata extraction.pageindex/local_api.py: Updated_extract_page_textsto usepypdf.PdfReader.parser_pdfium_charlevel&parser_pdfium_parallel):_PdfDocand internal generic AST imports fromPyPDF2.generictopypdf.generic.pypdf.PdfReader.tests/test_client.pyforpypdf.test_permission_only_encrypted_pdf_does_not_crash_on_aescovering issue PyPDF2.errors.DependencyError: PyCryptodome is required for AES algorithm — crash on permission-only-encrypted PDFs (Flash preview) #426.tests/test_package_surface.py.Verification
pytest:DeprecationWarningforPyPDF2.DependencyError.Closes #478
Closes #426