diff --git a/.github/workflows/test-valgrind.yml b/.github/workflows/test-valgrind.yml index 41a61a775..244fcb95a 100644 --- a/.github/workflows/test-valgrind.yml +++ b/.github/workflows/test-valgrind.yml @@ -24,4 +24,4 @@ jobs: - uses: actions/setup-python@v5 - name: valgrind run: - python scripts/test.py ${{matrix.args}} -P 1 --valgrind 1 build test + python scripts/test.py ${{matrix.args}} -P 1 -T valgrind build test diff --git a/scripts/sysinstall.py b/scripts/sysinstall.py index a5f9a42ea..d4f2fc14f 100755 --- a/scripts/sysinstall.py +++ b/scripts/sysinstall.py @@ -235,8 +235,20 @@ def run(command, env_extra=None): if pip == 'sudo': log('## Installing Python packages required for building MuPDF and PyMuPDF.') #run(f'sudo pip install --upgrade pip') # Breaks on Github see: https://github.com/pypa/get-pip/issues/226. + # We need to install psutil and pillow as system packages, otherwise things like `import psutil` + # fail, seemingly because of pip warning: + # + # WARNING: Running pip as the 'root' user can result in broken + # permissions and conflicting behaviour with the system package + # manager. It is recommended to use a virtual environment instead: + # https://pip.pypa.io/warnings/venv + # names = test_py.wrap_get_requires_for_build_wheel(f'{__file__}/../..') + names = names.split(' ') + names = [n for n in names if n not in ('psutil', 'pillow')] + names = ' '.join(names) run(f'sudo pip install {names}') + run(f'sudo apt install python3-psutil python3-pillow') log('## Build and install MuPDF.') command = f'cd {mupdf_dir}' @@ -345,7 +357,7 @@ def run(command): # log('## Run PyMuPDF pytest tests.') def run(command, env_extra=None): - return run_command(command, doit=pytest_do, env_extra=env_extra) + return run_command(command, doit=pytest_do, env_extra=env_extra, caller=1) import gh_release if pip == 'venv': # Create venv. @@ -356,7 +368,11 @@ def run(command, env_extra=None): command += f' && pip install --upgrade {gh_release.test_packages}' run(command) elif pip == 'sudo': - run(f'sudo pip install --upgrade {gh_release.test_packages}') + names = gh_release.test_packages + names = names.split(' ') + names = [n for n in names if n not in ('psutil', 'pillow')] + names = ' '.join(names) + run(f'sudo pip install --upgrade {names}') else: log(f'Not installing packages for testing because {pip=}.') # Run pytest. @@ -403,9 +419,9 @@ def run(command, env_extra=None): run(command, env_extra=dict(PYMUPDF_SYSINSTALL_TEST='1')) -def run_command(command, capture=False, check=True, doit=True, env_extra=None): +def run_command(command, capture=False, check=True, doit=True, env_extra=None, caller=0): if doit: - return pipcl.run(command, capture=capture, check=check, caller=2, env_extra=env_extra) + return pipcl.run(command, capture=capture, check=check, caller=caller+2, env_extra=env_extra) else: log(f'## Would have run: {command}', caller=2) diff --git a/scripts/test.py b/scripts/test.py index 29f5dea84..a6095f40e 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -120,9 +120,23 @@ -m | --mupdf Location of local mupdf/ directory or 'git:...' to be used - when building PyMuPDF. [This sets environment variable - PYMUPDF_SETUP_MUPDF_BUILD, which is used by PyMuPDF/setup.py. If not - specified PyMuPDF will download its default mupdf .tgz.] + when building PyMuPDF. + + This sets environment variable PYMUPDF_SETUP_MUPDF_BUILD, which is used + by PyMuPDF/setup.py. If not specified PyMuPDF will download its default + mupdf .tgz. + + Additionally if starts with ':' we use the remaining text as + the branch name and add https://github.com/ArtifexSoftware/mupdf.git. + + For example: + + -m "git:--branch master https://github.com/ArtifexSoftware/mupdf.git" + -m :master + + -m "git:--branch 1.26.x https://github.com/ArtifexSoftware/mupdf.git" + -m :1.26.x + -M 0|1 --build-mupdf 0|1 @@ -181,8 +195,11 @@ --timeout Sets timeout when running tests. - -T | --pytest-prefix - Use specified prefix when running pytest. E.g. `gdb --args`. + -T + Use specified prefix when running pytest, must be one of: + gdb + helgrind + vagrind -v 0|1|2 0 - do not use a venv. @@ -192,10 +209,6 @@ 2 - Use venv The default is 2. - --valgrind 0|1 - Use valgrind in `test` or `buildtest`. - This will run `sudo apt update` and `sudo apt install valgrind`. - Commands: build @@ -376,12 +389,6 @@ def main(argv): elif arg == '-f': test_fitz = int(next(args)) - elif arg == '--gdb': - _gdb = int(next(args)) - if _gdb == 1: - pytest_prefix = 'gdb' - warnings += f'{arg=} is deprecated, use `-T gdb`.' - elif arg in ('-h', '--help'): show_help = True @@ -395,6 +402,10 @@ def main(argv): _mupdf = next(args) if _mupdf == '-': _mupdf = None + elif _mupdf.startswith(':'): + _branch = _mupdf[1:] + _mupdf = 'git:--branch {_branch} https://github.com/ArtifexSoftware/mupdf.git' + os.environ['PYMUPDF_SETUP_MUPDF_BUILD'] = _mupdf elif _mupdf.startswith('git:') or '://' in _mupdf: os.environ['PYMUPDF_SETUP_MUPDF_BUILD'] = _mupdf else: @@ -439,19 +450,15 @@ def main(argv): elif arg == '--timeout': test_timeout = float(next(args)) - elif arg in ('-T', '--pytest-prefix'): + elif arg == '-T': pytest_prefix = next(args) + assert pytest_prefix in ('gdb', 'helgrind', 'valgrind'), \ + f'Unrecognised {pytest_prefix=}, should be one of: gdb valgrind helgrind.' elif arg == '-v': venv = int(next(args)) assert venv in (0, 1, 2), f'Invalid {venv=} should be 0, 1 or 2.' - elif arg == '--valgrind': - _valgrind = int(next(args)) - if _valgrind == 1: - pytest_prefix = 'valgrind' - warnings += f'{arg=} is deprecated, use `-T _valgrind`.' - elif arg in ('build', 'cibw', 'pyodide', 'test', 'wheel'): commands.append(arg) diff --git a/setup.py b/setup.py index 92792c889..e8c5b2248 100755 --- a/setup.py +++ b/setup.py @@ -807,12 +807,11 @@ def build_mupdf_windows( devenv = os.environ.get('PYMUPDF_SETUP_DEVENV') if not devenv: try: - # Prefer VS-2019 as that is what MuPDF's project/solution files are - # written for. - log(f'Looking for Visual Studio 2019.') - vs = pipcl.wdev.WindowsVS(year=2019) + # Prefer VS-2022 as that is what Github provide in windows-2022. + log(f'Looking for Visual Studio 2022.') + vs = pipcl.wdev.WindowsVS(year=2022) except Exception as e: - log(f'Failed to find VS-2019:\n' + log(f'Failed to find VS-2022:\n' f'{textwrap.indent(traceback.format_exc(), " ")}' ) log(f'Looking for any Visual Studio.')