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
|
#!/usr/bin/env python3
import argparse
import subprocess
import venv
from pathlib import Path
_DIR = Path(__file__).parent
_PROGRAM_DIR = _DIR.parent
_VENV_DIR = _PROGRAM_DIR / ".venv"
parser = argparse.ArgumentParser()
parser.add_argument("--dev", action="store_true", help="Install dev requirements")
parser.add_argument("--http", action="store_true", help="Install http requirements")
parser.add_argument(
"--zeroconf", action="store_true", help="Install zeroconf requirements"
)
args = parser.parse_args()
# Create virtual environment
builder = venv.EnvBuilder(with_pip=True)
context = builder.ensure_directories(_VENV_DIR)
builder.create(_VENV_DIR)
# Upgrade dependencies
pip = [context.env_exe, "-m", "pip"]
subprocess.check_call(pip + ["install", "--upgrade", "pip"])
subprocess.check_call(pip + ["install", "--upgrade", "setuptools", "wheel"])
# Install requirements
extras = []
if args.dev:
extras.append("dev")
if args.http:
extras.append("http")
if args.zeroconf:
extras.append("zeroconf")
extras_str = ""
if extras:
extras_str = "[" + ",".join(extras) + "]"
subprocess.check_call(pip + ["install", "-e", f"{_PROGRAM_DIR}{extras_str}"])
|