MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / venv

Function venv

scripts/gh_release.py:509–559  ·  view source on GitHub ↗

Runs remaining args, or the specified command if present, in a venv. command: Command as string or list of args. Should usually start with 'python' to run the venv's python. packages: List of packages (or comma-separated string) to install. quick:

( command=None, packages=None, quick=False, system_site_packages=False)

Source from the content-addressed store, hash-verified

507venv_name = f'venv-pymupdf-{platform.python_version()}-{cpu_bits()}'
508
509def venv( command=None, packages=None, quick=False, system_site_packages=False):
510 '''
511 Runs remaining args, or the specified command if present, in a venv.
512
513 command:
514 Command as string or list of args. Should usually start with 'python'
515 to run the venv's python.
516 packages:
517 List of packages (or comma-separated string) to install.
518 quick:
519 If true and venv directory already exists, we don't recreate venv or
520 install Python packages in it.
521 '''
522 command2 = ''
523 if platform.system() == 'OpenBSD':
524 # libclang not available from pypi.org, but system py3-llvm package
525 # works. `pip install` should be run with --no-build-isolation and
526 # explicit `pip install swig psutil`.
527 system_site_packages = True
528 #ssp = ' --system-site-packages'
529 log(f'OpenBSD: libclang not available from pypi.org.')
530 log(f'OpenBSD: system package `py3-llvm` must be installed.')
531 log(f'OpenBSD: creating venv with --system-site-packages.')
532 log(f'OpenBSD: `pip install .../PyMuPDF` must be preceded by install of swig etc.')
533 ssp = ' --system-site-packages' if system_site_packages else ''
534 if quick and os.path.isdir(venv_name):
535 log(f'{quick=}: Not creating venv because directory already exists: {venv_name}')
536 command2 += 'true'
537 else:
538 quick = False
539 command2 += f'{sys.executable} -m venv{ssp} {venv_name}'
540 if platform.system() == 'Windows':
541 command2 += f' && {venv_name}\\Scripts\\activate'
542 else:
543 command2 += f' && . {venv_name}/bin/activate'
544 if quick:
545 log(f'{quick=}: Not upgrading pip or installing packages.')
546 else:
547 command2 += ' && python -m pip install --upgrade pip'
548 if packages:
549 if isinstance(packages, str):
550 packages = packages.split(',')
551 command2 += ' && pip install ' + ' '.join(packages)
552 command2 += ' &&'
553 if isinstance( command, str):
554 command2 += ' ' + command
555 else:
556 for arg in command:
557 command2 += ' ' + shlex.quote(arg)
558
559 run( command2)
560
561
562def test( project, package, valgrind):

Callers 1

mainFunction · 0.85

Calls 2

runFunction · 0.70
logFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…