setup_dev.py 1.4 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 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
"""
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"

    print(f"Creating a venv using {sys.executable} at {venv_path}...")
    subprocess.check_call([sys.executable, "-m", "venv", venv_path.as_posix()])

    print("Installing base requirements...")
    subprocess.check_call([venv_python.as_posix(), "-m", "pip", "install", "pdm"])

    print("Setup project for development...")
    subprocess.check_call([venv_python.as_posix(), "-m", "pdm", "install", "-d"])

    pdm_path = (
        BASE_DIR
        / "__pypackages__"
        / ".".join(sys.version_info[:2])
        / scripts_dir
        / "pdm"
    )

    print(f"\nDeleting venv {venv_path}...")
    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."
    )


if __name__ == "__main__":
    main()