Skip to content

Commit ddf0efb

Browse files
authored
chore: add nox support (#3101)
* chore: add nox support * chore: add more lines to CODEOWNERS
1 parent 9f11951 commit ddf0efb

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.github/CODEOWNERS

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ CMakeLists.txt @henryiii
44
*.yaml @henryiii
55
/tools/ @henryiii
66
/pybind11/ @henryiii
7+
noxfile.py @henryiii
8+
.clang-format @henryiii
9+
.clang-tidy @henryiii

.github/CONTRIBUTING.md

+27
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ derivative works thereof, in binary and source code form.
5353

5454
## Development of pybind11
5555

56+
### Quick setup
57+
58+
To setup a quick development environment, use [`nox`](https://nox.thea.codes).
59+
This will allow you to do some common tasks with minimal setup effort, but will
60+
take more time to run and be less flexible than a full development environment.
61+
If you use [`pipx run nox`](https://pipx.pypa.io), you don't even need to
62+
install `nox`. Examples:
63+
64+
```bash
65+
# List all available sessions
66+
nox -l
67+
68+
# Run linters
69+
nox -s lint
70+
71+
# Run tests
72+
nox -s tests
73+
74+
# Build and preview docs
75+
nox -s docs -- serve
76+
77+
# Build SDists and wheels
78+
nox -s build
79+
```
80+
81+
### Full setup
82+
5683
To setup an ideal development environment, run the following commands on a
5784
system with CMake 3.14+:
5885

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ repos:
2828
- id: requirements-txt-fixer
2929
- id: trailing-whitespace
3030
- id: fix-encoding-pragma
31+
exclude: ^noxfile.py$
3132

3233
# Black, the code formatter, natively supports pre-commit
3334
- repo: https://github.com/psf/black

noxfile.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import nox
2+
3+
4+
nox.options.sessions = ["lint", "tests", "tests_packaging"]
5+
6+
7+
@nox.session(reuse_venv=True)
8+
def lint(session: nox.Session) -> None:
9+
"""
10+
Lint the codebase (except for clang-format/tidy).
11+
"""
12+
session.install("pre-commit")
13+
session.run("pre-commit", "run", "-a")
14+
15+
16+
@nox.session
17+
def tests(session: nox.Session) -> None:
18+
"""
19+
Run the tests (requires a compiler).
20+
"""
21+
tmpdir = session.create_tmp()
22+
session.install("pytest", "cmake")
23+
session.run(
24+
"cmake",
25+
"-S",
26+
".",
27+
"-B",
28+
tmpdir,
29+
"-DPYBIND11_WERROR=ON",
30+
"-DDOWNLOAD_CATCH=ON",
31+
"-DDOWNLOAD_EIGEN=ON",
32+
*session.posargs
33+
)
34+
session.run("cmake", "--build", tmpdir)
35+
session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check")
36+
37+
38+
@nox.session
39+
def tests_packaging(session: nox.Session) -> None:
40+
"""
41+
Run the packaging tests.
42+
"""
43+
44+
session.install("-r", "tests/requirements.txt", "--prefer-binary")
45+
session.run("pytest", "tests/extra_python_package")
46+
47+
48+
@nox.session(reuse_venv=True)
49+
def docs(session: nox.Session) -> None:
50+
"""
51+
Build the docs. Pass "serve" to serve.
52+
"""
53+
54+
session.install("-r", "docs/requirements.txt")
55+
session.chdir("docs")
56+
session.run("sphinx-build", "-M", "html", ".", "_build")
57+
58+
if session.posargs:
59+
if "serve" in session.posargs:
60+
print("Launching docs at http://localhost:8000/ - use Ctrl-C to quit")
61+
session.run("python", "-m", "http.server", "8000", "-d", "_build/html")
62+
else:
63+
print("Unsupported argument to docs")
64+
65+
66+
@nox.session(reuse_venv=True)
67+
def make_changelog(session: nox.Session) -> None:
68+
"""
69+
Inspect the closed issues and make entries for a changelog.
70+
"""
71+
session.install("ghapi", "rich")
72+
session.run("python", "tools/make_changelog.py")
73+
74+
75+
@nox.session(reuse_venv=True)
76+
def build(session: nox.Session) -> None:
77+
"""
78+
Build SDists and wheels.
79+
"""
80+
81+
session.install("build")
82+
session.run("python", "-m", "build")
83+
session.run("python", "-m", "build", env={"PYBIND11_GLOBAL_SDIST": "1"})

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ignore =
4747
pybind11/include/**
4848
pybind11/share/**
4949
CMakeLists.txt
50+
noxfile.py
5051

5152

5253
[flake8]

0 commit comments

Comments
 (0)