strata-python 0.2.3__py3-none-any.whl → 0.2.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strata_python/oslib.py +9 -3
- strata_python/pages/render.py +10 -2
- {strata_python-0.2.3.dist-info → strata_python-0.2.4.dist-info}/METADATA +1 -1
- {strata_python-0.2.3.dist-info → strata_python-0.2.4.dist-info}/RECORD +7 -7
- {strata_python-0.2.3.dist-info → strata_python-0.2.4.dist-info}/WHEEL +0 -0
- {strata_python-0.2.3.dist-info → strata_python-0.2.4.dist-info}/entry_points.txt +0 -0
- {strata_python-0.2.3.dist-info → strata_python-0.2.4.dist-info}/licenses/LICENSE +0 -0
strata_python/oslib.py
CHANGED
|
@@ -101,8 +101,12 @@ MAC = sys.platform == "darwin"
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
def lower_priority(nice: int = 19, io: bool = False) -> None:
|
|
104
|
-
"""Run this process at lower CPU priority (nice value on POSIX, below-normal/idle class on Windows).
|
|
105
|
-
inherit it. Best effort: a refusal is skipped.
|
|
104
|
+
"""Run this process at lower CPU priority (nice value `nice` on POSIX, below-normal/idle class on Windows).
|
|
105
|
+
Children inherit it. Best effort: a refusal is skipped.
|
|
106
|
+
|
|
107
|
+
`nice` is the value the process ends at, not an increment: it is set absolutely and never lowers the current
|
|
108
|
+
one, so `lower_priority(19)` gives 19 even from a process that starts below 0 (issue #28; `os.nice` adds, so a
|
|
109
|
+
CI runner at -10 ended at 9).
|
|
106
110
|
|
|
107
111
|
`io=True` also lowers its disk priority, for batch jobs that read many large files (hashing an archive, exiftool
|
|
108
112
|
over a folder) and should not slow interactive use of the same disk: the idle I/O class on Linux (children
|
|
@@ -118,7 +122,9 @@ def lower_priority(nice: int = 19, io: bool = False) -> None:
|
|
|
118
122
|
k32.SetPriorityClass(k32.GetCurrentProcess(), 0x00100000) # PROCESS_MODE_BACKGROUND_BEGIN
|
|
119
123
|
return
|
|
120
124
|
with contextlib.suppress(OSError, AttributeError):
|
|
121
|
-
os.
|
|
125
|
+
current = os.getpriority(os.PRIO_PROCESS, 0)
|
|
126
|
+
if nice > current:
|
|
127
|
+
os.setpriority(os.PRIO_PROCESS, 0, nice)
|
|
122
128
|
if io:
|
|
123
129
|
_lower_io_priority()
|
|
124
130
|
|
strata_python/pages/render.py
CHANGED
|
@@ -244,14 +244,22 @@ def page_count(pdf: bytes) -> int:
|
|
|
244
244
|
|
|
245
245
|
|
|
246
246
|
def rasterise(pdf: bytes, page: int = 0, dpi: float = 300.0) -> Image.Image:
|
|
247
|
-
"""One page of a PDF as a greyscale picture at `dpi` (the scan's dpi gives the scan's size in pixels), white paper.
|
|
247
|
+
"""One page of a PDF as a greyscale picture at `dpi` (the scan's dpi gives the scan's size in pixels), white paper.
|
|
248
|
+
|
|
249
|
+
The picture is the page's size in points times `dpi / 72`, rounded to whole pixels. pdfium rounds up, so a scan
|
|
250
|
+
page 2660 px wide at 500 dpi (383.04 pt, stored a hair over) came back 2661 px (issue #27) and an ink comparison
|
|
251
|
+
against the scan had to pad or crop; the sliver of a pixel past the rounded edge is cut off here instead."""
|
|
248
252
|
doc = _document(pdf)
|
|
249
253
|
try:
|
|
250
254
|
if not 0 <= page < len(doc):
|
|
251
255
|
raise PageError(f"no page {page} in a PDF of {len(doc)}")
|
|
252
256
|
p = doc[page]
|
|
253
|
-
|
|
257
|
+
scale = dpi / 72.0
|
|
258
|
+
img = p.render(scale=scale).to_pil().convert("L")
|
|
259
|
+
w, h = round(p.get_width() * scale), round(p.get_height() * scale) # pdfium's sizes already follow /Rotate
|
|
254
260
|
p.close()
|
|
261
|
+
if img.size != (w, h): # pdfium's ceil is at most one pixel over round, so this only ever trims
|
|
262
|
+
img = img.crop((0, 0, min(img.width, w), min(img.height, h)))
|
|
255
263
|
return img
|
|
256
264
|
finally:
|
|
257
265
|
doc.close()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: strata-python
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Common code for Python web server apps: OS helpers, settings, FastAPI serving, CLI commands, test fixtures and the strata-check gate
|
|
5
5
|
Project-URL: Homepage, https://github.com/jburnhams/strata-python
|
|
6
6
|
Project-URL: Source, https://github.com/jburnhams/strata-python
|
|
@@ -5,7 +5,7 @@ strata_python/client.py,sha256=S-cfDQqbO0dJ951TAiFyW2CbkFQkN1OWnUBCYaTO3Lg,7911
|
|
|
5
5
|
strata_python/contracts.py,sha256=g72b9GQt_ZeiShYXhMJzy4hppDz6t124Ik7lEnnM_HA,5813
|
|
6
6
|
strata_python/http_server.py,sha256=64uYWy4zFxughOgtvkssGXMJDZ7jhRj1bxUIfnzte8w,4475
|
|
7
7
|
strata_python/live.py,sha256=kNY6h6gMxBo9l78UoGUIWjcADeZi4eZuAEp0jqDowEE,1215
|
|
8
|
-
strata_python/oslib.py,sha256=
|
|
8
|
+
strata_python/oslib.py,sha256=vfZDUCNZnTjjjB704eoyNXlPFCz2yVR3puFljE0Z1gE,12137
|
|
9
9
|
strata_python/public_check.py,sha256=A0JusSWnwXtaA3sKsRoa4ocM5MNx38Nc49-dymd__3Q,8398
|
|
10
10
|
strata_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
strata_python/pytest_plugin.py,sha256=BaD-XokrX1PMMj0Cqxj9IJTb6EXBp7ozQZ6SSCDumMg,7223
|
|
@@ -32,7 +32,7 @@ strata_python/db/_alembic/env.py,sha256=gXzRn02h59PB_1RaABkaT6GuyuzPQCZh3Z5ml2Jl
|
|
|
32
32
|
strata_python/db/_alembic/script.py.mako,sha256=04kgeBtNMa4cCnG8CfQcKt6P6rnloIfj8wy0u_DBydM,704
|
|
33
33
|
strata_python/pages/__init__.py,sha256=6QsTqJbFiuLCxywt8C0D6nyXRXjpzI1Xoo5u6rK9toQ,665
|
|
34
34
|
strata_python/pages/model.py,sha256=8Skz3eishAZiNHIHzScI0g60wGpH6jZ3vNc0LpMZ4q4,9821
|
|
35
|
-
strata_python/pages/render.py,sha256=
|
|
35
|
+
strata_python/pages/render.py,sha256=Q3_xliHCkDoGKXNLT3KksaYtfNnm0T2-p-7FhOu6loQ,12421
|
|
36
36
|
strata_python/tasks/__init__.py,sha256=q1fIMbB1nD5xrmM6awllA3axrchWJP9Qo0OiudUPj18,1530
|
|
37
37
|
strata_python/tasks/child.py,sha256=1ZpQwlFx0bbNXD5UKmPrlcEogCf-MrPGSOSK8TpqllA,11133
|
|
38
38
|
strata_python/tasks/flight.py,sha256=FjWl7M1Y1qV5Mcr3Qwu6H464sobzpYEjQAKcz_GjPH4,5704
|
|
@@ -41,8 +41,8 @@ strata_python/tasks/queue.py,sha256=b4in3XnplTlapL_ECTs_WYJcittYj3iKz7q_fQ8_HDY,
|
|
|
41
41
|
strata_python/tasks/retry.py,sha256=NztmOf3Q-rl5y3CZlfP1qcDqPT0jOiIDjMfD-MUkr5s,3995
|
|
42
42
|
strata_python/tasks/status.py,sha256=a6QF5u8BzoVJ1S2tynbYzdlkx1TuFlyEUmzxSdIxOiY,7979
|
|
43
43
|
strata_python/tasks/ticker.py,sha256=V6JLWgAGV5sIGeX1vp4t35omuRvvB6AYWv_lzJAq69Y,2860
|
|
44
|
-
strata_python-0.2.
|
|
45
|
-
strata_python-0.2.
|
|
46
|
-
strata_python-0.2.
|
|
47
|
-
strata_python-0.2.
|
|
48
|
-
strata_python-0.2.
|
|
44
|
+
strata_python-0.2.4.dist-info/METADATA,sha256=9MqWkBTQJWbxVbQ1zLi3hSkk82k4IbWK61EmNTQg71c,29135
|
|
45
|
+
strata_python-0.2.4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
46
|
+
strata_python-0.2.4.dist-info/entry_points.txt,sha256=6RVv-uDumVQ-KY2YdvKwd5R3l6P9WQD4kPtPOKKEM-I,256
|
|
47
|
+
strata_python-0.2.4.dist-info/licenses/LICENSE,sha256=9yVMCPoK7unONyTAiDYjMTt3MZPGJ639nWOwxyNsZGg,1066
|
|
48
|
+
strata_python-0.2.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|