|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import os |
3 | 4 | import pathlib |
4 | 5 | import shutil |
| 6 | +import sys |
5 | 7 |
|
6 | 8 | import nox |
7 | 9 |
|
8 | 10 | # Control factors for finding pieces of the module |
9 | 11 | MODULE_NAME = "module_name" |
10 | 12 | TESTS_PATH = "tests" |
11 | 13 | COVERAGE_FAIL_UNDER = 50 |
| 14 | +VENV_PATH = "venv" |
| 15 | +WINDOWS_PYTHON = "py" |
| 16 | +LINUX_PYTHON = "python3" |
12 | 17 | REQUIREMENT_IN_FILES = [ |
13 | 18 | pathlib.Path("requirements/requirements.in"), |
14 | 19 | pathlib.Path("requirements/requirements-dev.in"), |
@@ -97,6 +102,32 @@ def build(session: nox.Session) -> None: |
97 | 102 | session.run("python", "-m", "build") |
98 | 103 |
|
99 | 104 |
|
| 105 | +@nox.session(python=False) |
| 106 | +def install(session: nox.Session) -> None: |
| 107 | + """Setup a development environment. Uses active venv if available, builds one if not.""" |
| 108 | + # Use the active environement if it exists, otherwise create a new one |
| 109 | + venv_path = os.environ.get("VIRTUAL_ENV", VENV_PATH) |
| 110 | + |
| 111 | + if sys.platform == "win32": |
| 112 | + py_command = "py" |
| 113 | + venv_path = f"{venv_path}/Scripts" |
| 114 | + activate_command = f"{venv_path}/activate" |
| 115 | + else: |
| 116 | + py_command = "python3" |
| 117 | + venv_path = f"{venv_path}/bin" |
| 118 | + activate_command = f"source {venv_path}/activate" |
| 119 | + |
| 120 | + if not os.path.exists(VENV_PATH): |
| 121 | + session.run(py_command, "-m", "venv", VENV_PATH) |
| 122 | + session.run(f"{venv_path}/python", "-m", "pip", "install", "--upgrade", "pip") |
| 123 | + |
| 124 | + session.run(f"{venv_path}/python", "-m", "pip", "install", "-e", ".[dev,test]") |
| 125 | + session.run(f"{venv_path}/pre-commit", "install") |
| 126 | + |
| 127 | + if not os.environ.get("VIRTUAL_ENV"): |
| 128 | + session.log(f"\n\nRun '{activate_command}' to enter the virtual environment.\n") |
| 129 | + |
| 130 | + |
100 | 131 | @nox.session() |
101 | 132 | def update(session: nox.Session) -> None: |
102 | 133 | """Process requirement*.in files, updating only additions/removals.""" |
|
0 commit comments