Skip to content

Commit 521f371

Browse files
setup.py: Allow PYMUPDF_SETUP_MUPDF_BUILD to specify git clone of mupdf.
This is to support automated regular testing with latest MuPDF.
1 parent 1889a2a commit 521f371

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

setup.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
If set, overrides location of mupdf when building PyMuPDF:
2727
Empty string:
2828
Build PyMuPDF with the system mupdf.
29+
A string starting with 'git:':
30+
Use `git clone` to get a mupdf directory. We use the string in
31+
the git clone command; it must contain the git URL from which
32+
to clone, and can also contain other `git clone` args, for
33+
example:
34+
PYMUPDF_SETUP_MUPDF_BUILD="git:--branch master https://github.com/ArtifexSoftware/mupdf.git"
2935
Otherwise:
3036
Location of mupdf directory.
3137
@@ -454,7 +460,40 @@ def get_mupdf():
454460
log( f'PYMUPDF_SETUP_MUPDF_BUILD="", using system mupdf')
455461
return None
456462

457-
else:
463+
git_prefix = 'git:'
464+
if path.startswith( git_prefix):
465+
# Get git clone of mupdf.
466+
#
467+
# `mupdf_url_or_local` is taken to be portion of a `git clone` command,
468+
# for example:
469+
#
470+
# PYMUPDF_SETUP_MUPDF_BUILD="git:--branch master git://git.ghostscript.com/mupdf.git"
471+
# PYMUPDF_SETUP_MUPDF_BUILD="git:--branch 1.20.x https://github.com/ArtifexSoftware/mupdf.git"
472+
# PYMUPDF_SETUP_MUPDF_BUILD="git:--branch master https://github.com/ArtifexSoftware/mupdf.git"
473+
#
474+
# One would usually also set PYMUPDF_SETUP_MUPDF_TGZ= (empty string) to
475+
# avoid the need to download a .tgz into an sdist.
476+
#
477+
command_suffix = path[ len(git_prefix):]
478+
path = 'mupdf'
479+
assert not os.path.exists( path), \
480+
f'Cannot use git clone because local directory already exists: {path}'
481+
command = (''
482+
+ f'git clone'
483+
+ f' --recursive'
484+
#+ f' --single-branch'
485+
#+ f' --recurse-submodules'
486+
+ f' --depth 1'
487+
+ f' --shallow-submodules'
488+
#+ f' --branch {branch}'
489+
#+ f' git://git.ghostscript.com/mupdf.git'
490+
+ f' {command_suffix}'
491+
+ f' {path}'
492+
)
493+
log( f'Running: {command}')
494+
subprocess.run( command, shell=True, check=True)
495+
496+
if 1:
458497
# Use custom mupdf directory.
459498
log( f'Using custom mupdf directory from $PYMUPDF_SETUP_MUPDF_BUILD: {path}')
460499
assert os.path.isdir( path), f'$PYMUPDF_SETUP_MUPDF_BUILD is not a directory: {path}'

0 commit comments

Comments
 (0)