Skip to content

Commit c0fc8e1

Browse files
setup.py: improve handling of PYMUPDF_SETUP_MUPDF_BUILD when it starts with git:.
We now use pipcl.git_get(), which works much better than the previous code.
1 parent 812e975 commit c0fc8e1

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

setup.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@
8888
Empty string:
8989
Build PyMuPDF with the system MuPDF.
9090
A string starting with 'git:':
91-
Use `git clone` to get a MuPDF checkout. We use the
92-
string in the git clone command; it must contain the git
93-
URL from which to clone, and can also contain other `git
94-
clone` args, for example:
95-
PYMUPDF_SETUP_MUPDF_BUILD="git:--branch master https://github.com/ArtifexSoftware/mupdf.git"
91+
We use `git` commands to clone/update a local MuPDF checkout.
92+
Should match `git:[--branch <branch>][--tag <tag>][<remote>]`.
93+
If <remote> is omitted we use a default.
94+
For example:
95+
PYMUPDF_SETUP_MUPDF_BUILD="git:--branch master"
96+
Passed as <remote> arg to pipcl.git_get().
9697
Otherwise:
9798
Location of mupdf directory.
9899
@@ -425,7 +426,7 @@ def git_patch(directory, patch, hard=False):
425426

426427
mupdf_tgz = os.path.abspath( f'{__file__}/../mupdf.tgz')
427428

428-
def get_mupdf_internal(out, location=None, sha=None, local_tgz=None):
429+
def get_mupdf_internal(out, location=None, local_tgz=None):
429430
'''
430431
Gets MuPDF as either a .tgz or a local directory.
431432
@@ -438,8 +439,6 @@ def get_mupdf_internal(out, location=None, sha=None, local_tgz=None):
438439
If starts with 'git:', should be remote git location.
439440
Otherwise if containing '://' should be URL for .tgz.
440441
Otherwise should path of local mupdf checkout.
441-
sha:
442-
If not None and we use git clone, we checkout this sha.
443442
local_tgz:
444443
If not None, must be local .tgz file.
445444
Returns:
@@ -451,7 +450,7 @@ def get_mupdf_internal(out, location=None, sha=None, local_tgz=None):
451450
default location.
452451
453452
'''
454-
log(f'get_mupdf_internal(): {out=} {location=} {sha=}')
453+
log(f'get_mupdf_internal(): {out=} {location=}')
455454
assert out in ('dir', 'tgz')
456455
if location is None:
457456
location = f'https://mupdf.com/downloads/archive/mupdf-{version_mupdf}-source.tar.gz'
@@ -465,21 +464,15 @@ def get_mupdf_internal(out, location=None, sha=None, local_tgz=None):
465464
if local_tgz:
466465
assert os.path.isfile(local_tgz)
467466
elif location.startswith( 'git:'):
468-
location_git = location[4:]
469467
local_dir = 'mupdf-git'
468+
pipcl.git_get(location, local_dir, default_remote='https://github.com/ArtifexSoftware/mupdf.git')
470469

471-
# Try to update existing checkout.
472-
e = run(f'cd {local_dir} && git pull && git submodule update --init', check=False)
473-
if e:
474-
# No existing git checkout, so do a fresh clone.
475-
_fs_remove(local_dir)
476-
gitargs = location[4:]
477-
run(f'git clone --recursive --depth 1 --shallow-submodules {gitargs} {local_dir}')
478-
479470
# Show sha of checkout.
480-
run( f'cd {local_dir} && git show --pretty=oneline|head -n 1', check=False)
481-
if sha:
482-
run( f'cd {local_dir} && git checkout {sha}')
471+
run(
472+
f'cd {local_dir} && git show --pretty=oneline|head -n 1',
473+
check = False,
474+
prefix = 'mupdf git id: ',
475+
)
483476
elif '://' in location:
484477
# Download .tgz.
485478
local_tgz = os.path.basename( location)

0 commit comments

Comments
 (0)