Skip to content

Commit 42112d1

Browse files
authored
Add a noxfile to receptorctl (#991)
1 parent 97235ff commit 42112d1

File tree

5 files changed

+124
-26
lines changed

5 files changed

+124
-26
lines changed

.github/workflows/pull_request.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ jobs:
3030
with:
3131
fetch-depth: 0
3232

33-
- name: Setup up python
34-
uses: actions/setup-python@v5
35-
with:
36-
python-version: '3.11'
37-
38-
- name: Install tox
39-
run: pip install tox
33+
- name: Setup nox
34+
uses: wntrblm/nox@2024.03.02
4035

4136
- name: Run receptorctl linters
4237
run: make receptorctl-lint
@@ -105,13 +100,9 @@ jobs:
105100
name: receptor
106101
path: /usr/local/bin/receptor
107102
receptorctl:
108-
name: receptorctl (Python ${{ matrix.python-version }})
103+
name: receptorctl
109104
needs: receptor
110-
strategy:
111-
matrix:
112-
os-version: ["ubuntu-22.04"]
113-
python-version: ["3.8", "3.9", "3.10", "3.11"]
114-
runs-on: "${{ matrix.os-version }}"
105+
runs-on: ubuntu-latest
115106
steps:
116107
- name: Checkout
117108
uses: actions/checkout@v4
@@ -127,16 +118,8 @@ jobs:
127118
- name: Fix permissions on receptor binary
128119
run: sudo chmod a+x /usr/local/bin/receptor
129120

130-
- name: Set up Python
131-
uses: actions/setup-python@v5
132-
with:
133-
python-version: "${{ matrix.python-version }}"
134-
135-
- name: Upgrade pip
136-
run: pip install --upgrade pip
137-
138-
- name: Install tox
139-
run: pip install tox
121+
- name: Setup nox
122+
uses: wntrblm/nox@2024.03.02
140123

141124
- name: Run receptorctl tests
142125
run: make receptorctl-test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ kubectl
2222
/docs/build
2323
/dist
2424
/test-configs
25-
coverage.txt
25+
coverage.txt
26+
venv

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ lint:
8989
@golint cmd/... pkg/... example/...
9090

9191
receptorctl-lint: receptorctl/.VERSION
92-
@cd receptorctl && tox -e lint
92+
@cd receptorctl && nox -s lint
9393

9494
format:
9595
@find cmd/ pkg/ -type f -name '*.go' -exec $(GO) fmt {} \;
@@ -140,7 +140,7 @@ test: receptor
140140
$(GO) test ./... $(TESTCMD) -count=1 -race -timeout 5m
141141

142142
receptorctl-test: receptorctl/.VERSION
143-
@cd receptorctl && tox -e py3
143+
@cd receptorctl && nox -s tests
144144

145145
testloop: receptor
146146
@i=1; while echo "------ $$i" && \

receptorctl/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
11
Receptorctl is a front-end CLI and importable Python library that interacts with Receptor over its control socket interface.
2+
3+
# Setting up nox
4+
5+
This project includes a `nox` configuration to automate tests, checks, and other functions in a reproducible way using isolated environments.
6+
Before you submit a PR, you should install `nox` and verify your changes.
7+
8+
> To run `make receptorctl-lint` and `receptorctl-test` from the repository root, you must first install `nox`.
9+
10+
1. Install `nox` using `python3 -m pip install nox` or your distribution's package manager.
11+
2. Run `nox --list` from the `receptorctl` directory to view available sessions.
12+
13+
You can run `nox` with no arguments to execute all checks and tests.
14+
Alternatively, you can run only certain tasks as outlined in the following sections.
15+
16+
# Checking changes to Receptorctl
17+
18+
Run the following `nox` sessions to check for code style and formatting issues:
19+
20+
* Run all checks.
21+
22+
``` bash
23+
nox -s lint
24+
```
25+
26+
* Check code style.
27+
28+
``` bash
29+
nox -s check_style
30+
```
31+
32+
* Check formatting.
33+
34+
``` bash
35+
nox -s check_format
36+
```
37+
38+
* Format code if the check fails.
39+
40+
``` bash
41+
nox -s format
42+
```
43+
44+
# Running Receptorctl tests
45+
46+
Run the following `nox` sessions to test Receptorctl changes:
47+
48+
* Run tests against the complete matrix of Python versions.
49+
50+
``` bash
51+
nox -s tests
52+
```
53+
54+
* Run tests against a specific Python version.
55+
56+
``` bash
57+
# For example, this command tests Receptorctl against Python 3.11.
58+
nox -s tests-3.11
59+
```

receptorctl/noxfile.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from glob import iglob
2+
3+
import nox
4+
5+
python_versions = ["3.8", "3.9", "3.10", "3.11"]
6+
7+
LINT_FILES: tuple[str, ...] = (
8+
*iglob("receptorctl/*.py"),
9+
"setup.py",
10+
)
11+
12+
13+
@nox.session(python=python_versions)
14+
def tests(session: nox.Session):
15+
"""
16+
Run receptorctl tests
17+
"""
18+
session.install("pytest")
19+
session.install("-e", ".")
20+
session.run("pytest", "-v", "tests", *session.posargs)
21+
22+
23+
@nox.session
24+
def check_style(session: nox.Session):
25+
"""
26+
Check receptorctl Python code style
27+
"""
28+
session.install("flake8")
29+
session.run("flake8", *session.posargs, *LINT_FILES)
30+
31+
32+
@nox.session
33+
def check_format(session: nox.Session):
34+
"""
35+
Check receptorctl Python file formatting without making changes
36+
"""
37+
session.install("black")
38+
session.run("black", "--check", *session.posargs, *LINT_FILES)
39+
40+
41+
@nox.session
42+
def format(session: nox.Session):
43+
"""
44+
Format receptorctl Python files
45+
"""
46+
session.install("black")
47+
session.run("black", *session.posargs, *LINT_FILES)
48+
49+
50+
@nox.session
51+
def lint(session: nox.Session):
52+
"""
53+
Check receptorctl for code style and formatting
54+
"""
55+
session.notify("check_style")
56+
session.notify("check_format")

0 commit comments

Comments
 (0)