Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make maint #76

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/github-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Test with ruff
run: |
echo `ruff --version`
ruff pdfly/
ruff check pdfly/

package:
name: Build & verify package
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pdfly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""pdfly is a command line utility for manipulating PDFs and getting information about them."""

from ._version import __version__

__all__ = [
Expand Down
19 changes: 9 additions & 10 deletions pdfly/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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)}",
Expand Down
11 changes: 3 additions & 8 deletions pdfly/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def extract_images(
exists=True,
resolve_path=True,
),
]
],
) -> None:
pdfly.extract_images.main(pdf)

Expand Down Expand Up @@ -175,7 +175,7 @@ def extract_text(
exists=True,
resolve_path=True,
),
]
],
) -> None:
"""Extract text from a PDF file."""
from pypdf import PdfReader
Expand All @@ -198,7 +198,6 @@ def compress(
output: Annotated[
Path,
typer.Argument(
exists=False,
writable=True,
),
],
Expand All @@ -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,
),
],
Expand Down
4 changes: 1 addition & 3 deletions pdfly/pagemeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions pdfly/update_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
48 changes: 14 additions & 34 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading
Loading