diff --git a/.github/workflows/test_mupdf-release-branch.yml b/.github/workflows/test_mupdf-release-branch.yml index db83b9266..0bf1a934a 100644 --- a/.github/workflows/test_mupdf-release-branch.yml +++ b/.github/workflows/test_mupdf-release-branch.yml @@ -27,7 +27,7 @@ jobs: - name: test_mupdf-release-branch env: - inputs_PYMUPDF_SETUP_MUPDF_BUILD: "git:--recursive --depth 1 --shallow-submodules --branch 1.23.x https://github.com/ArtifexSoftware/mupdf.git" + inputs_PYMUPDF_SETUP_MUPDF_BUILD: "git:--recursive --depth 1 --shallow-submodules --branch 1.24.x https://github.com/ArtifexSoftware/mupdf.git" inputs_flavours: "0" inputs_sdist: "0" inputs_wheels_cps: "cp312*" diff --git a/scripts/gh_release.py b/scripts/gh_release.py index 629039e86..395f34b9e 100755 --- a/scripts/gh_release.py +++ b/scripts/gh_release.py @@ -259,18 +259,29 @@ def make_string(*items): log(f'Not running cibuildwheel because CIBW_ARCHS_MACOS is empty string.') return - def env_set(name, value, pass_=False): - assert isinstance( value, str) - if not name.startswith('CIBW'): - assert pass_, f'{name=} {value=}' - env_extra[ name] = value - if pass_ and platform.system() == 'Linux': + def env_pass(name): + ''' + Adds `name` to CIBW_ENVIRONMENT_PASS_LINUX if required to be available + when building wheel with cibuildwheel. + ''' + if platform.system() == 'Linux': v = env_extra.get('CIBW_ENVIRONMENT_PASS_LINUX', '') if v: v += ' ' v += name env_extra['CIBW_ENVIRONMENT_PASS_LINUX'] = v + + def env_set(name, value, pass_=False): + assert isinstance( value, str) + if not name.startswith('CIBW'): + assert pass_, f'{name=} {value=}' + env_extra[ name] = value + if pass_: + env_pass(name) + if os.environ.get('PYMUPDF_SETUP_LIBCLANG'): + env_pass('PYMUPDF_SETUP_LIBCLANG') + env_set('PYMUPDF_SETUP_IMPLEMENTATIONS', inputs_wheels_implementations, pass_=1) if inputs_skeleton: env_set('PYMUPDF_SETUP_SKELETON', inputs_skeleton, pass_=1) diff --git a/scripts/sysinstall.py b/scripts/sysinstall.py index 3677919d2..c1ab557a3 100755 --- a/scripts/sysinstall.py +++ b/scripts/sysinstall.py @@ -206,11 +206,7 @@ def run(command): if pip == 'sudo': print('## Installing Python packages required for building MuPDF and PyMuPDF.') run(f'sudo pip install --upgrade pip') - names = ('' - + test_py.get_pyproject_required(os.path.abspath(f'{__file__}/../../pyproject.toml')) - + ' ' - + test_py.get_pyproject_required(os.path.abspath(f'{mupdf_dir}/pyproject.toml')) - ) + names = test_py.wrap_get_requires_for_build_wheel(f'{__file__}/../..') run(f'sudo pip install {names}') print('## Build and install MuPDF.') @@ -272,6 +268,7 @@ def run(command): # `python -m installer` fails to overwrite existing files. run(f'{sudo}rm -r {p}/site-packages/fitz || true') run(f'{sudo}rm -r {p}/site-packages/PyMuPDF-*.dist-info || true') + run(f'{sudo}rm -r {root_prefix}/bin/pymupdf || true') if pip == 'venv': run(f'{sudo}{venv_name}/bin/python -m installer --destdir {root} --prefix {prefix} {wheel}') else: @@ -339,8 +336,11 @@ def run(command): command = '' if pip == 'venv': command += f'. {test_venv}/bin/activate &&' - command += f' LD_LIBRARY_PATH={root_prefix}/lib PYTHONPATH={pythonpath}' - command += f' pytest -k "not test_color_count and not test_3050" {pymupdf_dir}' + command += f' LD_LIBRARY_PATH={root_prefix}/lib PYTHONPATH={pythonpath} PATH=$PATH:{root_prefix}/bin' + run(f'ls -l {root_prefix}/bin/') + # 2024-03-20: Not sure whether/where `pymupdf` binary is installed, so we + # disable the test_cli* tests. + command += f' pytest -k "not test_color_count and not test_3050 and not test_cli and not test_cli_out" {pymupdf_dir}' run(command) diff --git a/scripts/test.py b/scripts/test.py index c7bfad0a3..dca82d55b 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -440,6 +440,27 @@ def get_pyproject_required(ppt=None): else: assert 0, f'Failed to find "requires" line in {ppt}' +def wrap_get_requires_for_build_wheel(dir_): + ''' + Returns space-separated list of required + packages. Looks at `dir_`/pyproject.toml and calls + `dir_`/setup.py:get_requires_for_build_wheel(). + ''' + dir_abs = os.path.abspath(dir_) + ret = list() + ppt = os.path.join(dir_abs, 'pyproject.toml') + if os.path.exists(ppt): + ret += get_pyproject_required(ppt) + if os.path.exists(os.path.join(dir_abs, 'setup.py')): + sys.path.insert(0, dir_abs) + try: + from setup import get_requires_for_build_wheel as foo + for i in foo(): + ret.append(i) + finally: + del sys.path[0] + return ' '.join(ret) + def log(text): gh_release.log(text, caller=1) diff --git a/setup.py b/setup.py index d07623535..ae54f27fe 100755 --- a/setup.py +++ b/setup.py @@ -68,6 +68,9 @@ Build wheel called `PyMuPDFb` containing only shared libraries that are not specific to a particular Python version - e.g. on Linux this will be `libmupdf.so` and `libmupdfcpp.so`. + + PYMUPDF_SETUP_LIBCLANG + For internal testing. PYMUPDF_SETUP_MUPDF_BUILD If set, overrides location of MuPDF when building PyMuPDF: @@ -1166,7 +1169,11 @@ def get_requires_for_build_wheel(config_settings=None): ''' ret = list() ret.append('setuptools') - if openbsd: + libclang = os.environ.get('PYMUPDF_SETUP_LIBCLANG') + if libclang: + print(f'Overriding to use {libclang=}.') + ret.append(libclang) + elif openbsd: print(f'OpenBSD: libclang not available via pip; assuming `pkg_add py3-llvm`.') elif darwin and platform.machine() == 'arm64': print(f'MacOS/arm64: forcing use of libclang 16.0.6 because 18.1.1 known to fail with `clang.cindex.TranslationUnitLoadError: Error parsing translation unit.`') diff --git a/src_classic/__init__.py b/src_classic/__init__.py index 6cc1a7be0..488a248c2 100644 --- a/src_classic/__init__.py +++ b/src_classic/__init__.py @@ -78,20 +78,6 @@ def v_tuple_to_string(t): mupdf_version_tuple_required_prev = (mupdf_version_tuple_required[0], mupdf_version_tuple_required[1]-1) mupdf_version_tuple_required_next = (mupdf_version_tuple_required[0], mupdf_version_tuple_required[1]+1) -if mupdf_version_tuple[:2] not in ( - mupdf_version_tuple_required_prev[:2], - mupdf_version_tuple_required[:2], - mupdf_version_tuple_required_next[:2], - ): - raise ValueError( - f'MuPDF library {v_tuple_to_string(mupdf_version_tuple)!r} mismatch:' - f' require' - f' {v_tuple_to_string(mupdf_version_tuple_required_prev)!r}' - f' or {v_tuple_to_string(mupdf_version_tuple_required)!r}' - f' or {v_tuple_to_string(mupdf_version_tuple_required_next)!r}' - f'.' - ) - # copy functions in 'utils' to their respective fitz classes import fitz_old.utils from .table import find_tables diff --git a/tests/test_general.py b/tests/test_general.py index 1f2206888..bbbbe0169 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -967,6 +967,7 @@ def check(expect_out, expect_err, message=None, log=None, ): env['PYMUPDF_LOG'] = log if message: env['PYMUPDF_MESSAGE'] = message + print(f'Running `pymupdf internal`. {env.get("PATH")=}.') cp = subprocess.run(f'pymupdf internal', shell=1, check=1, capture_output=1, env=env, text=True) check_lines(expect_out, cp.stdout)