-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-venv.py
More file actions
63 lines (50 loc) · 1.85 KB
/
setup-venv.py
File metadata and controls
63 lines (50 loc) · 1.85 KB
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
"""Script responsible for first time setup of the project's venv.
Since this is a first time setup script, we intentionally only use builtin Python dependencies.
"""
import argparse
import shutil
import subprocess
from pathlib import Path
from util import check_dependencies
from util import existing_dir
from util import remove_readonly
def main() -> None:
"""Parses args and passes through to setup_venv."""
parser: argparse.ArgumentParser = get_parser()
args: argparse.Namespace = parser.parse_args()
setup_venv(path=args.path, python_version=args.python_version)
def get_parser() -> argparse.ArgumentParser:
"""Creates the argument parser for setup-venv."""
parser: argparse.ArgumentParser = argparse.ArgumentParser(
prog="setup-venv", usage="python ./scripts/setup-venv.py . -p '3.10'"
)
parser.add_argument(
"path",
type=existing_dir,
metavar="PATH",
help="Path to the repo's root directory (must already exist).",
)
parser.add_argument(
"-p",
"--python",
dest="python_version",
help="The Python version that will serve as the main working version used by the IDE.",
)
return parser
def setup_venv(path: Path, python_version: str) -> None:
"""Set up the provided cookiecutter-robust-python project's venv."""
commands: list[list[str]] = [
["uv", "lock"],
["uv", "venv", ".venv"],
["uv", "python", "install", python_version],
["uv", "python", "pin", python_version],
["uv", "sync", "--all-groups"],
]
check_dependencies(path=path, dependencies=["uv"])
venv_path: Path = path / ".venv"
if venv_path.exists():
shutil.rmtree(venv_path, onerror=remove_readonly)
for command in commands:
subprocess.run(command, cwd=path, capture_output=True)
if __name__ == "__main__":
main()