diff --git a/.github/workflows/ci.txt b/.github/workflows/ci.txt index 065e23e..73df9ab 100644 --- a/.github/workflows/ci.txt +++ b/.github/workflows/ci.txt @@ -1,12 +1,18 @@ # -# This file is autogenerated by pip-compile with python 3.11 -# To update, run: +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: # # pip-compile .github/workflows/ci.in # -pydantic==1.10.4 - # via -r .github/workflows/ci.in -pypdf==3.3.0 +annotated-types==0.6.0 + # via pydantic +pydantic==2.5.0 # via -r .github/workflows/ci.in -typing-extensions==4.4.0 +pydantic-core==2.14.1 # via pydantic +pypdf==3.17.0 + # via -r .github/workflows/ci.in +typing-extensions==4.8.0 + # via + # pydantic + # pydantic-core diff --git a/.github/workflows/json_consistency.py b/.github/workflows/json_consistency.py index c7bec8a..1383bb6 100644 --- a/.github/workflows/json_consistency.py +++ b/.github/workflows/json_consistency.py @@ -1,5 +1,6 @@ import datetime import json +import logging import sys from pathlib import Path @@ -7,13 +8,17 @@ from pypdf import PdfReader +logger = logging.getLogger() + +logger.level = logging.ERROR + class AnnotationCount(BaseModel): - Highlight: int | None - Ink: int | None - Link: int | None - Text: int | None - Widget: int | None + Highlight: int | None = None + Ink: int | None = None + Link: int | None = None + Text: int | None = None + Widget: int | None = None def items(self) -> list[tuple[str, int]]: return [ @@ -47,7 +52,7 @@ def main() -> None: """Check the consistency of the JSON metadata file.""" with open("files.json") as f: data = json.load(f) - main_pdf = MainPdfFile.parse_obj(data) + main_pdf = MainPdfFile.model_validate(data) registered_pdfs = [] seen_failure = False diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2f6d5c..0e34938 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ # pre-commit run --all-files repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.5.0 hooks: - id: check-ast - id: check-case-conflict @@ -20,21 +20,21 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: 22.1.0 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/asottile/pyupgrade - rev: v2.31.1 + rev: v3.15.0 hooks: - id: pyupgrade args: [--py39-plus] - repo: https://github.com/asottile/blacken-docs - rev: v1.12.1 + rev: 1.16.0 hooks: - id: blacken-docs additional_dependencies: [black==22.1.0] - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.280' + rev: 'v0.1.5' hooks: - id: ruff args: ['--fix'] diff --git a/025-attachment/add_attachment.py b/025-attachment/add_attachment.py new file mode 100644 index 0000000..d6a58d5 --- /dev/null +++ b/025-attachment/add_attachment.py @@ -0,0 +1,10 @@ +from pypdf import PdfReader, PdfWriter + +reader = PdfReader("../001-trivial/minimal-document.pdf") +writer = PdfWriter() +writer.append_pages_from_reader(reader) + +with open("image.png", "rb") as file: + writer.add_attachment("image.png", file.read()) +with open("with-attachment.pdf", "wb") as file: + writer.write(file) diff --git a/025-attachment/image.png b/025-attachment/image.png new file mode 100644 index 0000000..7d74f9a Binary files /dev/null and b/025-attachment/image.png differ diff --git a/025-attachment/with-attachment.pdf b/025-attachment/with-attachment.pdf new file mode 100644 index 0000000..c54c152 Binary files /dev/null and b/025-attachment/with-attachment.pdf differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b30d534 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +maint: + pip-compile .github/workflows/ci.in --upgrade diff --git a/files.json b/files.json index ce93bbc..9ea5554 100644 --- a/files.json +++ b/files.json @@ -317,6 +317,16 @@ "Highlight": 1, "Ink": 1 } + }, + { + "path": "025-attachment/with-attachment.pdf", + "producer": "pypdf", + "creation_date": null, + "encrypted": false, + "pages": 1, + "images": 1, + "forms": 0, + "annotations": {} } ] -} \ No newline at end of file +}