Skip to content

Commit e3c35fe

Browse files
committed
Add bootstrap.py for dev env bootstrapping
1 parent ff5d700 commit e3c35fe

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ Install Python, nodejs and yarn.
1818
- https://nodejs.org/
1919
- https://classic.yarnpkg.com/en/docs/install
2020

21-
Create a Python virtualenv e.g. with https://docs.python.org/3/library/venv.html.
22-
The minimum Python version is 3.8.
21+
N.B The minimum Python version is 3.8.
22+
23+
Run `python bootsrap.py` to create a virtual environment with correct dependencies.
24+
After that, make sure to activate the virtual env before running other development commands.
2325

2426
```
25-
python -m venv .venv
27+
python bootstrap.py
2628
source .venv/bin/activate # On linux and OSX
2729
.venv\Scripts\activate.bat # On Windows
2830
```

bootstrap.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Creates a virtual environment for developing the library.
2+
3+
Also installs the needed dependencies.
4+
"""
5+
6+
from pathlib import Path
7+
import platform
8+
import subprocess
9+
import sys
10+
from venv import EnvBuilder
11+
12+
venv_dir = Path(".") / ".venv"
13+
src_dir = Path(".") / "Browser"
14+
15+
if not venv_dir.exists():
16+
print(f"Creating virtualenv in {venv_dir}")
17+
EnvBuilder(with_pip=True).create(venv_dir)
18+
19+
subprocess.run(
20+
[
21+
sys.executable,
22+
"-m",
23+
"pip",
24+
"install",
25+
"-r",
26+
str(src_dir / "dev-requirements.txt"),
27+
]
28+
)
29+
subprocess.run(
30+
[sys.executable, "-m", "pip", "install", "-r", str(src_dir / "requirements.txt")]
31+
)
32+
33+
activate_script = (
34+
"source .venv/bin/activate"
35+
if sys.platform != "Windows"
36+
else ".venv\Scripts\activate.bat"
37+
)
38+
print(f"Virtualenv `{venv_dir}` is ready and up-to-date.")
39+
print(f"Run `{activate_script}` to activate the virtualenv.")

0 commit comments

Comments
 (0)