This illustrates the use of nox in a simpler project. It can build docs,
run linters, and execute unittests simply and effectively.

Note we pin the packaging package as newer versions have changed
behavior on rolling release distros that don't have proper version. This
is necessary to fix gating. The followup change fixes it properly.

Change-Id: I795e4d73f60d90b0f027df43a80ebda773ee9194
This commit is contained in:
Clark Boylan 2022-12-16 12:33:43 -08:00
parent 69c7262259
commit 697af0b17a
6 changed files with 87 additions and 22 deletions

1
.gitignore vendored
View File

@ -23,6 +23,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.nox
.tox
nosetests.xml
.testrepository

View File

@ -49,7 +49,7 @@
vars:
release_python: python3
templates:
- publish-opendev-tox-docs
- publish-opendev-nox-docs
check:
jobs:
- bindep-centos-7
@ -60,12 +60,15 @@
- bindep-ubuntu-bionic
- bindep-ubuntu-focal
- build-python-release
- tox-pep8
- tox-py27
- tox-py35:
nodeset: ubuntu-xenial
- tox-py39:
nodeset: ubuntu-focal
- nox-linters
- nox-py27
- nox-py36:
nodeset: ubuntu-bionic
- nox-py310:
nodeset: ubuntu-jammy
- nox-py311:
nodeset: ubuntu-jammy
- nox-cover
gate:
jobs:
- bindep-centos-7
@ -76,12 +79,15 @@
- bindep-ubuntu-bionic
- bindep-ubuntu-focal
- build-python-release
- tox-pep8
- tox-py27
- tox-py35:
nodeset: ubuntu-xenial
- tox-py39:
nodeset: ubuntu-focal
- nox-linters
- nox-py27
- nox-py36:
nodeset: ubuntu-bionic
- nox-py310:
nodeset: ubuntu-jammy
- nox-py311:
nodeset: ubuntu-jammy
- nox-cover
promote:
jobs:
- opendev-promote-python

59
noxfile.py Normal file
View File

@ -0,0 +1,59 @@
import nox
nox.options.error_on_external_run = True
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ["tests-3", "tests-2.7", "linters"]
# Note setting python this way seems to give us a target name without
# python specific suffixes while still allowing us to force a specific
# version using --force-python.
@nox.session(python="3")
def linters(session):
session.install("hacking>=3.2.0,<3.3")
session.run("flake8")
@nox.session(python="3")
def docs(session):
session.install("-r", "requirements.txt")
session.install("-r", "doc/requirements.txt")
session.install(".")
session.run(
"sphinx-build", "-W",
"-d", "doc/build/doctrees",
"-b", "html",
"doc/source/", "doc/build/html"
)
@nox.session(python="3")
def venv(session):
session.install("-r", "requirements.txt")
session.install("-r", "test-requirements.txt")
session.install("-e", ".")
session.run(*session.posargs)
# This will attempt to run python3 and 2.7 tests by default.
@nox.session(python=["3", "2.7"])
def tests(session):
session.install("-r", "requirements.txt")
session.install("-r", "test-requirements.txt")
session.install("-e", ".")
session.run("stestr", "run", *session.posargs)
session.run("stestr", "slowest")
@nox.session(python="3")
def cover(session):
session.install("-r", "requirements.txt")
session.install("-r", "test-requirements.txt")
session.install("-e", ".")
session.env["PYTHON"] = "coverage run --source bindep --parallel-mode"
session.run("stestr", "run", *session.posargs)
session.run("stestr", "slowest")
session.run("coverage", "combine")
session.run("coverage", "html", "-d", "cover")
session.run("coverage", "xml", "-o", "cover/coverage.xml")

View File

@ -2,5 +2,5 @@ distro<1.7.0 ; python_version < '3.6'
distro>=1.7.0 ; python_version >= '3.6'
pbr>=2.0.0 # Apache-2.0
Parsley
packaging ; python_version >= '3.6'
packaging<22.0 ; python_version >= '3.6'
packaging<21.0 ; python_version < '3.6'

View File

@ -51,3 +51,10 @@ console_scripts =
[wheel]
universal = 1
[flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125,E129,H,W503,W504
builtins = _
exclude=.venv,.git,.nox,.tox,dist,doc,*lib/python*,*egg,build

View File

@ -41,11 +41,3 @@ deps =
-r{toxinidir}/doc/requirements.txt
commands =
sphinx-build -W -d doc/build/doctrees -b html doc/source/ doc/build/html
[flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125,E129,H,W503,W504
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build