Skip to content

Commit aebb0b1

Browse files
setup.py src/ tests/: Removed support for mupdf-1.24.
1 parent 106c4a5 commit aebb0b1

14 files changed

+43
-159
lines changed

setup.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,7 @@ def add(flavour, from_, to_):
700700
add('p', f'{mupdf_build_dir}/_mupdf.so', to_dir)
701701
add('b', f'{mupdf_build_dir}/libmupdfcpp.so', to_dir)
702702
add('b', f'{mupdf_build_dir}/libmupdf.dylib', to_dir)
703-
if mupdf_version_tuple >= (1, 25):
704-
# MuPDF-1.25+ language bindings build also builds
705-
# libmupdf-threads.a.
706-
add('d', f'{mupdf_build_dir}/libmupdf-threads.a', f'{to_dir_d}/lib/')
703+
add('d', f'{mupdf_build_dir}/libmupdf-threads.a', f'{to_dir_d}/lib/')
707704
elif pyodide:
708705
add('p', f'{mupdf_build_dir}/_mupdf.so', to_dir)
709706
add('b', f'{mupdf_build_dir}/libmupdfcpp.so', 'PyMuPDF.libs/')
@@ -712,10 +709,7 @@ def add(flavour, from_, to_):
712709
add('p', f'{mupdf_build_dir}/_mupdf.so', to_dir)
713710
add('b', pipcl.get_soname(f'{mupdf_build_dir}/libmupdfcpp.so'), to_dir)
714711
add('b', pipcl.get_soname(f'{mupdf_build_dir}/libmupdf.so'), to_dir)
715-
if mupdf_version_tuple >= (1, 25):
716-
# MuPDF-1.25+ language bindings build also builds
717-
# libmupdf-threads.a.
718-
add('d', f'{mupdf_build_dir}/libmupdf-threads.a', f'{to_dir_d}/lib/')
712+
add('d', f'{mupdf_build_dir}/libmupdf-threads.a', f'{to_dir_d}/lib/')
719713

720714
if 'd' in PYMUPDF_SETUP_FLAVOUR:
721715
# Add MuPDF C and C++ headers to `ret_d`. Would prefer to use
@@ -802,10 +796,7 @@ def build_mupdf_windows(
802796
tesseract = '' if os.environ.get('PYMUPDF_SETUP_MUPDF_TESSERACT') == '0' else 'tesseract-'
803797
windows_build_tail = f'build\\shared-{tesseract}{build_type}'
804798
if g_py_limited_api:
805-
if get_mupdf_version(mupdf_local) >= (1, 24, 11):
806-
windows_build_tail += f'-Py_LIMITED_API_{pipcl.current_py_limited_api()}'
807-
else:
808-
windows_build_tail += f'-Py_LIMITED_API={pipcl.current_py_limited_api()}'
799+
windows_build_tail += f'-Py_LIMITED_API_{pipcl.current_py_limited_api()}'
809800
windows_build_tail += f'-x{wp.cpu.bits}-py{wp.version}'
810801
windows_build_dir = f'{mupdf_local}\\{windows_build_tail}'
811802
#log( f'Building mupdf.')
@@ -982,16 +973,12 @@ def build_mupdf_unix(
982973
if (
983974
linux
984975
and os.environ.get('PYMUPDF_SETUP_MUPDF_BSYMBOLIC', '1') == '1'
985-
and mupdf_version_tuple >= (1, 24, 3)
986976
):
987977
log(f'Appending `bsymbolic-` to MuPDF build path.')
988978
build_prefix += 'bsymbolic-'
989979
log(f'{g_py_limited_api=}')
990980
if g_py_limited_api:
991-
if get_mupdf_version(mupdf_local) >= (1, 24, 11):
992-
build_prefix += f'Py_LIMITED_API_{pipcl.current_py_limited_api()}-'
993-
else:
994-
build_prefix += f'Py_LIMITED_API={pipcl.current_py_limited_api()}-'
981+
build_prefix += f'Py_LIMITED_API_{pipcl.current_py_limited_api()}-'
995982
unix_build_dir = f'{mupdf_local}/build/{build_prefix}{build_type}'
996983
# We need MuPDF's Python bindings, so we build MuPDF with
997984
# `mupdf/scripts/mupdfwrap.py` instead of running `make`.

src/__init__.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,7 @@ def _format_g(value, *, fmt='%g'):
414414
ret += _format_g(v, fmt=fmt)
415415
return ret
416416
else:
417-
if mupdf_version_tuple >= (1, 24, 2):
418-
return mupdf.fz_format_double(fmt, value)
419-
else:
420-
return fmt % value
417+
return mupdf.fz_format_double(fmt, value)
421418

422419
format_g = _format_g
423420

@@ -6415,9 +6412,6 @@ def valid_codepoints(self):
64156412
'''
64166413
Returns sorted list of valid unicodes of a fz_font.
64176414
'''
6418-
if mupdf_version_tuple < (1, 24, 11):
6419-
# mupdf.fz_enumerate_font_cmap2() not available.
6420-
return []
64216415
ucs_gids = mupdf.fz_enumerate_font_cmap2(self.this)
64226416
ucss = [i.ucs for i in ucs_gids]
64236417
ucss_unique = set(ucss)
@@ -13474,18 +13468,11 @@ def width(self):
1347413468
TEXT_PRESERVE_SPANS = mupdf.FZ_STEXT_PRESERVE_SPANS
1347513469
TEXT_MEDIABOX_CLIP = mupdf.FZ_STEXT_MEDIABOX_CLIP
1347613470
TEXT_CID_FOR_UNKNOWN_UNICODE = mupdf.FZ_STEXT_USE_CID_FOR_UNKNOWN_UNICODE
13477-
if mupdf_version_tuple >= (1, 25):
13478-
TEXT_COLLECT_STRUCTURE = mupdf.FZ_STEXT_COLLECT_STRUCTURE
13479-
TEXT_ACCURATE_BBOXES = mupdf.FZ_STEXT_ACCURATE_BBOXES
13480-
TEXT_COLLECT_VECTORS = mupdf.FZ_STEXT_COLLECT_VECTORS
13481-
TEXT_IGNORE_ACTUALTEXT = mupdf.FZ_STEXT_IGNORE_ACTUALTEXT
13482-
TEXT_STEXT_SEGMENT = mupdf.FZ_STEXT_SEGMENT
13483-
else:
13484-
TEXT_COLLECT_STRUCTURE = 256
13485-
TEXT_ACCURATE_BBOXES = 512
13486-
TEXT_COLLECT_VECTORS = 1024
13487-
TEXT_IGNORE_ACTUALTEXT = 2048
13488-
TEXT_STEXT_SEGMENT = 4096
13471+
TEXT_COLLECT_STRUCTURE = mupdf.FZ_STEXT_COLLECT_STRUCTURE
13472+
TEXT_ACCURATE_BBOXES = mupdf.FZ_STEXT_ACCURATE_BBOXES
13473+
TEXT_COLLECT_VECTORS = mupdf.FZ_STEXT_COLLECT_VECTORS
13474+
TEXT_IGNORE_ACTUALTEXT = mupdf.FZ_STEXT_IGNORE_ACTUALTEXT
13475+
TEXT_STEXT_SEGMENT = mupdf.FZ_STEXT_SEGMENT
1348913476

1349013477
TEXTFLAGS_WORDS = (0
1349113478
| TEXT_PRESERVE_LIGATURES
@@ -16458,10 +16445,7 @@ def __str__(self):
1645816445
# FZ_STEXT_SYNTHETIC is per-char, not per-span.
1645916446
style.char_flags = ch.m_internal.flags & ~mupdf.FZ_STEXT_SYNTHETIC
1646016447
style.font = JM_font_name(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
16461-
if mupdf_version_tuple >= (1, 25):
16462-
style.argb = ch.m_internal.argb
16463-
else:
16464-
style.argb = ch.m_internal.color
16448+
style.argb = ch.m_internal.argb
1646516449
style.asc = JM_font_ascender(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
1646616450
style.desc = JM_font_descender(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
1646716451
style.bidi = ch.m_internal.bidi

tests/test_2548.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ def test_2548():
3232
# This checks that PyMuPDF 1.23.7 fixes this bug, and also that earlier
3333
# versions with updated MuPDF also fix the bug.
3434
rebased = hasattr(pymupdf, 'mupdf')
35-
if pymupdf.mupdf_version_tuple >= (1, 25):
36-
expected = 'format error: cycle in structure tree\nstructure tree broken, assume tree is missing'
37-
else:
38-
expected = 'Loop found in structure tree. Ignoring structure.'
35+
expected = 'format error: cycle in structure tree\nstructure tree broken, assume tree is missing'
3936
if rebased:
4037
assert wt == expected, f'expected:\n {expected!r}\nwt:\n {wt!r}\n'
4138
assert not e

tests/test_2907.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,3 @@ def test_2907():
1616
pdf_pages = list(fitz_document.pages())
1717
(page,) = pdf_pages
1818
page.clean_contents()
19-
if pymupdf.mupdf_version_tuple < (1, 24, 2):
20-
# We expect 'dropping unclosed PDF processor' warnings.
21-
wt = pymupdf.TOOLS.mupdf_warnings()
22-
assert wt

tests/test_annots.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,7 @@ def test_redact2():
193193
page.add_redact_annot(page.rect)
194194
page.apply_redactions(text=1)
195195
t = page.get_text("words")
196-
if pymupdf.mupdf_version_tuple < (1, 24, 2):
197-
assert t == []
198-
else:
199-
assert t == all_text0
196+
assert t == all_text0
200197
assert not page.get_drawings()
201198

202199

@@ -390,10 +387,6 @@ def test_3209():
390387
pdf.save(path) # Check the output PDF that the annotation is correctly drawn
391388

392389
def test_3863():
393-
if pymupdf.mupdf_version_tuple < (1, 24, 10):
394-
print(f'test_3863(): not running because {pymupdf.mupdf_version_tuple=} < 1.24.10.')
395-
return
396-
397390
path_in = os.path.normpath(f'{__file__}/../../tests/resources/test_3863.pdf')
398391
path_out = os.path.normpath(f'{__file__}/../../tests/test_3863.pdf.pdf')
399392

@@ -470,15 +463,11 @@ def test_parent():
470463
try:
471464
print(a) # should raise
472465
except Exception as e:
473-
if pymupdf.mupdf_version_tuple >= (1, 25):
474-
if platform.system() == 'OpenBSD':
475-
assert isinstance(e, pymupdf.mupdf.FzErrorBase), f'Incorrect {type(e)=}.'
476-
else:
477-
assert isinstance(e, pymupdf.mupdf.FzErrorArgument), f'Incorrect {type(e)=}.'
478-
assert str(e) == 'code=4: annotation not bound to any page', f'Incorrect error text {str(e)=}.'
466+
if platform.system() == 'OpenBSD':
467+
assert isinstance(e, pymupdf.mupdf.FzErrorBase), f'Incorrect {type(e)=}.'
479468
else:
480-
assert isinstance(e, ReferenceError)
481-
assert str(e) == 'weakly-referenced object no longer exists'
469+
assert isinstance(e, pymupdf.mupdf.FzErrorArgument), f'Incorrect {type(e)=}.'
470+
assert str(e) == 'code=4: annotation not bound to any page', f'Incorrect error text {str(e)=}.'
482471
else:
483472
assert 0, f'Failed to get expected exception.'
484473

tests/test_balance_count.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ def test_q_count():
2222
# Although counts of q and Q are equal now, the unshielded 'cm' before
2323
# the first 'q' makes the contents unusable for insertions.
2424
pymupdf.TOOLS._insert_contents(page, b"1 0 0 -1 0 0 cm q ", False) # prepend
25-
if pymupdf.mupdf_version_tuple >= (1, 24, 2):
26-
assert page.is_wrapped is False
27-
else:
28-
assert page.is_wrapped
25+
assert page.is_wrapped is False
2926
if page._count_q_balance() == (0, 0):
3027
print("imbalance undetected by q balance count")
3128

tests/test_font.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ def test_3933():
171171
font = pymupdf.Font(fontname=name, fontbuffer=content)
172172
supported_symbols = font.valid_codepoints()
173173
print(f'Font {name}: {len(supported_symbols)=}.', flush=1)
174-
if pymupdf.mupdf_version_tuple < (1, 24, 11):
175-
assert len(supported_symbols) == 0
176-
else:
177-
assert len(supported_symbols) == expected.get(name)
174+
assert len(supported_symbols) == expected.get(name)
178175

179176

180177
def test_3780():

tests/test_general.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -895,14 +895,12 @@ def test_bboxlog_2885():
895895
page=doc[0]
896896

897897
bbl = page.get_bboxlog()
898-
if pymupdf.mupdf_version_tuple >= (1, 24, 9):
899-
wt = pymupdf.TOOLS.mupdf_warnings()
900-
assert wt == 'invalid marked content and clip nesting'
898+
wt = pymupdf.TOOLS.mupdf_warnings()
899+
assert wt == 'invalid marked content and clip nesting'
901900

902901
bbl = page.get_bboxlog(layers=True)
903-
if pymupdf.mupdf_version_tuple >= (1, 24, 9):
904-
wt = pymupdf.TOOLS.mupdf_warnings()
905-
assert wt == 'invalid marked content and clip nesting'
902+
wt = pymupdf.TOOLS.mupdf_warnings()
903+
assert wt == 'invalid marked content and clip nesting'
906904

907905
def test_3081():
908906
'''
@@ -1591,10 +1589,7 @@ def test_scientific_numbers():
15911589
page.insert_text(point, "Test")
15921590
contents = page.read_contents()
15931591
print(f'{contents=}')
1594-
if pymupdf.mupdf_version_tuple >= (1, 24, 2):
1595-
assert b" 1e-" not in contents
1596-
else:
1597-
assert b" 1e-" in contents
1592+
assert b" 1e-" not in contents
15981593

15991594
def test_3615():
16001595
print('')
@@ -1614,16 +1609,8 @@ def test_3654():
16141609
for page in document:
16151610
content += page.get_text() + '\n\n'
16161611
content = content.strip()
1617-
1618-
if pymupdf.mupdf_version_tuple < (1, 25):
1619-
# As of 2024-07-04 we get a warning for this input file.
1620-
wt = pymupdf.TOOLS.mupdf_warnings()
1621-
assert wt == 'dropping unclosed output'
16221612

16231613
def test_3727():
1624-
if pymupdf.mupdf_version_tuple < (1, 24, 9):
1625-
print('test_3727(): not running because known to segv: {pymupdf.mupdf_version=}')
1626-
return
16271614
path = os.path.normpath(f'{__file__}/../../tests/resources/test_3727.pdf')
16281615
doc = pymupdf.open(path)
16291616
for page in doc:
@@ -1681,17 +1668,14 @@ def test_3450():
16811668
print(f'test_3450(): {t=}')
16821669

16831670
def test_3859():
1684-
if pymupdf.mupdf_version_tuple > (1, 24, 9):
1685-
print(f'{pymupdf.mupdf.PDF_NULL=}.')
1686-
print(f'{pymupdf.mupdf.PDF_TRUE=}.')
1687-
print(f'{pymupdf.mupdf.PDF_FALSE=}.')
1688-
for name in ('NULL', 'TRUE', 'FALSE'):
1689-
name2 = f'PDF_{name}'
1690-
v = getattr(pymupdf.mupdf, name2)
1691-
print(f'{name=} {name2=} {v=} {type(v)=}')
1692-
assert type(v)==pymupdf.mupdf.PdfObj, f'`v` is not a pymupdf.mupdf.PdfObj.'
1693-
else:
1694-
assert not hasattr(pymupdf.mupdf, 'PDF_TRUE')
1671+
print(f'{pymupdf.mupdf.PDF_NULL=}.')
1672+
print(f'{pymupdf.mupdf.PDF_TRUE=}.')
1673+
print(f'{pymupdf.mupdf.PDF_FALSE=}.')
1674+
for name in ('NULL', 'TRUE', 'FALSE'):
1675+
name2 = f'PDF_{name}'
1676+
v = getattr(pymupdf.mupdf, name2)
1677+
print(f'{name=} {name2=} {v=} {type(v)=}')
1678+
assert type(v)==pymupdf.mupdf.PdfObj, f'`v` is not a pymupdf.mupdf.PdfObj.'
16951679

16961680
def test_3905():
16971681
data = b'A,B,C,D\r\n1,2,1,2\r\n2,2,1,2\r\n'
@@ -1717,12 +1701,9 @@ def test_3624():
17171701
print(f'Saving to {path_png=}.')
17181702
pixmap.save(path_png)
17191703
rms = gentle_compare.pixmaps_rms(path_png_expected, path_png)
1720-
if pymupdf.mupdf_version_tuple < (1, 24, 10):
1721-
assert rms > 12
1722-
else:
1723-
# We get small differences in sysinstall tests, where some
1724-
# thirdparty libraries can differ.
1725-
assert rms < 1
1704+
# We get small differences in sysinstall tests, where some thirdparty
1705+
# libraries can differ.
1706+
assert rms < 1
17261707

17271708

17281709
def test_4043():

tests/test_mupdf_regressions.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ def test_707673():
3131
page.clean_contents(sanitize=True)
3232
words1 = page.get_text("words")
3333
ok = gentle_compare.gentle_compare(words0, words1)
34-
if pymupdf.mupdf_version_tuple >= (1, 24, 1):
35-
assert ok
36-
else:
37-
assert not ok
34+
assert ok
3835

3936

4037
def test_707727():
@@ -56,27 +53,15 @@ def test_707727():
5653
if pymupdf.mupdf_version_tuple >= (1, 25, 2):
5754
# New sanitising gives small fp rounding errors.
5855
assert rms < 0.05
59-
elif pymupdf.mupdf_version_tuple > (1, 24, 1):
60-
assert rms == 0
6156
else:
62-
assert rms != 0
63-
if pymupdf.mupdf_version_tuple <= (1, 24, 1):
64-
# We expect warnings.
65-
wt = pymupdf.TOOLS.mupdf_warnings()
66-
print(f"{wt=}")
67-
assert wt
57+
assert rms == 0
6858

6959

7060
def test_707721():
7161
"""Confirm text extraction works for nested MCID with Type 3 fonts.
7262
PyMuPDF issue https://github.com/pymupdf/PyMuPDF/issues/3357
7363
MuPDF issue: https://bugs.ghostscript.com/show_bug.cgi?id=707721
7464
"""
75-
if pymupdf.mupdf_version_tuple < (1, 24, 2):
76-
print(
77-
"test_707721(): not running because MuPDF-{pymupdf.mupdf_version} known to hang."
78-
)
79-
return
8065
filename = os.path.join(scriptdir, "resources", "test_3357.pdf")
8166
doc = pymupdf.open(filename)
8267
page = doc[0]
@@ -110,7 +95,4 @@ def test_3376():
11095
words1 = page.get_text("words", sort=True)
11196

11297
ok = gentle_compare.gentle_compare(words0_e, words1)
113-
if pymupdf.mupdf_version_tuple >= (1, 24, 2):
114-
assert ok
115-
else:
116-
assert not ok
98+
assert ok

tests/test_pixmap.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,7 @@ def do(gi):
366366
out1 = do(1)
367367
out2 = do(2)
368368
print(f'{len(out0)=} {len(out1)=} {len(out2)=}.')
369-
if pymupdf.mupdf_version_tuple >= (1, 24, 3):
370-
assert out1 == out0
371-
else:
372-
assert out1 != out0
369+
assert out1 == out0
373370
assert out2 == out0
374371

375372

@@ -417,9 +414,7 @@ def test_3448():
417414
path_diff = os.path.normpath(f'{__file__}/../../tests/test_3448-diff.png')
418415
diff.save(path_diff)
419416
print(f'{rms=}')
420-
if pymupdf.mupdf_version_tuple < (1, 24, 11):
421-
assert 30 <= rms < 45
422-
elif pymupdf.mupdf_version_tuple < (1, 25, 5):
417+
if pymupdf.mupdf_version_tuple < (1, 25, 5):
423418
# Prior to fix for mupdf bug 708274.
424419
assert 1 < rms < 2
425420
else:

0 commit comments

Comments
 (0)