| 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 |
parser.add_argument("--http", action="store_true", help="Install http requirements") |
| 14 |
parser.add_argument( |
| 15 |
"--zeroconf", action="store_true", help="Install zeroconf requirements" |
| 16 |
) |
| 17 |
args = parser.parse_args() |
| 18 |
|
| 19 |
# Create virtual environment |
| 20 |
builder = venv.EnvBuilder(with_pip=True) |
| 21 |
context = builder.ensure_directories(_VENV_DIR) |
| 22 |
builder.create(_VENV_DIR) |
| 23 |
|
| 24 |
# Upgrade dependencies |
| 25 |
pip = [context.env_exe, "-m", "pip"] |
| 26 |
subprocess.check_call(pip + ["install", "--upgrade", "pip"]) |
| 27 |
subprocess.check_call(pip + ["install", "--upgrade", "setuptools", "wheel"]) |
| 28 |
|
| 29 |
# Install requirements |
| 30 |
extras = [] |
| 31 |
if args.dev: |
| 32 |
extras.append("dev") |
| 33 |
|
| 34 |
if args.http: |
| 35 |
extras.append("http") |
| 36 |
|
| 37 |
if args.zeroconf: |
| 38 |
extras.append("zeroconf") |
| 39 |
|
| 40 |
extras_str = "" |
| 41 |
if extras: |
| 42 |
extras_str = "[" + ",".join(extras) + "]" |
| 43 |
|
| 44 |
subprocess.check_call(pip + ["install", "-e", f"{_PROGRAM_DIR}{extras_str}"]) |