setup_dev.py 1.9 KB
Newer Older
F
Frost Ming 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
"""
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
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"

F
frostming 已提交
24
    print(f"Creating a venv using {sys.executable} at {venv_path}...", flush=True)
F
Frost Ming 已提交
25 26
    subprocess.check_call([sys.executable, "-m", "venv", venv_path.as_posix()])

F
frostming 已提交
27
    print("Installing base requirements...", flush=True)
F
Frost Ming 已提交
28 29
    subprocess.check_call([venv_python.as_posix(), "-m", "pip", "install", "pdm"])

N
Nasy 已提交
30
    subprocess.check_call(
F
Frost Ming 已提交
31 32 33 34 35 36 37 38 39 40
        [
            venv_python.as_posix(),
            "-m",
            "pip",
            "install",
            "-U",
            "pip",
            "pip_shims",
            "vistir",
        ]
N
Nasy 已提交
41 42
    )

F
frostming 已提交
43 44
    print("Setup project for development...", flush=True)
    venv_pdm = (venv_python.parent / "pdm").as_posix()
F
Frost Ming 已提交
45

F
frostming 已提交
46
    subprocess.check_call([venv_pdm, "use", sys.executable])
F
Frost Ming 已提交
47
    subprocess.check_call([venv_pdm, "config", "set", "parallel_install", "false"])
F
frostming 已提交
48
    subprocess.check_call([venv_pdm, "install", "-d"])
F
Frost Ming 已提交
49 50 51 52

    pdm_path = (
        BASE_DIR
        / "__pypackages__"
N
Nasy 已提交
53
        / ".".join(map(str, sys.version_info[:2]))
F
Frost Ming 已提交
54 55
        / scripts_dir
        / "pdm"
F
frostming 已提交
56
    ).absolute()
F
Frost Ming 已提交
57

F
frostming 已提交
58
    print(f"\nDeleting venv {venv_path}...", flush=True)
F
Frost Ming 已提交
59 60 61 62
    shutil.rmtree(venv_path, ignore_errors=True)

    print(
        f"An editable version of pdm is installed at {pdm_path}, "
F
frostming 已提交
63 64
        "you can create an alias for it for convenience.",
        flush=True,
F
Frost Ming 已提交
65 66 67 68 69
    )


if __name__ == "__main__":
    main()