Skip to content

Commit 2f67a46

Browse files
committed
Add install session for noxfile
This probably fails in multiple ways for Windows but an attempt was made.
1 parent 2354151 commit 2f67a46

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ python -m pip install --editable .[dev,test]
114114
pre-commit install
115115
```
116116

117+
### Install with nox
118+
119+
If you have `nox` installed with `pipx` or in the current venv you can use the
120+
following session. This is an alternative to the two steps above.
121+
122+
```console
123+
nox -s install
124+
```
125+
117126
---
118127

119128
## Pre-commit and nox tools

noxfile.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
from __future__ import annotations
22

3+
import os
34
import pathlib
45
import shutil
6+
import sys
57

68
import nox
79

810
# Control factors for finding pieces of the module
911
MODULE_NAME = "module_name"
1012
TESTS_PATH = "tests"
1113
COVERAGE_FAIL_UNDER = 50
14+
VENV_PATH = "venv"
15+
WINDOWS_PYTHON = "py"
16+
LINUX_PYTHON = "python3"
1217
REQUIREMENT_IN_FILES = [
1318
pathlib.Path("requirements/requirements.in"),
1419
pathlib.Path("requirements/requirements-dev.in"),
@@ -97,6 +102,32 @@ def build(session: nox.Session) -> None:
97102
session.run("python", "-m", "build")
98103

99104

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+
100131
@nox.session()
101132
def update(session: nox.Session) -> None:
102133
"""Process requirement*.in files, updating only additions/removals."""

0 commit comments

Comments
 (0)