MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / swig_get

Function swig_get

pipcl.py:3323–3427  ·  view source on GitHub ↗

Returns or a new swig binary. If is true and starts with 'git:' (not Windows), the remaining text is passed to git_get() and we clone/update/build swig, and return the built binary. We default to the main swig repository, branch master, so for example 'git:' w

(swig, quick, swig_local='pipcl-swig-git')

Source from the content-addressed store, hash-verified

3321
3322
3323def swig_get(swig, quick, swig_local='pipcl-swig-git'):
3324 '''
3325 Returns <swig> or a new swig binary.
3326
3327 If <swig> is true and starts with 'git:' (not Windows), the remaining text
3328 is passed to git_get() and we clone/update/build swig, and return the built
3329 binary. We default to the main swig repository, branch master, so for
3330 example 'git:' will return the latest swig from branch master.
3331
3332 Otherwise we simply return <swig>.
3333
3334 Args:
3335 swig:
3336 If starts with 'git:', passed as <text> arg to git_get().
3337 quick:
3338 If true, we do not update/build local checkout if the binary is
3339 already present.
3340 swig_local:
3341 path to use for checkout.
3342 ''&#x27;
3343 if swig and swig.startswith('git:'):
3344 assert platform.system() != 'Windows', f'Cannot build swig on Windows.'
3345 # Note that {swig_local}/install/bin/swig doesn't work on MacOS because
3346 # {swig_local}/INSTALL is a file and the fs is case-insensitive.
3347 swig_binary = f'{swig_local}/install-dir/bin/swig'
3348 if quick and os.path.isfile(swig_binary):
3349 log1(f'{quick=} and {swig_binary=} already exists, so not downloading/building.')
3350 else:
3351 if darwin():
3352 run(f'brew install automake')
3353 run(f'brew install pcre2')
3354 run(f'brew install bison')
3355 # Default bison doesn't work, and Brew's bison is not added to $PATH.
3356 #
3357 # > bison is keg-only, which means it was not symlinked into /opt/homebrew,
3358 # > because macOS already provides this software and installing another version in
3359 # > parallel can cause all kinds of trouble.
3360 # >
3361 # > If you need to have bison first in your PATH, run:
3362 # > echo 'export PATH="/opt/homebrew/opt/bison/bin:$PATH"' >> ~/.zshrc
3363 #
3364 swig_env_extra = dict()
3365 macos_add_brew_path('bison', swig_env_extra)
3366 run(f'which bison')
3367 run(f'which bison', env_extra=swig_env_extra)
3368
3369 # Building swig requires bison>=3.5.
3370 bison_ok = 0
3371 e, text = run(f'bison --version', capture=1, check=0, env_extra=swig_env_extra)
3372 if not e:
3373 log(textwrap.indent(text, ' '))
3374 m = re.search('bison (GNU Bison) ([0-9]+)[.]([0-9]+)', text)
3375 if m:
3376 assert m, f'Unexpected output from `bison --version`: {text!r}'
3377 version_tuple = int(m.group(1)), int(m.group2())
3378 if version_tuple >= (3, 5):
3379 bison_ok = 1
3380 if not bison_ok:

Callers

nothing calls this directly

Calls 7

log1Function · 0.85
darwinFunction · 0.85
macos_add_brew_pathFunction · 0.85
git_getFunction · 0.85
searchMethod · 0.80
runFunction · 0.70
logFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…