From ddf0efb9905770399eea765b4aaca09446155f04 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 12 Jul 2021 17:45:40 -0400 Subject: [PATCH] chore: add nox support (#3101) * chore: add nox support * chore: add more lines to CODEOWNERS --- .github/CODEOWNERS | 3 ++ .github/CONTRIBUTING.md | 27 ++++++++++++++ .pre-commit-config.yaml | 1 + noxfile.py | 83 +++++++++++++++++++++++++++++++++++++++++ setup.cfg | 1 + 5 files changed, 115 insertions(+) create mode 100644 noxfile.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 60af5e797..4e2c66902 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,3 +4,6 @@ CMakeLists.txt @henryiii *.yaml @henryiii /tools/ @henryiii /pybind11/ @henryiii +noxfile.py @henryiii +.clang-format @henryiii +.clang-tidy @henryiii diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6f9ebf21f..ff1997f98 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -53,6 +53,33 @@ derivative works thereof, in binary and source code form. ## Development of pybind11 +### Quick setup + +To setup a quick development environment, use [`nox`](https://nox.thea.codes). +This will allow you to do some common tasks with minimal setup effort, but will +take more time to run and be less flexible than a full development environment. +If you use [`pipx run nox`](https://pipx.pypa.io), you don't even need to +install `nox`. Examples: + +```bash +# List all available sessions +nox -l + +# Run linters +nox -s lint + +# Run tests +nox -s tests + +# Build and preview docs +nox -s docs -- serve + +# Build SDists and wheels +nox -s build +``` + +### Full setup + To setup an ideal development environment, run the following commands on a system with CMake 3.14+: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 85d575464..3f5a5723c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,6 +28,7 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace - id: fix-encoding-pragma + exclude: ^noxfile.py$ # Black, the code formatter, natively supports pre-commit - repo: https://github.com/psf/black diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..3bc61273f --- /dev/null +++ b/noxfile.py @@ -0,0 +1,83 @@ +import nox + + +nox.options.sessions = ["lint", "tests", "tests_packaging"] + + +@nox.session(reuse_venv=True) +def lint(session: nox.Session) -> None: + """ + Lint the codebase (except for clang-format/tidy). + """ + session.install("pre-commit") + session.run("pre-commit", "run", "-a") + + +@nox.session +def tests(session: nox.Session) -> None: + """ + Run the tests (requires a compiler). + """ + tmpdir = session.create_tmp() + session.install("pytest", "cmake") + session.run( + "cmake", + "-S", + ".", + "-B", + tmpdir, + "-DPYBIND11_WERROR=ON", + "-DDOWNLOAD_CATCH=ON", + "-DDOWNLOAD_EIGEN=ON", + *session.posargs + ) + session.run("cmake", "--build", tmpdir) + session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check") + + +@nox.session +def tests_packaging(session: nox.Session) -> None: + """ + Run the packaging tests. + """ + + session.install("-r", "tests/requirements.txt", "--prefer-binary") + session.run("pytest", "tests/extra_python_package") + + +@nox.session(reuse_venv=True) +def docs(session: nox.Session) -> None: + """ + Build the docs. Pass "serve" to serve. + """ + + session.install("-r", "docs/requirements.txt") + session.chdir("docs") + session.run("sphinx-build", "-M", "html", ".", "_build") + + if session.posargs: + if "serve" in session.posargs: + print("Launching docs at http://localhost:8000/ - use Ctrl-C to quit") + session.run("python", "-m", "http.server", "8000", "-d", "_build/html") + else: + print("Unsupported argument to docs") + + +@nox.session(reuse_venv=True) +def make_changelog(session: nox.Session) -> None: + """ + Inspect the closed issues and make entries for a changelog. + """ + session.install("ghapi", "rich") + session.run("python", "tools/make_changelog.py") + + +@nox.session(reuse_venv=True) +def build(session: nox.Session) -> None: + """ + Build SDists and wheels. + """ + + session.install("build") + session.run("python", "-m", "build") + session.run("python", "-m", "build", env={"PYBIND11_GLOBAL_SDIST": "1"}) diff --git a/setup.cfg b/setup.cfg index 041e62dae..527d18aac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,6 +47,7 @@ ignore = pybind11/include/** pybind11/share/** CMakeLists.txt + noxfile.py [flake8]