Skip to content

Commit c462fc0

Browse files
authored
Merge pull request #124 from Preocts/preocts
Replace Makefile with noxfile config
2 parents 8b6884e + 527ddd3 commit c462fc0

File tree

3 files changed

+118
-117
lines changed

3 files changed

+118
-117
lines changed

Makefile

Lines changed: 0 additions & 50 deletions
This file was deleted.

README.md

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -65,68 +65,42 @@ the desired version while creating the `venv`. (e.g. `python3` or `python3.8`)
6565

6666
## Installation steps
6767

68-
### Makefile
69-
70-
This repo has a Makefile with some quality of life scripts if the system
71-
supports `make`. Please note there are no checks for an active `venv` in the
72-
Makefile. If you are on Windows you can install make using scoop or chocolatey.
73-
74-
| PHONY | Description |
75-
| ------------- | --------------------------------------------------------------------- |
76-
| `install-dev` | install development/test requirements and project as editable install |
77-
| `update-dev` | regenerate requirements-*.txt (will keep existing pins) |
78-
| `upgrade-dev` | attempt to update all dependencies, regenerate requirements-*.txt |
79-
| `coverage` | Run tests with coverage, generate console report |
80-
| `docker-test` | Run coverage and tests in a docker container. |
81-
| `build-dist` | Build source distribution and wheel distribution |
82-
| `clean` | Deletes build, nox, coverage, pytest, mypy, cache, and pyc artifacts |
83-
84-
8568
Clone this repo and enter root directory of repo:
8669

8770
```console
88-
$ git clone https://github.com/[ORG NAME]/[REPO NAME]
89-
$ cd [REPO NAME]
71+
git clone https://github.com/[ORG NAME]/[REPO NAME]
72+
cd [REPO NAME]
9073
```
9174

92-
9375
Create the `venv`:
9476

9577
```console
96-
$ python -m venv venv
78+
python -m venv venv
9779
```
9880

9981
Activate the `venv`:
10082

10183
```console
10284
# Linux/Mac
103-
$ . venv/bin/activate
85+
. venv/bin/activate
10486

10587
# Windows
106-
$ venv\Scripts\activate
88+
venv\Scripts\activate
10789
```
10890

10991
The command prompt should now have a `(venv)` prefix on it. `python` will now
11092
call the version of the interpreter used to create the `venv`
11193

11294
Install editable library and development requirements:
11395

114-
### With Makefile:
115-
11696
```console
117-
make install-dev
118-
```
119-
120-
### Without Makefile:
121-
122-
```console
123-
$ python -m pip install --editable .[dev,test]
97+
python -m pip install --editable .[dev,test]
12498
```
12599

126100
Install pre-commit [(see below for details)](#pre-commit):
127101

128102
```console
129-
$ pre-commit install
103+
pre-commit install
130104
```
131105

132106
---
@@ -136,33 +110,32 @@ $ pre-commit install
136110
Run pre-commit on all files:
137111

138112
```console
139-
$ pre-commit run --all-files
113+
pre-commit run --all-files
140114
```
141115

142116
Run tests (quick):
143117

144118
```console
145-
$ pytest
119+
pytest
146120
```
147121

148-
Run tests (slow):
122+
Run tests:
149123

150124
```console
151-
$ nox
125+
nox
152126
```
153127

154128
Build dist:
155129

156130
```console
157-
$ python -m pip install --upgrade build
158-
159-
$ python -m build
131+
python -m pip install --upgrade build
132+
python -m build
160133
```
161134

162135
To deactivate (exit) the `venv`:
163136

164137
```console
165-
$ deactivate
138+
deactivate
166139
```
167140

168141
---
@@ -176,22 +149,6 @@ generated `requirements-*.txt` files.
176149

177150
Once updated following the steps below, the package can be installed if needed.
178151

179-
### With Makefile
180-
181-
To update the generated files with a dependency:
182-
183-
```console
184-
make update-dev
185-
```
186-
187-
To attempt to upgrade all generated dependencies:
188-
189-
```console
190-
make upgrade-dev
191-
```
192-
193-
### Without Makefile
194-
195152
To update the generated files with a dependency:
196153

197154
```console
@@ -200,13 +157,7 @@ pip-compile --no-emit-index-url requirements/requirements-dev.in
200157
pip-compile --no-emit-index-url requirements/requirements-test.in
201158
```
202159

203-
To attempt to upgrade all generated dependencies:
204-
205-
```console
206-
pip-compile --upgrade --no-emit-index-url requirements/requirements.in
207-
pip-compile --upgrade --no-emit-index-url requirements/requirements-dev.in
208-
pip-compile --upgrade --no-emit-index-url requirements/requirements-test.in
209-
```
160+
To attempt to upgrade all generated dependencies add the `--upgrade` flag.
210161

211162
---
212163

noxfile.py

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
from __future__ import annotations
22

3+
import os
4+
import sys
5+
36
import nox
47

8+
# Control factors for finding pieces of the module
59
MODULE_NAME = "module_name"
6-
COVERAGE_FAIL_UNDER = "--fail-under=50"
10+
TESTS_PATH = "tests"
11+
COVERAGE_FAIL_UNDER = 50
12+
REQUIREMENT_IN_FILES = [
13+
os.path.join("requirements", "requirements.in"),
14+
os.path.join("requirements", "requirements-dev.in"),
15+
os.path.join("requirements", "requirements-test.in"),
16+
]
17+
18+
# What are we allowed to clean (delete)?
19+
CLEAN_DIRS = [
20+
"__pycache__",
21+
".mypy_cache",
22+
".pytest_cache",
23+
".coverage",
24+
".nox",
25+
"dist",
26+
"build",
27+
]
28+
CLEAN_FILES = [
29+
"*.pyc",
30+
"*.pyo",
31+
"coverage.json",
32+
".coverage.*",
33+
]
34+
35+
36+
# Define the default sessions run when `nox` is called on the CLI
37+
nox.options.sessions = [
38+
"tests_with_coverage",
39+
"coverage_combine_and_report",
40+
"mypy_check",
41+
]
742

843

944
@nox.session(
@@ -14,17 +49,19 @@ def tests_with_coverage(session: nox.Session) -> None:
1449
print_standard_logs(session)
1550

1651
session.install(".[test]")
17-
session.run("coverage", "run", "-p", "-m", "pytest", "tests/")
52+
session.run("coverage", "run", "-p", "-m", "pytest", TESTS_PATH)
1853

1954

2055
@nox.session()
2156
def coverage_combine_and_report(session: nox.Session) -> None:
2257
"""Combine all coverage partial files and generate JSON report."""
2358
print_standard_logs(session)
2459

60+
fail_under = f"--fail-under={COVERAGE_FAIL_UNDER}"
61+
2562
session.install(".[test]")
2663
session.run("python", "-m", "coverage", "combine")
27-
session.run("python", "-m", "coverage", "report", "-m", COVERAGE_FAIL_UNDER)
64+
session.run("python", "-m", "coverage", "report", "-m", fail_under)
2865
session.run("python", "-m", "coverage", "json")
2966

3067

@@ -38,6 +75,69 @@ def mypy_check(session: nox.Session) -> None:
3875
session.run("mypy", "-p", MODULE_NAME, "--no-incremental")
3976

4077

78+
@nox.session(python=False)
79+
def coverage(session: nox.Session) -> None:
80+
"""Generate a coverage report. Does not use a venv."""
81+
session.run("coverage", "erase")
82+
session.run("coverage", "run", "-m", "pytest", TESTS_PATH)
83+
session.run("coverage", "report", "-m")
84+
85+
86+
@nox.session(python=False)
87+
def docker(session: nox.Session) -> None:
88+
"""Run tests in a docker container. Requires docker damon running."""
89+
session.run("docker", "build", "-t", "pydocker-test", ".")
90+
session.run("docker", "run", "-it", "--rm", "pydocker-test")
91+
92+
93+
@nox.session()
94+
def build(session: nox.Session) -> None:
95+
"""Build distrobution files."""
96+
print_standard_logs(session)
97+
98+
session.install("build")
99+
session.run("python", "-m", "build")
100+
101+
102+
@nox.session()
103+
def update(session: nox.Session) -> None:
104+
"""Process requirement*.in files, updating only additions/removals."""
105+
print_standard_logs(session)
106+
107+
session.install("pip-tools")
108+
for filename in REQUIREMENT_IN_FILES:
109+
session.run("pip-compile", "--no-emit-index-url", filename)
110+
111+
112+
@nox.session()
113+
def upgrade(session: nox.Session) -> None:
114+
"""Process requirement*.in files and upgrade all libraries as possible."""
115+
print_standard_logs(session)
116+
117+
session.install("pip-tools")
118+
for filename in REQUIREMENT_IN_FILES:
119+
session.run("pip-compile", "--no-emit-index-url", "--upgrade", filename)
120+
121+
122+
@nox.session(python=False)
123+
def clean(session: nox.Session) -> None:
124+
"""Clean cache, .pyc, .pyo, and artifact files from project."""
125+
if sys.platform.startswith("win"):
126+
print("Windows unsupported at this time.")
127+
return None
128+
129+
elif sys.platform in ["linux", "darwin"]:
130+
for dirpath in CLEAN_DIRS:
131+
session.run("find", ".", "-name", dirpath, "-exec", "rm", "-rf", "{}", "+")
132+
133+
for file in CLEAN_FILES:
134+
session.run("find", ".", "-name", file, "-exec", "rm", "-f", "{}", "+")
135+
136+
else:
137+
print("Unknown OS for this session.")
138+
return None
139+
140+
41141
def print_standard_logs(session: nox.Session) -> None:
42142
"""Reusable output for monitoring environment factors."""
43143
version = session.run("python", "--version", silent=True)

0 commit comments

Comments
 (0)