-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_requirements.py
72 lines (61 loc) · 1.92 KB
/
install_requirements.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import argparse
import platform
import subprocess
import sys
from typing import List
def run_pip(
args: List[str], command: str = "install", upgrade: bool = True, force: bool = False
):
cmd = ["pip", command]
if upgrade:
cmd.append("--upgrade")
if force:
cmd.append("--force")
cmd.extend(args)
result = subprocess.run(cmd)
if result.returncode != 0:
sys.exit(result.returncode)
def install_requirements(force: bool = False):
args = ["-r", "requirements.txt"]
if platform.system() == "Windows":
args.append("-f")
args.append("https://download.pytorch.org/whl/torch_stable.html")
run_pip(args, force=force)
def install_checkers(force: bool = False):
args = ["mypy", "ruff", "black", "isort"]
run_pip(args, force=force)
def main():
parser = argparse.ArgumentParser(description="Install dependencies")
parser.add_argument(
dest="target",
help=(
"Optionnaly specify which targtet dependencies to install. "
"`dev` are dev tools (checker, linter, formatter), "
"and `regular` are the ones in requirements.txt. "
"For convenience: `all = [deps, dev]` "
"[Default: all]"
),
choices=["all", "deps", "dev"],
default="all",
nargs="*",
)
parser.add_argument(
"-f",
"--force",
dest="force",
help=("Force re-installing the depenencies"),
action="store_true",
)
options = parser.parse_args()
if (
"all" in options.target
or "deps" in options.target
or "regular" in options.target
):
print("⇒ Installing regular dependencies")
install_requirements(force=options.force)
if "all" in options.target or "dev" in options.target:
print("⇒ Installing dev depdendencies")
install_checkers(force=options.force)
if __name__ == "__main__":
main()