forked from pdm-project/pdm
/
setup_dev.py
63 lines (50 loc) · 1.98 KB
/
setup_dev.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
"""
This script is used to setup development environment of pdm. It follows the naming
convention of setuptools but it is not basically a setuptools setup script.
After running this script, an editable version of pdm will be installed into
`__packages__`.
"""
import os
import shutil
import subprocess
import sys
import textwrap
from pathlib import Path
BASE_DIR = Path(__file__).parent
if sys.version_info < (3, 7):
sys.exit("PDM requires Python 3.7 or higher.")
def main():
venv_path = BASE_DIR / "env"
scripts_dir = "Scripts" if os.name == "nt" else "bin"
venv_python = venv_path / scripts_dir / "python"
print(f"Creating a venv using {sys.executable} at {venv_path}...", flush=True)
subprocess.check_call([sys.executable, "-m", "venv", venv_path.as_posix()])
print("Installing base requirements...", flush=True)
subprocess.check_call([venv_python.as_posix(), "-m", "pip", "install", "-U", "pip"])
subprocess.check_call([venv_python.as_posix(), "-m", "pip", "install", "."])
print("Setup project for development...", flush=True)
venv_pdm = (venv_python.parent / "pdm").as_posix()
subprocess.check_call([venv_pdm, "use", sys.executable])
subprocess.check_call([venv_pdm, "config", "parallel_install", "false"])
subprocess.check_call([venv_pdm, "install", "-vv"])
pep582_output = subprocess.check_output(
[venv_pdm, "run", "pdm", "--pep582"]
).decode("utf-8")
pdm_path = (
BASE_DIR
/ "__pypackages__"
/ ".".join(map(str, sys.version_info[:2]))
/ scripts_dir
/ "pdm"
).absolute()
print(f"\nDeleting venv {venv_path}...", flush=True)
shutil.rmtree(venv_path, ignore_errors=True)
print(
f"An editable version of pdm is installed at {pdm_path}, "
"you can create an alias for it for convenience.\n"
"Ensure PEP 582 is enabled by executing\n"
+ textwrap.indent(pep582_output, " " * 4),
flush=True,
)
if __name__ == "__main__":
main()