From 12a0aca425ead764d722ae23f5a12ae2ec0b4a3f Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 24 Jan 2023 10:13:35 -0800 Subject: [PATCH] Switch from tox to nox Recent tox releases have put us on a config treadmill. Avoid these issues entirely by using nox. Nox is a tox alternative that uses standard tools like pip and should be simpler to use for us. Change-Id: Ie79845bbed7ca1254aec466bd5219186fefcdac9 --- .gitignore | 1 + .zuul.yaml | 14 +++++----- CONTRIBUTING.rst | 19 ++++++------- doc/source/developing.rst | 6 ++-- noxfile.py | 58 +++++++++++++++++++++++++++++++++++++++ setup.cfg | 5 ++++ tox.ini | 42 ---------------------------- 7 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 noxfile.py delete mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 11600e33..38ca662f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ ChangeLog .gerrit .testrepository .tox +.nox .venv *.egg *.egg-info diff --git a/.zuul.yaml b/.zuul.yaml index b4873362..7a5a0626 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -2,18 +2,18 @@ vars: release_python: python3 templates: - - publish-opendev-tox-docs + - publish-opendev-nox-docs check: jobs: &jobs - build-python-release - - tox-linters - - tox-py36: + - nox-linters + - nox-py36: nodeset: ubuntu-bionic - - tox-py37: + - nox-py37: nodeset: ubuntu-bionic - - tox-py38: + - nox-py38: nodeset: ubuntu-focal - - tox-py39: + - nox-py39: nodeset: ubuntu-focal gate: jobs: *jobs @@ -23,4 +23,4 @@ release: jobs: - opendev-release-python - - opendev-publish-unversioned-tox-docs + - opendev-publish-unversioned-nox-docs diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 9b43ec73..7877dcee 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -20,13 +20,13 @@ tools, or review ``bindep.txt`` by hand. Running Tests ------------- -The testing system is based on a combination of tox and testr. The canonical -approach to running tests is to simply run the command `tox`. This will +The testing system is based on a combination of nox and testr. The canonical +approach to running tests is to simply run the command `nox`. This will create virtual environments, populate them with dependencies and run all of -the tests that OpenStack CI systems run. Behind the scenes, tox is running -`testr run --parallel`, but is set up such that you can supply any additional -testr arguments that are needed to tox. For example, you can run: -`tox -- --analyze-isolation` to cause tox to tell testr to add +the tests that OpenStack CI systems run. Behind the scenes, nox is running +`stestr run`, but is set up such that you can supply any additional +stestr arguments that are needed to nox. For example, you can run: +`nox -s tests -- --analyze-isolation` to cause nox to tell testr to add --analyze-isolation to its argument list. It is also possible to run the tests inside of a virtual environment @@ -38,7 +38,6 @@ test-requirements.txt. Installing them via pip, for instance, is simply:: pip install -r requirements.txt -r test-requirements.txt In you go this route, you can interact with the testr command directly. -Running `testr run` will run the entire test suite. `testr run --parallel` -will run it in parallel (this is the default incantation tox uses.) More -information about testr can be found at: -https://testrepository.readthedocs.io/en/latest/ +Running `stestr run` will run the entire test suite. +More information about testr can be found at: +https://stestr.readthedocs.io/en/latest/README.html diff --git a/doc/source/developing.rst b/doc/source/developing.rst index fa2c2a1f..81d4cf5f 100644 --- a/doc/source/developing.rst +++ b/doc/source/developing.rst @@ -13,7 +13,7 @@ following: cached copy (it needs to be located in a ``.gerrit`` directory at the top level of the git-review project) -To run git-review integration tests, use tox. For example, to test against -Python 3.7:: +To run git-review integration tests, use nox. For example, to test against +Python 3:: - tox -e py37 + nox -s tests diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 00000000..aa20c0e8 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,58 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import nox + + +nox.options.error_on_external_run = True +nox.options.reuse_existing_virtualenvs = True +nox.options.sessions = ["tests-3", "docs", "linters"] + + +@nox.session(python="3") +def linters(session): + session.install("-r", "requirements.txt") + session.install("-r", "test-requirements.txt") + session.install("-e", ".") + session.run("flake8") + + +@nox.session(python="3") +def docs(session): + session.install("-r", "requirements.txt") + session.install("-r", "doc/requirements.txt") + session.install("-e", ".") + 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) + + +@nox.session(python="3") +def tests(session): + session.install("-r", "requirements.txt") + session.install("-r", "test-requirements.txt") + session.install("-e", ".") + session.run("python", "-m", "git_review.tests.check_test_id_hashes", + "discover", "--list") + session.run("python", "-m", "git_review.tests.prepare") + session.run("stestr", "run", "--color", *session.posargs) diff --git a/setup.cfg b/setup.cfg index f5630322..8bef32de 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,3 +42,8 @@ console_scripts = [pbr] manpages = git-review.1 + +[flake8] +ignore = E125,H202,H405,H904,W504 +show-source = true +exclude = .venv,.git,.tox,.nox,dist,doc,releasenotes,*lib/python*,*egg,build diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 3543c94c..00000000 --- a/tox.ini +++ /dev/null @@ -1,42 +0,0 @@ -[tox] -envlist = linters,docs,py3 -ignore_basepython_conflict = true - -[testenv] -basepython = python3 -usedevelop = true -# See "testing behind a proxy" https://review.opendev.org/624496 -passenv = - http_proxy - https_proxy - # avoids potential slip-over of java 1.9 which breaks Gerrit, without it - # Gerrit may start with incompatible java version. - JAVA_HOME - # uncomment to allow custom java options to be added - # _JAVA_OPTIONS - TERM -commands = - python -m git_review.tests.check_test_id_hashes discover --list - python -m git_review.tests.prepare - stestr run --color {posargs} -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt - -[testenv:linters] -commands = flake8 - -[testenv:docs] -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/doc/requirements.txt -commands = - sphinx-build -W -d doc/build/doctrees -b html doc/source/ doc/build/html - -[testenv:venv] -commands = {posargs} - -[flake8] -ignore = E125,H202,H405,H904,W504 -show-source = true -exclude = .venv,.git,.tox,dist,doc,releasenotes,*lib/python*,*egg,build