Skip to content

Commit 5431882

Browse files
authored
Merge branch 'main' into load-from-memview
2 parents c16d9fc + 0a9c2e8 commit 5431882

File tree

11 files changed

+109
-141
lines changed

11 files changed

+109
-141
lines changed

.github/workflows/test_pyodide.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ jobs:
2525

2626
strategy:
2727
matrix:
28-
# 2023-12-22: Python-3.12 is known to fail, due to setuptools trying to
29-
# import distutils.
30-
python-version: ["3.11"]
28+
# Python version needs to match emsdk.
29+
python-version: ["3.12"]
3130

3231
# Avoid cancelling of all runs after a single failure.
3332
fail-fast: false
@@ -53,6 +52,6 @@ jobs:
5352

5453
# Upload generated wheels, to be accessible from github Actions page.
5554
#
56-
- uses: actions/upload-artifact@v3
55+
- uses: actions/upload-artifact@v4
5756
with:
5857
path: ./wheelhouse/*.whl

changes.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Change Log
99
* Fixed issues:
1010

1111
* **Fixed** `4139 <https://github.com/pymupdf/PyMuPDF/issues/4139>`_: Text color numbers change between 1.24.14 and 1.25.0
12-
* **Fixed** `4141 <https://github.com/pymupdf/PyMuPDF/issues/4141>`_: Some insertion methods fails for pages without a /Resouces object
12+
* **Fixed** `4141 <https://github.com/pymupdf/PyMuPDF/issues/4141>`_: Some insertion methods fails for pages without a /Resources object
1313
* **Fixed** `4180 <https://github.com/pymupdf/PyMuPDF/issues/4180>`_: Search problems
1414
* **Fixed** `4182 <https://github.com/pymupdf/PyMuPDF/issues/4182>`_: Text coordinate extraction error
1515
* **Fixed** `4245 <https://github.com/pymupdf/PyMuPDF/issues/4245>`_: Highlighting issue distorted on recent versions
@@ -20,7 +20,7 @@ Change Log
2020
* In annotations:
2121
* Added support for subtype FreeTextCallout.
2222
* Added support for rich text.
23-
* Added miter_limit arg to insert_text*() to allow supression of spikes caused by long miters.
23+
* Added miter_limit arg to insert_text*() to allow suppression of spikes caused by long miters.
2424
* Add Widget Support to `Document.insert_pdf()`.
2525
* Add `bibi` to span dicts.
2626
* Add `synthetic' to char dict.
@@ -68,6 +68,8 @@ Change Log
6868
* **Fixed** `3751 <https://github.com/pymupdf/PyMuPDF/issues/3751>`_: apply_redactions causes part of the page content to be hidden / transparent
6969

7070

71+
.. codespell:ignore-begin
72+
7173
**Changes in version 1.24.14 (2024-11-19)**
7274

7375
* Use MuPDF-1.24.11.
@@ -2624,3 +2626,5 @@ Changes in version 1.9.1 compared to version 1.8.0 are the following:
26242626
* Incremental saves for changes are possible now using the call pattern *doc.save(doc.name, incremental=True)*.
26252627
* A PDF's metadata can now be deleted, set or changed by document method *set_metadata()*. Supports incremental saves.
26262628
* A PDF's bookmarks (or table of contents) can now be deleted, set or changed with the entries of a list using document method *set_toc(list)*. Supports incremental saves.
2629+
2630+
.. codespell:ignore-end

docs/recipes-text.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ This script uses `Page.get_text("words")` to look for a string, handed in via cl
198198

199199
How to Mark Searched Text
200200
~~~~~~~~~~~~~~~~~~~~~~~~~~
201+
202+
.. codespell:ignore-begin
203+
201204
This script searches for text and marks it::
202205

203206
# -*- coding: utf-8 -*-
@@ -222,6 +225,8 @@ This script searches for text and marks it::
222225
# save to a new PDF
223226
doc.save("a-squiggly.pdf")
224227

228+
.. codespell:ignore-end
229+
225230
The result looks like this:
226231

227232
.. image:: images/img-textmarker.*

docs/samples/national-capitals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Table data. Used to populate a temporary SQL database, which will be processed by the script.
2121
Its only purpose is to avoid carrying around a separate database file.
2222
"""
23+
# codespell:ignore-begin
2324
table_data = """China;Beijing;21542000;1.5%;2018
2425
Japan;Tokyo;13921000;11.2%;2019
2526
DR Congo;Kinshasa;12691000;13.2%;2017
@@ -260,6 +261,7 @@
260261
Cocos (Keeling) Islands (Australia);West Island;134;24.6%;2011
261262
Pitcairn Islands (UK);Adamstown;40;100.0%;2021
262263
South Georgia and the South Sandwich Islands (UK);King Edward Point;22;73.3%;2018"""
264+
# codespell:ignore-end
263265

264266
# -------------------------------------------------------------------
265267
# HTML template for the report. We define no table header <th> items

scripts/test.py

Lines changed: 36 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ def build_pyodide_wheel(pyodide_build_version=None):
474474
#
475475
env_extra['PYMUPDF_SETUP_MUPDF_TESSERACT'] = '0'
476476
setup = pyodide_setup(pymupdf_dir, pyodide_build_version=pyodide_build_version)
477-
command = f'{setup} && pyodide build --exports pyinit'
477+
command = f'{setup} && echo "### Running pyodide build" && pyodide build --exports whole_archive'
478+
479+
command = command.replace(' && ', '\n && ')
480+
478481
run(command, env_extra=env_extra)
479482

480483
# Copy wheel into `wheelhouse/` so it is picked up as a workflow
@@ -499,23 +502,32 @@ def pyodide_setup(
499502
clean:
500503
If true we create an entirely new environment. Otherwise
501504
we reuse any existing emsdk repository and venv.
505+
pyodide_build_version:
506+
Version of Python package pyodide-build; if None we use latest
507+
available version.
508+
2025-02-13: pyodide_build_version='0.29.3' works.
509+
510+
The returned command does the following:
502511
503-
* Clone emsdk repository to `pipcl_emsdk` if not already present.
504-
* Create and activate a venv `pipcl_venv_pyodide` if not already present.
512+
* Checkout latest emsdk from https://github.com/emscripten-core/emsdk.git:
513+
* Clone emsdk repository to `emsdk` if not already present.
514+
* Run `git pull -r` inside emsdk checkout.
515+
* Create venv `venv_pyodide_<python_version>` if not already present.
516+
* Activate venv `venv_pyodide_<python_version>`.
505517
* Install/upgrade package `pyodide-build`.
506518
* Run emsdk install scripts and enter emsdk environment.
507-
* Replace emsdk/upstream/bin/wasm-opt
508-
(https://github.com/pyodide/pyodide/issues/4048).
509519
510520
Example usage in a build function:
511521
512-
command = pipcl_wasm.pyodide_setup()
522+
command = pyodide_setup()
513523
command += ' && pyodide build --exports pyinit'
514524
subprocess.run(command, shell=1, check=1)
515525
'''
516526
command = f'cd {directory}'
517527

518-
# Clone emsdk.
528+
# Clone/update emsdk. We always use the latest emsdk with `git pull`.
529+
#
530+
# 2025-02-13: this works: 2514ec738de72cebbba7f4fdba0cf2fabcb779a5
519531
#
520532
dir_emsdk = 'emsdk'
521533
if clean:
@@ -524,106 +536,40 @@ def pyodide_setup(
524536
# important to remove it here.
525537
shutil.rmtree('.pyodide-xbuildenv', ignore_errors=1)
526538
if not os.path.exists(f'{directory}/{dir_emsdk}'):
527-
command += f' && echo "### cloning emsdk.git"'
539+
command += f' && echo "### Cloning emsdk.git"'
528540
command += f' && git clone https://github.com/emscripten-core/emsdk.git {dir_emsdk}'
541+
command += f' && echo "### Updating checkout {dir_emsdk}"'
542+
command += f' && (cd {dir_emsdk} && git pull -r)'
543+
command += f' && echo "### Checkout {dir_emsdk} is:"'
544+
command += f' && (cd {dir_emsdk} && git show -s --oneline)'
529545

530546
# Create and enter Python venv.
531547
#
532-
# 2024-10-11: we only work with python-3.11; later versions fail with
533-
# pyodide-build==0.23.4 because `distutils` not available.
534-
if pyodide_build_version:
535-
python = sys.executable
536-
a, b = sys.version_info[:2]
537-
venv_pyodide = f'venv_pyodide_{a}.{b}'
538-
else:
539-
pyodide_build_version = '0.23.4'
540-
venv_pyodide = 'venv_pyodide_3.11'
541-
python = sys.executable
542-
if sys.version_info[:2] != (3, 11):
543-
log(f'Forcing use of python-3.11 because {sys.version=} is not 3.11.')
544-
python = 'python3.11'
548+
python = sys.executable
549+
venv_pyodide = f'venv_pyodide_{sys.version_info[0]}.{sys.version_info[1]}'
550+
545551
if not os.path.exists( f'{directory}/{venv_pyodide}'):
546-
command += f' && echo "### creating venv {venv_pyodide}"'
552+
command += f' && echo "### Creating venv {venv_pyodide}"'
547553
command += f' && {python} -m venv {venv_pyodide}'
548554
command += f' && . {venv_pyodide}/bin/activate'
549-
command += f' && echo "### running pip install ..."'
550-
command += f' && python -m pip install --upgrade pip wheel pyodide-build=={pyodide_build_version}'
551-
#command += f' && python -m pip install --upgrade pip wheel pyodide-build'
555+
command += f' && echo "### Installing Python packages."'
556+
command += f' && python -m pip install --upgrade pip wheel pyodide-build'
557+
if pyodide_build_version:
558+
command += f'=={pyodide_build_version}'
552559

553560
# Run emsdk install scripts and enter emsdk environment.
554561
#
555562
command += f' && cd {dir_emsdk}'
556563
command += ' && PYODIDE_EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)'
557-
command += ' && echo "### running ./emsdk install"'
564+
command += ' && echo "### PYODIDE_EMSCRIPTEN_VERSION is: $PYODIDE_EMSCRIPTEN_VERSION"'
565+
command += ' && echo "### Running ./emsdk install"'
558566
command += ' && ./emsdk install ${PYODIDE_EMSCRIPTEN_VERSION}'
559-
command += ' && echo "### running ./emsdk activate"'
567+
command += ' && echo "### Running ./emsdk activate"'
560568
command += ' && ./emsdk activate ${PYODIDE_EMSCRIPTEN_VERSION}'
561-
command += ' && echo "### running ./emsdk_env.sh"'
569+
command += ' && echo "### Running ./emsdk_env.sh"'
562570
command += ' && . ./emsdk_env.sh' # Need leading `./` otherwise weird 'Not found' error.
563571

564-
if pyodide_build_version:
565-
command += ' && echo "### Not patching emsdk"'
566-
else:
567-
# Make our returned command replace emsdk/upstream/bin/wasm-opt
568-
# with a script that does nothing, otherwise the linker
569-
# command fails after it has created the output file. See:
570-
# https://github.com/pyodide/pyodide/issues/4048
571-
#
572-
573-
def write( text, path):
574-
with open( path, 'w') as f:
575-
f.write( text)
576-
os.chmod( path, 0o755)
577-
578-
# Create a script that our command runs, that overwrites
579-
# `emsdk/upstream/bin/wasm-opt`, hopefully in a way that is
580-
# idempotent.
581-
#
582-
# The script moves the original wasm-opt to wasm-opt-0.
583-
#
584-
write(
585-
textwrap.dedent('''
586-
#! /usr/bin/env python3
587-
import os
588-
p = 'upstream/bin/wasm-opt'
589-
p0 = 'upstream/bin/wasm-opt-0'
590-
p1 = '../wasm-opt-1'
591-
if os.path.exists( p0):
592-
print(f'### {__file__}: {p0!r} already exists so not overwriting from {p!r}.')
593-
else:
594-
s = os.stat( p)
595-
assert s.st_size > 15000000, f'File smaller ({s.st_size}) than expected: {p!r}'
596-
print(f'### {__file__}: Moving {p!r} -> {p0!r}.')
597-
os.rename( p, p0)
598-
print(f'### {__file__}: Moving {p1!r} -> {p!r}.')
599-
os.rename( p1, p)
600-
'''
601-
).strip(),
602-
f'{directory}/wasm-opt-replace.py',
603-
)
604-
605-
# Create a wasm-opt script that basically does nothing, except
606-
# defers to the original script when run with `--version`.
607-
#
608-
write(
609-
textwrap.dedent('''
610-
#!/usr/bin/env python3
611-
import os
612-
import sys
613-
import subprocess
614-
if sys.argv[1:] == ['--version']:
615-
root = os.path.dirname(__file__)
616-
subprocess.run(f'{root}/wasm-opt-0 --version', shell=1, check=1)
617-
else:
618-
print(f'{__file__}: Doing nothing. {sys.argv=}')
619-
'''
620-
).strip(),
621-
f'{directory}/wasm-opt-1',
622-
)
623-
command += ' && ../wasm-opt-replace.py'
624-
625572
command += ' && cd ..'
626-
627573
return command
628574

629575

src/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18004,7 +18004,16 @@ def final():
1800418004

1800518005
def PDF_NAME(x):
1800618006
assert isinstance(x, str)
18007-
return getattr(mupdf, f'PDF_ENUM_NAME_{x}')
18007+
ret = getattr(mupdf, f'PDF_ENUM_NAME_{x}')
18008+
# Note that we return a (swig proxy for) pdf_obj*, not a mupdf.PdfObj. In
18009+
# the C++ API, the constructor PdfObj::PdfObj(pdf_obj*) is marked as
18010+
# explicit, but this seems to be ignored by SWIG. If SWIG started to
18011+
# generate code that respected `explicit`, we would need to do `return
18012+
# mupdf.PdfObj(ret)`.
18013+
#
18014+
# [Compare with extra.i, where we define our own PDF_NAME2() macro that
18015+
# returns a mupdf::PdfObj.]
18016+
return ret
1800818017

1800918018

1801018019
def UpdateFontInfo(doc: Document, info: typing.Sequence):

0 commit comments

Comments
 (0)