Debian Codegraph @

script/setup

raw
1 #!/usr/bin/env python3
2 import argparse
3 import subprocess
4 import venv
5 from pathlib import Path
6
7 _DIR = Path(__file__).parent
8 _PROGRAM_DIR = _DIR.parent
9 _VENV_DIR = _PROGRAM_DIR / ".venv"
10
11 parser = argparse.ArgumentParser()
12 parser.add_argument("--dev", action="store_true", help="Install dev requirements")
13 args = parser.parse_args()
14
15 # Create virtual environment
16 builder = venv.EnvBuilder(with_pip=True)
17 context = builder.ensure_directories(_VENV_DIR)
18 builder.create(_VENV_DIR)
19
20 # Upgrade dependencies
21 pip = [context.env_exe, "-m", "pip"]
22 subprocess.check_call(pip + ["install", "--upgrade", "pip"])
23 subprocess.check_call(pip + ["install", "--upgrade", "setuptools", "wheel"])
24
25 # Install requirements
26 subprocess.check_call(pip + ["install", "-e", str(_PROGRAM_DIR)])
27
28 if args.dev:
29 # Install dev requirements
30 subprocess.check_call(
31 pip + ["install", "-e", f"{_PROGRAM_DIR}[dev]"]
32 )