Skip to content

Commit 788e8b4

Browse files
authored
make maint (#76)
1 parent bff4b8e commit 788e8b4

File tree

12 files changed

+107
-146
lines changed

12 files changed

+107
-146
lines changed

.github/workflows/github-ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
- name: Test with ruff
7474
run: |
7575
echo `ruff --version`
76-
ruff pdfly/
76+
ruff check pdfly/
7777
7878
package:
7979
name: Build & verify package

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
- id: blacken-docs
2929
additional_dependencies: [black==22.1.0]
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
31-
rev: v0.7.2
31+
rev: v0.7.4
3232
hooks:
3333
- id: ruff
3434
args: ['--fix']

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
For a full list see the documentation:
66
https://www.sphinx-doc.org/en/master/usage/configuration.html
77
"""
8+
89
# -- Path setup --------------------------------------------------------------
910

1011
# If extensions (or modules to document with autodoc) are in another directory,

pdfly/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""pdfly is a command line utility for manipulating PDFs and getting information about them."""
2+
23
from ._version import __version__
34

45
__all__ = [

pdfly/cat.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
# All rights reserved. This software is available under a BSD license;
4343
# see https://github.com/py-pdf/pypdf/LICENSE
4444

45-
4645
import os
4746
import sys
4847
import traceback
@@ -71,13 +70,13 @@ def main(
7170
writer = PdfWriter()
7271
in_fs = {}
7372
try:
74-
for filename, page_range in filename_page_ranges: # type: ignore
73+
for filepath, page_range in filename_page_ranges: # type: ignore
7574
if verbose:
76-
print(filename, page_range, file=sys.stderr)
77-
if filename not in in_fs:
78-
in_fs[filename] = open(filename, "rb")
75+
print(filepath, page_range, file=sys.stderr)
76+
if filepath not in in_fs:
77+
in_fs[filepath] = open(filepath, "rb")
7978

80-
reader = PdfReader(in_fs[filename])
79+
reader = PdfReader(in_fs[filepath])
8180
num_pages = len(reader.pages)
8281
start, end, step = page_range.indices(num_pages)
8382
if (
@@ -117,11 +116,11 @@ def parse_filepaths_and_pagerange_args(
117116
fn_pgrgs_l = list(fn_pgrgs)
118117
fn_pgrgs_l.insert(0, str(filename))
119118
filename_page_ranges, invalid_filepaths = [], []
120-
for filename, page_range in parse_filename_page_ranges(fn_pgrgs_l): # type: ignore
121-
if Path(filename).is_file():
122-
filename_page_ranges.append((filename, page_range))
119+
for filepath, page_range in parse_filename_page_ranges(fn_pgrgs_l): # type: ignore
120+
if Path(filepath).is_file():
121+
filename_page_ranges.append((Path(filepath), page_range))
123122
else:
124-
invalid_filepaths.append(str(filename))
123+
invalid_filepaths.append(str(filepath))
125124
if invalid_filepaths:
126125
print(
127126
f"Invalid file path or page range provided: {' '.join(invalid_filepaths)}",

pdfly/cli.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def extract_images(
5757
exists=True,
5858
resolve_path=True,
5959
),
60-
]
60+
],
6161
) -> None:
6262
pdfly.extract_images.main(pdf)
6363

@@ -175,7 +175,7 @@ def extract_text(
175175
exists=True,
176176
resolve_path=True,
177177
),
178-
]
178+
],
179179
) -> None:
180180
"""Extract text from a PDF file."""
181181
from pypdf import PdfReader
@@ -198,7 +198,6 @@ def compress(
198198
output: Annotated[
199199
Path,
200200
typer.Argument(
201-
exists=False,
202201
writable=True,
203202
),
204203
],
@@ -211,18 +210,14 @@ def uncompress(
211210
pdf: Annotated[
212211
Path,
213212
typer.Argument(
214-
exists=True,
215-
file_okay=True,
216213
dir_okay=False,
217-
writable=False,
218-
readable=True,
214+
exists=True,
219215
resolve_path=True,
220216
),
221217
],
222218
output: Annotated[
223219
Path,
224220
typer.Argument(
225-
exists=False,
226221
writable=True,
227222
),
228223
],

pdfly/pagemeta.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def main(pdf: Path, page_index: int, output: OutputOptions) -> None:
5757
)
5858
table.add_row(
5959
"artbox",
60-
f"{meta.artbox}: "
61-
f"with={meta.artbox[2] - meta.artbox[0]} "
62-
f"x height={meta.artbox[3] - meta.artbox[1]}",
60+
f"{meta.artbox}: with={meta.artbox[2] - meta.artbox[0]} x height={meta.artbox[3] - meta.artbox[1]}",
6361
)
6462
table.add_row(
6563
"bleedbox",

pdfly/update_offsets.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ def update_lines(
232232
lines_out[len_obj_line] = updated_length + "\n"
233233
else:
234234
raise RuntimeError(
235-
f"obj {curr_obj} with stream-len {stream_len}"
236-
f" has no object-length-line: {map_obj_length_line}"
235+
f"obj {curr_obj} with stream-len {stream_len} has no object-length-line: {map_obj_length_line}"
237236
)
238237

239238
return lines_out
@@ -260,7 +259,7 @@ def read_binary_file(file_path: Path, encoding: str) -> List[str]:
260259

261260
# Split buffer into chunks based on LF, CR, or CRLF
262261
while True:
263-
match = re.search(b"(\x0D\x0A|\x0A|\x0D)", buffer)
262+
match = re.search(b"(\x0d\x0a|\x0a|\x0d)", buffer)
264263
if not match:
265264
break # No more line breaks found, process the remaining buffer
266265

requirements/ci.txt

+14-34
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,56 @@
44
#
55
# pip-compile requirements/ci.in
66
#
7-
aiohttp==3.9.1
8-
# via black
9-
aiosignal==1.3.1
10-
# via aiohttp
117
astor==0.8.1
128
# via flake8-simplify
13-
async-timeout==4.0.3
14-
# via aiohttp
15-
attrs==23.1.0
16-
# via
17-
# aiohttp
18-
# flake8-bugbear
19-
black==23.12.0
9+
attrs==24.2.0
10+
# via flake8-bugbear
11+
black==24.8.0
2012
# via -r requirements/ci.in
2113
click==8.1.7
2214
# via black
23-
flake8==6.1.0
15+
flake8==7.1.1
2416
# via
2517
# -r requirements/ci.in
2618
# flake8-bugbear
2719
# flake8-comprehensions
2820
# flake8-isort
2921
# flake8-simplify
30-
flake8-bugbear==23.12.2
22+
flake8-bugbear==24.10.31
3123
# via -r requirements/ci.in
32-
flake8-comprehensions==3.14.0
24+
flake8-comprehensions==3.15.0
3325
# via -r requirements/ci.in
3426
flake8-isort==6.1.1
3527
# via -r requirements/ci.in
3628
flake8-simplify==0.21.0
3729
# via -r requirements/ci.in
38-
frozenlist==1.4.1
39-
# via
40-
# aiohttp
41-
# aiosignal
42-
idna==3.6
43-
# via yarl
4430
isort==5.13.2
4531
# via flake8-isort
4632
mccabe==0.7.0
4733
# via flake8
48-
multidict==6.0.4
49-
# via
50-
# aiohttp
51-
# yarl
52-
mypy==1.7.1
34+
mypy==1.13.0
5335
# via -r requirements/ci.in
5436
mypy-extensions==1.0.0
5537
# via
5638
# black
5739
# mypy
58-
packaging==23.2
40+
packaging==24.2
5941
# via black
6042
pathspec==0.12.1
6143
# via black
62-
platformdirs==4.1.0
44+
platformdirs==4.3.6
6345
# via black
64-
pycodestyle==2.11.1
46+
pycodestyle==2.12.1
6547
# via flake8
66-
pyflakes==3.1.0
48+
pyflakes==3.2.0
6749
# via flake8
68-
ruff==0.1.8
50+
ruff==0.7.4
6951
# via -r requirements/ci.in
70-
tomli==2.0.1
52+
tomli==2.1.0
7153
# via
7254
# black
7355
# mypy
74-
typing-extensions==4.9.0
56+
typing-extensions==4.12.2
7557
# via
7658
# black
7759
# mypy
78-
yarl==1.9.4
79-
# via aiohttp

0 commit comments

Comments
 (0)