File size: 2,173 Bytes
25c6e75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""Install the bundled wheel into a project-local virtual environment."""
import argparse
import os
from pathlib import Path
import subprocess
import sys


def main():
    if sys.version_info < (3, 10):
        print('Python 3.10 or newer is required.', file=sys.stderr)
        return 2
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--fast', action='store_true', help='install optional NumPy filter (may require network)')
    parser.add_argument('--no-demo', action='store_true', help='install and run doctor only')
    args = parser.parse_args()
    root = Path(__file__).resolve().parents[1]
    version = (root / 'VERSION').read_text().strip()
    wheels = list((root / 'wheels').glob(f'qyxo_zhaenivoth_guard-{version}-*.whl'))
    if len(wheels) != 1:
        print('Expected one bundled release wheel; use python -m pip install . instead.', file=sys.stderr)
        return 2
    environment = root / '.venv'
    python = environment / ('Scripts/python.exe' if os.name == 'nt' else 'bin/python')
    try:
        if not python.is_file():
            subprocess.run([sys.executable, '-m', 'venv', str(environment)], check=True)
        install = [str(python), '-m', 'pip', 'install']
        if args.fast:
            install.append(str(wheels[0]) + '[filter]')
        else:
            # The exact package has no runtime dependencies. The local wheel
            # can be installed without an index or a compiler.
            install += ['--no-index', '--no-deps', str(wheels[0])]
        subprocess.run(install, check=True)
        subprocess.run([str(python), '-m', 'qzguard', 'doctor'], cwd=str(root.parent), check=True)
        if not args.no_demo:
            subprocess.run([str(python), '-m', 'qzguard', 'demo', '--backend',
                            'filtered' if args.fast else 'exact'], cwd=str(root.parent), check=True)
    except (OSError, subprocess.CalledProcessError) as exc:
        print(f'Installation did not complete: {exc}', file=sys.stderr)
        return 2
    print(f'Ready. Run: {python} -m qzguard --help')
    return 0


if __name__ == '__main__':
    raise SystemExit(main())