diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index f302b58..d4cda99 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -73,7 +73,7 @@ jobs: - name: Test with ruff run: | echo `ruff --version` - ruff pdfly/ + ruff check pdfly/ package: name: Build & verify package diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e27e3e6..fe3ff6b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: - id: blacken-docs additional_dependencies: [black==22.1.0] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.2 + rev: v0.7.4 hooks: - id: ruff args: ['--fix'] diff --git a/docs/conf.py b/docs/conf.py index 07e324c..eae1ba7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,6 +5,7 @@ For a full list see the documentation: https://www.sphinx-doc.org/en/master/usage/configuration.html """ + # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, diff --git a/pdfly/__init__.py b/pdfly/__init__.py index 7364aa3..1efc402 100644 --- a/pdfly/__init__.py +++ b/pdfly/__init__.py @@ -1,4 +1,5 @@ """pdfly is a command line utility for manipulating PDFs and getting information about them.""" + from ._version import __version__ __all__ = [ diff --git a/pdfly/cat.py b/pdfly/cat.py index eacb2c0..324d823 100644 --- a/pdfly/cat.py +++ b/pdfly/cat.py @@ -42,7 +42,6 @@ # All rights reserved. This software is available under a BSD license; # see https://github.com/py-pdf/pypdf/LICENSE - import os import sys import traceback @@ -71,13 +70,13 @@ def main( writer = PdfWriter() in_fs = {} try: - for filename, page_range in filename_page_ranges: # type: ignore + for filepath, page_range in filename_page_ranges: # type: ignore if verbose: - print(filename, page_range, file=sys.stderr) - if filename not in in_fs: - in_fs[filename] = open(filename, "rb") + print(filepath, page_range, file=sys.stderr) + if filepath not in in_fs: + in_fs[filepath] = open(filepath, "rb") - reader = PdfReader(in_fs[filename]) + reader = PdfReader(in_fs[filepath]) num_pages = len(reader.pages) start, end, step = page_range.indices(num_pages) if ( @@ -117,11 +116,11 @@ def parse_filepaths_and_pagerange_args( fn_pgrgs_l = list(fn_pgrgs) fn_pgrgs_l.insert(0, str(filename)) filename_page_ranges, invalid_filepaths = [], [] - for filename, page_range in parse_filename_page_ranges(fn_pgrgs_l): # type: ignore - if Path(filename).is_file(): - filename_page_ranges.append((filename, page_range)) + for filepath, page_range in parse_filename_page_ranges(fn_pgrgs_l): # type: ignore + if Path(filepath).is_file(): + filename_page_ranges.append((Path(filepath), page_range)) else: - invalid_filepaths.append(str(filename)) + invalid_filepaths.append(str(filepath)) if invalid_filepaths: print( f"Invalid file path or page range provided: {' '.join(invalid_filepaths)}", diff --git a/pdfly/cli.py b/pdfly/cli.py index 9c5fa31..44b5ecd 100644 --- a/pdfly/cli.py +++ b/pdfly/cli.py @@ -57,7 +57,7 @@ def extract_images( exists=True, resolve_path=True, ), - ] + ], ) -> None: pdfly.extract_images.main(pdf) @@ -175,7 +175,7 @@ def extract_text( exists=True, resolve_path=True, ), - ] + ], ) -> None: """Extract text from a PDF file.""" from pypdf import PdfReader @@ -198,7 +198,6 @@ def compress( output: Annotated[ Path, typer.Argument( - exists=False, writable=True, ), ], @@ -211,18 +210,14 @@ def uncompress( pdf: Annotated[ Path, typer.Argument( - exists=True, - file_okay=True, dir_okay=False, - writable=False, - readable=True, + exists=True, resolve_path=True, ), ], output: Annotated[ Path, typer.Argument( - exists=False, writable=True, ), ], diff --git a/pdfly/pagemeta.py b/pdfly/pagemeta.py index 762fce6..7830fc2 100644 --- a/pdfly/pagemeta.py +++ b/pdfly/pagemeta.py @@ -57,9 +57,7 @@ def main(pdf: Path, page_index: int, output: OutputOptions) -> None: ) table.add_row( "artbox", - f"{meta.artbox}: " - f"with={meta.artbox[2] - meta.artbox[0]} " - f"x height={meta.artbox[3] - meta.artbox[1]}", + f"{meta.artbox}: with={meta.artbox[2] - meta.artbox[0]} x height={meta.artbox[3] - meta.artbox[1]}", ) table.add_row( "bleedbox", diff --git a/pdfly/update_offsets.py b/pdfly/update_offsets.py index ac4bb07..92b7626 100644 --- a/pdfly/update_offsets.py +++ b/pdfly/update_offsets.py @@ -232,8 +232,7 @@ def update_lines( lines_out[len_obj_line] = updated_length + "\n" else: raise RuntimeError( - f"obj {curr_obj} with stream-len {stream_len}" - f" has no object-length-line: {map_obj_length_line}" + f"obj {curr_obj} with stream-len {stream_len} has no object-length-line: {map_obj_length_line}" ) return lines_out @@ -260,7 +259,7 @@ def read_binary_file(file_path: Path, encoding: str) -> List[str]: # Split buffer into chunks based on LF, CR, or CRLF while True: - match = re.search(b"(\x0D\x0A|\x0A|\x0D)", buffer) + match = re.search(b"(\x0d\x0a|\x0a|\x0d)", buffer) if not match: break # No more line breaks found, process the remaining buffer diff --git a/requirements/ci.txt b/requirements/ci.txt index 564460b..eac538c 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -4,76 +4,56 @@ # # pip-compile requirements/ci.in # -aiohttp==3.9.1 - # via black -aiosignal==1.3.1 - # via aiohttp astor==0.8.1 # via flake8-simplify -async-timeout==4.0.3 - # via aiohttp -attrs==23.1.0 - # via - # aiohttp - # flake8-bugbear -black==23.12.0 +attrs==24.2.0 + # via flake8-bugbear +black==24.8.0 # via -r requirements/ci.in click==8.1.7 # via black -flake8==6.1.0 +flake8==7.1.1 # via # -r requirements/ci.in # flake8-bugbear # flake8-comprehensions # flake8-isort # flake8-simplify -flake8-bugbear==23.12.2 +flake8-bugbear==24.10.31 # via -r requirements/ci.in -flake8-comprehensions==3.14.0 +flake8-comprehensions==3.15.0 # via -r requirements/ci.in flake8-isort==6.1.1 # via -r requirements/ci.in flake8-simplify==0.21.0 # via -r requirements/ci.in -frozenlist==1.4.1 - # via - # aiohttp - # aiosignal -idna==3.6 - # via yarl isort==5.13.2 # via flake8-isort mccabe==0.7.0 # via flake8 -multidict==6.0.4 - # via - # aiohttp - # yarl -mypy==1.7.1 +mypy==1.13.0 # via -r requirements/ci.in mypy-extensions==1.0.0 # via # black # mypy -packaging==23.2 +packaging==24.2 # via black pathspec==0.12.1 # via black -platformdirs==4.1.0 +platformdirs==4.3.6 # via black -pycodestyle==2.11.1 +pycodestyle==2.12.1 # via flake8 -pyflakes==3.1.0 +pyflakes==3.2.0 # via flake8 -ruff==0.1.8 +ruff==0.7.4 # via -r requirements/ci.in -tomli==2.0.1 +tomli==2.1.0 # via # black # mypy -typing-extensions==4.9.0 +typing-extensions==4.12.2 # via # black # mypy -yarl==1.9.4 - # via aiohttp diff --git a/requirements/dev.txt b/requirements/dev.txt index 31f5434..fa76740 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -4,137 +4,127 @@ # # pip-compile requirements/dev.in # -aiohttp==3.9.1 - # via black -aiosignal==1.3.1 - # via aiohttp -annotated-types==0.6.0 +annotated-types==0.7.0 # via pydantic -async-timeout==4.0.3 - # via aiohttp -attrs==23.1.0 - # via aiohttp -black==23.12.0 +backports-tarfile==1.2.0 + # via jaraco-context +black==24.8.0 # via -r requirements/dev.in -build==1.0.3 +build==1.2.2.post1 # via pip-tools -certifi==2023.11.17 +certifi==2024.8.30 # via requests -cffi==1.16.0 +cffi==1.17.1 # via cryptography cfgv==3.4.0 # via pre-commit -charset-normalizer==3.3.2 +charset-normalizer==3.4.0 # via requests click==8.1.7 # via # black # pip-tools -coverage[toml]==7.3.3 - # via - # coverage - # pytest-cov -cryptography==41.0.7 +coverage[toml]==7.6.1 + # via pytest-cov +cryptography==43.0.3 # via secretstorage -distlib==0.3.8 +distlib==0.3.9 # via virtualenv docutils==0.20.1 # via readme-renderer -exceptiongroup==1.2.0 +exceptiongroup==1.2.2 # via pytest -filelock==3.13.1 +filelock==3.16.1 # via virtualenv -frozenlist==1.4.1 - # via - # aiohttp - # aiosignal -identify==2.5.33 +identify==2.6.1 # via pre-commit -idna==3.6 - # via - # requests - # yarl -importlib-metadata==7.0.0 +idna==3.10 + # via requests +importlib-metadata==8.5.0 # via # build # keyring # twine -importlib-resources==6.1.1 +importlib-resources==6.4.5 # via keyring iniconfig==2.0.0 # via pytest -jaraco-classes==3.3.0 +jaraco-classes==3.4.0 + # via keyring +jaraco-context==6.0.1 + # via keyring +jaraco-functools==4.1.0 # via keyring jeepney==0.8.0 # via # keyring # secretstorage -keyring==24.3.0 +keyring==25.5.0 # via twine markdown-it-py==3.0.0 # via rich mdurl==0.1.2 # via markdown-it-py -more-itertools==10.1.0 - # via jaraco-classes -multidict==6.0.4 +more-itertools==10.5.0 # via - # aiohttp - # yarl + # jaraco-classes + # jaraco-functools mypy-extensions==1.0.0 # via black -nh3==0.2.15 +nh3==0.2.18 # via readme-renderer -nodeenv==1.8.0 +nodeenv==1.9.1 # via pre-commit -packaging==23.2 +packaging==24.2 # via # black # build # pytest pathspec==0.12.1 # via black -pip-tools==7.3.0 +pip-tools==7.4.1 # via -r requirements/dev.in -pkginfo==1.9.6 +pkginfo==1.10.0 # via twine -platformdirs==4.1.0 +platformdirs==4.3.6 # via # black # virtualenv -pluggy==1.3.0 +pluggy==1.5.0 # via pytest pre-commit==3.5.0 # via -r requirements/dev.in -pycparser==2.21 +pycparser==2.22 # via cffi -pydantic==2.5.2 +pydantic==2.9.2 # via -r requirements/dev.in -pydantic-core==2.14.5 +pydantic-core==2.23.4 # via pydantic -pygments==2.17.2 +pygments==2.18.0 # via # readme-renderer # rich -pyproject-hooks==1.0.0 - # via build -pytest==7.4.3 +pyproject-hooks==1.2.0 + # via + # build + # pip-tools +pytest==8.3.3 # via # -r requirements/dev.in # pytest-cov # pytest-socket # pytest-timeout -pytest-cov==4.1.0 +pytest-cov==5.0.0 # via -r requirements/dev.in -pytest-socket==0.6.0 +pytest-socket==0.7.0 # via -r requirements/dev.in -pytest-timeout==2.2.0 +pytest-timeout==2.3.1 # via -r requirements/dev.in -pyyaml==6.0.1 +pyyaml==6.0.2 # via pre-commit -readme-renderer==42.0 +readme-renderer==43.0 # via twine -requests==2.31.0 +requests==2.32.3 # via # requests-toolbelt # twine @@ -142,42 +132,39 @@ requests-toolbelt==1.0.0 # via twine rfc3986==2.0.0 # via twine -rich==13.7.0 +rich==13.9.4 # via # -r requirements/dev.in # twine secretstorage==3.3.3 # via keyring -tomli==2.0.1 +tomli==2.1.0 # via # black # build # coverage # pip-tools - # pyproject-hooks # pytest -twine==4.0.2 +twine==5.1.1 # via -r requirements/dev.in -typing-extensions==4.9.0 +typing-extensions==4.12.2 # via # annotated-types # black # pydantic # pydantic-core # rich -urllib3==2.1.0 +urllib3==2.2.3 # via # requests # twine -virtualenv==20.25.0 +virtualenv==20.27.1 # via pre-commit -wheel==0.42.0 +wheel==0.45.0 # via # -r requirements/dev.in # pip-tools -yarl==1.9.4 - # via aiohttp -zipp==3.17.0 +zipp==3.20.2 # via # importlib-metadata # importlib-resources diff --git a/requirements/docs.txt b/requirements/docs.txt index 8e1fe43..a67dc54 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -6,26 +6,26 @@ # alabaster==0.7.13 # via sphinx -attrs==23.1.0 +attrs==24.2.0 # via -r requirements/docs.in -babel==2.14.0 +babel==2.16.0 # via sphinx -certifi==2023.11.17 +certifi==2024.8.30 # via requests -charset-normalizer==3.3.2 +charset-normalizer==3.4.0 # via requests docutils==0.17.1 # via # myst-parser # sphinx # sphinx-rtd-theme -idna==3.6 +idna==3.10 # via requests imagesize==1.4.1 # via sphinx -importlib-metadata==7.0.0 +importlib-metadata==8.5.0 # via sphinx -jinja2==3.1.2 +jinja2==3.1.4 # via # myst-parser # sphinx @@ -33,7 +33,7 @@ markdown-it-py==2.2.0 # via # mdit-py-plugins # myst-parser -markupsafe==2.1.3 +markupsafe==2.1.5 # via jinja2 mdit-py-plugins==0.3.5 # via myst-parser @@ -41,15 +41,15 @@ mdurl==0.1.2 # via markdown-it-py myst-parser==0.16.1 # via -r requirements/docs.in -packaging==23.2 +packaging==24.2 # via sphinx -pygments==2.17.2 +pygments==2.18.0 # via sphinx -pytz==2023.3.post1 +pytz==2024.2 # via babel -pyyaml==6.0.1 +pyyaml==6.0.2 # via myst-parser -requests==2.31.0 +requests==2.32.3 # via sphinx snowballstemmer==2.2.0 # via sphinx @@ -75,7 +75,7 @@ sphinxcontrib-qthelp==1.0.3 # via sphinx sphinxcontrib-serializinghtml==1.1.5 # via sphinx -urllib3==2.1.0 +urllib3==2.2.3 # via requests -zipp==3.17.0 +zipp==3.20.2 # via importlib-metadata diff --git a/setup.py b/setup.py index 62a65ee..96353a3 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ """Package pdfly with setuptools.""" + import re from setuptools import find_packages, setup