From 023e446d7ae63494b41c9c3b1f3bfdfa70751abb Mon Sep 17 00:00:00 2001 From: Spacetown Date: Sat, 18 Sep 2021 00:07:10 +0200 Subject: [PATCH 01/10] Add noxfile.py for test. --- noxfile.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 noxfile.py diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..b7ce1fd33 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,87 @@ +import os +import sys +import nox +from nox import sessions +from nox.sessions import Session + +GCC_VERSIONS = ["gcc-5", "gcc-6", "gcc-8", "clang-10", "all"] +DEFAULT_TEST_DIRECTORIES = ["doc", "gcovr"] +BLACK_CONFORM_FILES = [ + "noxfile.py", + "gcovr/gcov.py", + "gcovr/gcov_parser.py", +] + +nox.options.sessions = ["lint", "doc", "tests(version='gcc-5')"] + + +@nox.session +def lint(session): + session.install("flake8", "black") + if session.posargs: + args = session.posargs + else: + args = DEFAULT_TEST_DIRECTORIES + session.run("flake8", *args) + + if session.posargs: + session.run("python", "-m", "black", *session.posargs) + else: + session.run( + "python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES + ) + session.run("python", "-m", "black", "--diff", *DEFAULT_TEST_DIRECTORIES) + + +@nox.session +def black(session): + session.install("black") + if session.posargs: + args = session.posargs + else: + args = "." + session.run("python", "-m", "black", *args) + + +@nox.session +def black(session): + session.install("black") + + +@nox.session +def doc(session): + session.install("-r", "requirements.txt") + session.install("-r", "doc/requirements.txt") + session.install("-e", ".") + session.run("bash", "-c", "cd doc && make html O=-W", external=True) + + +@nox.session +@nox.parametrize("version", GCC_VERSIONS) +def tests(session, version): + session.install("-r", "requirements.txt") + session.install("-e", ".") + if version == "all": + for version in GCC_VERSIONS: + if not version == "all": + tests(session, version) + else: + if os.environ.get("USE_COVERAGE") == "true": + args = ["--cov=gcovr", "--cov-branch"].append(args) + + session.env["GCOVR_TEST_SUITE"] = "1" + session.env["CC"] = version + session.env["CFLAGS"] = "--this_flag_does_not_exist" + session.env["CXX"] = version.replace("clang", "clang++").replace("gcc", "g++") + session.env["CXXFLAGS"] = "--this_flag_does_not_exist" + session.env["GCOV"] = version.replace("clang", "llvm-cov").replace( + "gcc", "gcov" + ) + session.run( + "bash", "-c", "cd gcovr/tests && make --silent clean", external=True + ) + args = ["-m", "pytest"] + args += session.posargs + if "--" not in args: + args += ["--", "gcovr", "doc/examples"] + session.run("python", *args) From 663b628322006605a5ebb79fd4eaf5f6dd031b8a Mon Sep 17 00:00:00 2001 From: Spacetown Date: Sun, 19 Sep 2021 21:23:52 +0200 Subject: [PATCH 02/10] Move docker to noxfile.py --- Makefile | 127 ----------------------------------- admin/Dockerfile.qa | 12 ++-- gcovr/tests/test_gcovr.py | 2 +- noxfile.py | 137 ++++++++++++++++++++++++++++---------- 4 files changed, 110 insertions(+), 168 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index dc6b270ce..000000000 --- a/Makefile +++ /dev/null @@ -1,127 +0,0 @@ -# This Makefile helps perform some developer tasks, like linting or testing. -# Run `make` or `make help` to see a list of tasks. - -# Override the environment variables to hide the values from the test drivers -unexport MFLAGS -unexport MAKEFLAGS - -# Set a variable if it's empty or provided by `make`. -# usage: $(call set_sensible_default, NAME, value) -set_sensible_default = $(if $(filter undefined default,$(origin $(1))),$(2),$(value $(1))) - -PYTHON := $(call set_sensible_default,PYTHON,python3) - -override AVAILABLE_CC := gcc-5 gcc-6 gcc-8 clang-10 all - -# Setting CXX and GCOV depending on CC. Only CC has to be set to a specific version. -# If using GitHub actions on Windows, gcc-8 is set but gcc is used, so we override it. -CC := $(call set_sensible_default,CC,gcc-5) -ifeq ($(filter $(CC),$(AVAILABLE_CC)),) -$(error Unsupported version of GCC used. CC must be one of: $(AVAILABLE_CC)) -endif -CXX := $(call set_sensible_default,CXX,$(subst clang,clang++,$(subst gcc,g++,$(CC)))) -GCOV := $(call set_sensible_default,GCOV,$(patsubst clang%,llvm-cov% gcov,$(subst gcc,gcov,$(CC)))) -ifneq ($(CC),all) -export CC := $(CC) -export CXX := $(CXX) -endif - -USERID := $(shell id -u $(USER)) -QA_CONTAINER ?= gcovr-qa-$(CC)-uid_$(USERID) -TEST_OPTS ?= -ifeq ($(USE_COVERAGE),true) -override TEST_OPTS += --cov=gcovr --cov-branch -endif - -RUN_ALL_COMPILERS = \ - $(foreach cc,$(filter-out all,$(AVAILABLE_CC)),$(MAKE) $@ CC=$(cc); )\ - echo "Running $@ for compiler versions ($(filter-out all,$(AVAILABLE_CC))) finished" - -.PHONY: help setup-dev qa lint test doc docker-qa docker-qa-build - -help: - @echo "select one of the following targets:" - @echo " help print this message" - @echo " setup-dev prepare a development environment" - @echo " qa run all QA tasks (lint, test, doc)" - @echo " lint run the flake8 linter" - @echo " test run all tests" - @echo " doc render the docs" - @echo " docker-qa run qa in the docker container" - @echo " docker-qa-build" - @echo " build the qa docker container" - @echo "" - @echo "environment variables:" - @echo " PYTHON Python executable to use [current: $(PYTHON)]" - @echo " CC, CXX, GCOV" - @echo " the gcc version to use [current: CC=$(CC) CXX=$(CXX) GCOV=$(GCOV)]" - @echo " Available are $(AVAILABLE_CC)," - @echo " all can only be used for qa and docker-qa." - @echo " TEST_OPTS additional flags for pytest [current: $(TEST_OPTS)]" - @echo " USE_COVERAGE if true extend TEST_OPTS with flags for generating coverage data" - @echo " QA_CONTAINER" - @echo " tag for the qa docker container [current: $(QA_CONTAINER)]" - -docker-qa: export TEST_OPTS := $(TEST_OPTS) -docker-qa: export GCOVR_ISOLATED_TEST := zkQEVaBpXF1i - -ifeq ($(CC),all) - -qa: - $(RUN_ALL_COMPILERS) - -docker-qa: - $(RUN_ALL_COMPILERS) - -else - -setup-dev: - $(PYTHON) -m pip install --upgrade pip - $(PYTHON) -m pip install -r requirements.txt -r doc/requirements.txt - $(PYTHON) -m pip install -e . - $(PYTHON) --version -ifeq ($(CI),true) -ifeq ($(shell which $(CC) 2>/dev/null),) - cd $(dir $(shell which gcc 2>/dev/null)) && cp -f gcc.exe $(CC).exe -endif - $(CC) --version -ifeq ($(shell which $(CXX) 2>/dev/null),) - cd $(dir $(shell which g++ 2>/dev/null)) && cp -f g++.exe $(CXX).exe -endif - $(CXX) --version -ifeq ($(shell which $(GCOV) 2>/dev/null),) - cd $(dir $(shell which gcov 2>/dev/null)) && cp -f gcov.exe $(GCOV).exe -endif -endif - $(GCOV) --version - -qa: doc lint check-format test - -lint: - $(PYTHON) -m flake8 doc gcovr - -check-format: - $(PYTHON) -m black --diff doc gcovr - -test: export GCOVR_TEST_SUITE := 1 -test: export CC := $(CC) -test: export CFLAGS := --this_flag_does_not_exist # Env removed in text_gcovr.py -test: export CXX := $(CXX) -test: export CXXFLAGS := --this_flag_does_not_exist # Env removed in text_gcovr.py -test: export GCOV := $(GCOV) - -test: - cd gcovr/tests && make --silent clean - $(PYTHON) -m pytest $(TEST_OPTS) -- gcovr doc/examples - -doc: - cd doc && make html O=-W - -docker-qa: | docker-qa-build - docker run --rm -e TEST_OPTS -e GCOVR_ISOLATED_TEST -v `pwd`:/gcovr $(QA_CONTAINER) - -docker-qa-build: admin/Dockerfile.qa requirements.txt doc/requirements.txt - docker build --tag $(QA_CONTAINER) \ - --build-arg USERID=$(USERID) \ - --build-arg CC=$(CC) --build-arg CXX=$(CXX) --file $< . -endif diff --git a/admin/Dockerfile.qa b/admin/Dockerfile.qa index ba2a52470..017a5fe6f 100644 --- a/admin/Dockerfile.qa +++ b/admin/Dockerfile.qa @@ -13,11 +13,11 @@ WORKDIR /gcovr COPY requirements.txt . COPY doc/requirements.txt doc/ -ENV PYTHON=python3 CC=$CC CXX=$CXX +ENV CC=$CC CXX=$CXX GCOVR_ISOLATED_TEST=zkQEVaBpXF1i RUN \ - $PYTHON -m pip install --no-cache-dir --upgrade pip && \ - $PYTHON -m pip install --no-cache-dir -r requirements.txt -r doc/requirements.txt + python3 -m pip install --no-cache-dir --upgrade pip && \ + python3 -m pip install --no-cache-dir nox # Create new user "docker" and set password to "docker" RUN addgroup docker @@ -30,6 +30,6 @@ USER docker:docker # Unicode is necessary for some tools like "black" to work. ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 -CMD ( echo docker | sudo -S -p "Running pip with sudo" $PYTHON -m pip install -e . ) && \ - ( echo docker | sudo -S -p "Running chmod with sudo" chown -R docker:docker /gcovr ) && \ - make qa +CMD ( echo docker | sudo -S -p "Running chmod with sudo" chown -R docker:docker /gcovr ) && \ + echo "" && \ + python3 -m nox diff --git a/gcovr/tests/test_gcovr.py b/gcovr/tests/test_gcovr.py index da2ad20b2..9fbad61c7 100644 --- a/gcovr/tests/test_gcovr.py +++ b/gcovr/tests/test_gcovr.py @@ -56,7 +56,7 @@ IS_CLANG = True if env["CC"].startswith("clang") else False -REFERENCE_DIR = os.path.join("reference", env["CC"]) +REFERENCE_DIR = os.path.join("reference", env.get("CC_REFERENCE", env["CC"])) RE_DECIMAL = re.compile(r"(\d+\.\d+)") diff --git a/noxfile.py b/noxfile.py index b7ce1fd33..3b83eb8e3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,10 +1,8 @@ import os -import sys +import shutil import nox -from nox import sessions -from nox.sessions import Session -GCC_VERSIONS = ["gcc-5", "gcc-6", "gcc-8", "clang-10", "all"] +GCC_VERSIONS = ["gcc-5", "gcc-6", "gcc-8", "clang-10"] DEFAULT_TEST_DIRECTORIES = ["doc", "gcovr"] BLACK_CONFORM_FILES = [ "noxfile.py", @@ -12,7 +10,36 @@ "gcovr/gcov_parser.py", ] -nox.options.sessions = ["lint", "doc", "tests(version='gcc-5')"] +nox.options.sessions = [ + "qa", + "lint", + "doc", + "tests(version='{}')".format(os.environ.get("CC", "gcc-5")), +] + + +def set_environment(session, cc, check=True): + if check and (shutil.which(cc) is None): + session.env["CC_REFERENCE"] = cc + cc = "gcc" + cxx = "g++" + gcov = "gcov" + else: + cxx = cc.replace("clang", "clang++").replace("gcc", "g++") + gcov = cc.replace("clang", "llvm-cov").replace("gcc", "gcov") + session.env["GCOVR_TEST_SUITE"] = "1" + session.env["CC"] = cc + session.env["CFLAGS"] = "--this_flag_does_not_exist" + session.env["CXX"] = cxx + session.env["CXXFLAGS"] = "--this_flag_does_not_exist" + session.env["GCOV"] = gcov + + +@nox.session +def qa(session): + for session_id in nox.options.sessions: + session.log("Notify session {}".format(session_id)) + session.notify(session_id) @nox.session @@ -43,11 +70,6 @@ def black(session): session.run("python", "-m", "black", *args) -@nox.session -def black(session): - session.install("black") - - @nox.session def doc(session): session.install("-r", "requirements.txt") @@ -61,27 +83,74 @@ def doc(session): def tests(session, version): session.install("-r", "requirements.txt") session.install("-e", ".") - if version == "all": - for version in GCC_VERSIONS: - if not version == "all": - tests(session, version) - else: - if os.environ.get("USE_COVERAGE") == "true": - args = ["--cov=gcovr", "--cov-branch"].append(args) - - session.env["GCOVR_TEST_SUITE"] = "1" - session.env["CC"] = version - session.env["CFLAGS"] = "--this_flag_does_not_exist" - session.env["CXX"] = version.replace("clang", "clang++").replace("gcc", "g++") - session.env["CXXFLAGS"] = "--this_flag_does_not_exist" - session.env["GCOV"] = version.replace("clang", "llvm-cov").replace( - "gcc", "gcov" - ) - session.run( - "bash", "-c", "cd gcovr/tests && make --silent clean", external=True - ) - args = ["-m", "pytest"] - args += session.posargs - if "--" not in args: - args += ["--", "gcovr", "doc/examples"] - session.run("python", *args) + set_environment(session, version) + session.run("bash", "-c", "cd gcovr/tests && make --silent clean", external=True) + args = ["-m", "pytest"] + if os.environ.get("USE_COVERAGE") == "true": + args += ["--cov=gcovr", "--cov-branch"] + args += session.posargs + if "--" not in args: + args += ["--", "gcovr", "doc/examples"] + session.run("python", *args) + + +@nox.session +def tests_all_versions(session): + for version in GCC_VERSIONS: + session_id = "tests(version='{}')".format(version) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + +@nox.session +@nox.parametrize("version", GCC_VERSIONS) +def docker_qa(session, version): + container_id = "gcovr-qa-{}".format(version) + set_environment(session, version, True) + session.run( + "bash", + "-c", + " ".join( + [ + "docker", + "build", + "--tag", + container_id, + "--build-arg", + "USERID={}".format(os.geteuid()), + "--build-arg", + "CC=${CC}", + "--build-arg", + "CXX=${CXX}", + "--file", + "admin/Dockerfile.qa", + ".", + ] + ), + external=True, + ) + session.run( + "bash", + "-c", + " ".join( + [ + "docker", + "run", + "--rm", + "-e", + "TESTOPTS", + "-v", + "{}:/gcovr".format(os.getcwd()), + container_id, + ] + ), + external=True, + ) + + +@nox.session +def docker_qa_all_versions(session): + for version in GCC_VERSIONS: + session_id = "docker_qa(version='{}')".format(version) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) From f82debce5fbeccb5b532d862daac20f3fe31f602 Mon Sep 17 00:00:00 2001 From: Spacetown Date: Sun, 19 Sep 2021 23:30:27 +0200 Subject: [PATCH 03/10] Update GitHub actions --- .github/workflows/deploy.yml | 9 ++-- .github/workflows/test.yml | 30 +++++------- noxfile.py | 95 +++++++++++++++++++++++++++++++----- 3 files changed, 100 insertions(+), 34 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5f3076c7c..cec63f7ca 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -44,16 +44,17 @@ jobs: uses: seanmiddleditch/gha-setup-ninja@master - name: Install dependencies run: | - make setup-dev PYTHON=python + python -m pip install --upgrade pip + python -m pip install nox wheel - name: Lint with flake8 run: | - make lint PYTHON=python + python -m nox --session lint - name: Test with pytest run: | - make test CC=$CC PYTHON=python + python -m nox --session "tests_version($CC)" - name: Generate documentation run: | - make doc PYTHON=python + python -m nox --session doc - name: Build run: | python setup.py sdist bdist_wheel diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d705c2e45..049235115 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -105,8 +105,7 @@ jobs: - name: Setup environment run: | echo "USE_COVERAGE=${{ ( ( matrix.os == 'windows-2019' ) && ( matrix.python-version == '3.7' ) ) || ( ( matrix.os == 'ubuntu-18.04' ) && ( matrix.gcc == 'gcc-6' ) && ( matrix.python-version == '3.8' ) ) }}" >> $GITHUB_ENV - echo "CC=${{ matrix.gcc }}" >> $GITHUB_ENV - echo "PYTHON=python" >> $GITHUB_ENV + echo "TEST_OPTS=--archive_differences" >> $GITHUB_ENV shell: bash - name: Install msys with GCC (Windows) if: ${{ startsWith(matrix.os,'windows-') }} @@ -130,31 +129,22 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Cache pip - uses: actions/cache@v2 - with: - # This path is specific to Ubuntu - path: ~/.cache/pip - # Look to see if there is a cache hit for the corresponding requirements file - key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt', 'doc/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- - name: Install dependencies run: | - make setup-dev + python3 -m pip install --upgrade pip + python3 -m pip install nox codecov - name: Lint files run: | - make lint + python3 -m nox --session lint - name: Check format of files if: ${{ ( matrix.python-version != 'pypy3' ) }} # Currently fail of this job is OK. continue-on-error: true run: | - make check-format + python -m nox --session black - name: Test with pytest run: | - make test TEST_OPTS="--archive_differences" + python -m nox --session "tests_version(${{ matrix.gcc }})" - name: Upload pytest test results if: ${{ failure() }} uses: actions/upload-artifact@v2 @@ -179,13 +169,17 @@ jobs: gcc: [gcc-5, gcc-6, gcc-8, clang-10] steps: + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install nox - uses: actions/checkout@v2 - name: Build Docker run: | - make docker-qa-build CC=${{ matrix.gcc }} + python3 -m nox --session "docker_qa_build_version(${{ matrix.gcc }})" - name: Run Docker run: | - make docker-qa TEST_OPTS="--archive_differences" CC=${{ matrix.gcc }} + python3 -m nox --session "docker_qa_run_version(${{ matrix.gcc }})" - name: Upload pytest test results if: ${{ failure() }} uses: actions/upload-artifact@v2 diff --git a/noxfile.py b/noxfile.py index 3b83eb8e3..edce60db2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -3,6 +3,7 @@ import nox GCC_VERSIONS = ["gcc-5", "gcc-6", "gcc-8", "clang-10"] +GCC_VERSION2USE = os.environ.get("CC", "gcc-5") DEFAULT_TEST_DIRECTORIES = ["doc", "gcovr"] BLACK_CONFORM_FILES = [ "noxfile.py", @@ -14,7 +15,7 @@ "qa", "lint", "doc", - "tests(version='{}')".format(os.environ.get("CC", "gcc-5")), + "tests_version({})".format(GCC_VERSION2USE), ] @@ -66,7 +67,7 @@ def black(session): if session.posargs: args = session.posargs else: - args = "." + raise RuntimeError("Please add the files to format as argument.") session.run("python", "-m", "black", *args) @@ -79,8 +80,23 @@ def doc(session): @nox.session -@nox.parametrize("version", GCC_VERSIONS) -def tests(session, version): +def tests(session): + session_id = "tests_version({})".format(GCC_VERSION2USE) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + +@nox.session +def tests_all_versions(session): + for version in GCC_VERSIONS: + session_id = "tests_version({})".format(version) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + +@nox.session +@nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) +def tests_version(session, version): session.install("-r", "requirements.txt") session.install("-e", ".") set_environment(session, version) @@ -94,18 +110,28 @@ def tests(session, version): session.run("python", *args) +def docker_container_id(version): + return "gcovr-qa-{}".format(version) + + @nox.session -def tests_all_versions(session): +def docker_qa_build(session): + session_id = "docker_qa__build_version({})".format(GCC_VERSION2USE) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + +@nox.session +def docker_qa_build_all_versions(session): for version in GCC_VERSIONS: - session_id = "tests(version='{}')".format(version) + session_id = "docker_qa_build_version({})".format(version) session.log("Notify session {}".format(session_id)) session.notify(session_id) @nox.session -@nox.parametrize("version", GCC_VERSIONS) -def docker_qa(session, version): - container_id = "gcovr-qa-{}".format(version) +@nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) +def docker_qa_build_version(session, version): set_environment(session, version, True) session.run( "bash", @@ -115,7 +141,7 @@ def docker_qa(session, version): "docker", "build", "--tag", - container_id, + docker_container_id(version), "--build-arg", "USERID={}".format(os.geteuid()), "--build-arg", @@ -129,6 +155,27 @@ def docker_qa(session, version): ), external=True, ) + + +@nox.session +def docker_qa_run(session): + session_id = "docker_qa_run_version({})".format(GCC_VERSION2USE) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + +@nox.session +def docker_qa_run_all_versions(session): + for version in GCC_VERSIONS: + session_id = "docker_qa_run_version({})".format(version) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + +@nox.session +@nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) +def docker_qa_run_version(session, version): + set_environment(session, version, True) session.run( "bash", "-c", @@ -141,16 +188,40 @@ def docker_qa(session, version): "TESTOPTS", "-v", "{}:/gcovr".format(os.getcwd()), - container_id, + docker_container_id(version), ] ), external=True, ) +@nox.session +def docker_qa(session): + session_id = "docker_qa_build_version({})".format(GCC_VERSION2USE) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + session_id = "docker_qa_run_version({})".format(GCC_VERSION2USE) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + @nox.session def docker_qa_all_versions(session): for version in GCC_VERSIONS: - session_id = "docker_qa(version='{}')".format(version) + session_id = "docker_qa_build_version({})".format(version) session.log("Notify session {}".format(session_id)) session.notify(session_id) + session_id = "docker_qa_run_version({})".format(version) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + + +@nox.session +@nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) +def docker_qa_version(session, version): + session_id = "docker_qa_build_version({})".format(version) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) + session_id = "docker_qa_run_version({})".format(version) + session.log("Notify session {}".format(session_id)) + session.notify(session_id) From 695673f0ae706a69a020e9f8f7367f992b706ea9 Mon Sep 17 00:00:00 2001 From: Spacetown Date: Mon, 20 Sep 2021 22:14:59 +0200 Subject: [PATCH 04/10] Update docs. --- CHANGELOG.rst | 1 + CONTRIBUTING.rst | 94 ++++++++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0518f7dc4..f17ff9e1b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -28,6 +28,7 @@ Internal changes: - New parser for ``.gcov`` file format, should be more robust. (:issue:`512`) - Add option to run all comiler versions at once. (:issue:`514`) - Fix globing of reference data in tests. (:issue:`533`) + - Replace makefile for starting tests with noxfile.py. (:issue:`516`) 5.0 (11 June 2021) ------------------ diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index ed78f1825..5d91cddc7 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -71,7 +71,7 @@ Please follow this checklist for your pull request: - **Does it work?** Please run the tests locally:: - make test + python3 -m nox (see also: :ref:`test suite`) @@ -92,13 +92,13 @@ Please follow this checklist for your pull request: The source code should conform to the :pep:`8` standard. Please check your code:: - make lint + python3 -m nox --session lint # or: - python3 -m flake8 doc gcovr --ignore E501,W503 + python3 -m flake8 doc gcovr - The command ``make qa`` will run the linter, run the tests, + The command ``python3 -m nox`` will run the linter, run the tests, and check that the docs can be built. - **Add yourself as an author.** @@ -145,8 +145,8 @@ How to set up a development environment For working on gcovr, you will need a supported version of Python 3, GCC version 5, 6 or 8 (other GCC versions are supported by gcovr, -but will cause spurious test failures), ``make``, ``cmake`` and -``ninja``. +but will cause spurious test failures) or clang version 10, ``make``, +``cmake`` and ``ninja``. Please make sure that the tools are in the system ``PATH``. On **Windows**, you will need to install a GCC toolchain as the tests expect a Unix-like environment. You can use MinGW-W64 or MinGW. @@ -180,26 +180,15 @@ is needed. - (Optional) Set up a virtualenv (e.g. with ``python3 -m venv my-venv``) -- Install gcovr in development mode, and install the test requirements:: - - make setup-dev # install all test + doc dependencies - - # or: +- Install gcovr in development mode, and install nox:: pip install -e . - pip install -r requirements.txt + pip install nox You can then run gcovr as ``gcovr`` or ``python3 -m gcovr``. Run the tests to verify that everything works (see :ref:`test suite`). -- (Optional) Install documentation requirements:: - - # would be already done by `make setup-dev` - pip install -r doc/requirements.txt - - See ``doc/README.txt`` for details on working with the documentation. - - (Optional) Activate GitHub Actions for your forked repository, so that the cross-platform compatibility tests get run whenever you push your work to your repository. @@ -224,6 +213,7 @@ Path Description ``/gcovr/__main__.py`` command line interface + top-level behaviour ``/gcovr/templates/`` HTML report templates ``/gcovr/tests/`` unit tests + integration test corpus +``/noxfile.py`` Definition of tests tasks ``/setup.py`` Python package configuration ``/doc/`` documentation ``/doc/sources/`` user guide + website @@ -240,28 +230,29 @@ are in ``gcovr.generator.html`` and respective modules. Test suite ---------- -The QA process (``make qa``) consists of multiple parts: - -- linting (``make lint``) +The QA process (``python3 -m nox``) consists of multiple parts: -- checking format (``make check-format``) +- linting and checking format(``python3 -m nox --session lint``) -- tests (``make test``) +- tests (``python3 -m nox --session tests``) - unit tests in ``gcovr/tests`` - integration tests in ``gcovr/tests`` - documentation examples in ``doc/examples`` -- documentation build (``make doc``) +- documentation build (``python3 -m nox --session doc``) The tests are in the ``gcovr/tests`` directory. -You can run the tests with ``make test`` or ``python3 -m pytest -- gcovr doc/examples``. +You can run the tests with ``python3 -m nox --session tests_version($CC)``. There are unit tests for some parts of gcovr, and a comprehensive corpus of example projects that are executed as the ``test_gcovr.py`` integration test. Each ``gcovr/tests/*`` directory is one such example project. +You can format files with ``python3 -m nox --session black FileToFormat``) +`` + The next sections discuss the :ref:`structure of integration tests `, how to :ref:`run and filter tests `, @@ -308,34 +299,38 @@ Each Makefile contains the following targets: Run and filter tests ~~~~~~~~~~~~~~~~~~~~ -To run all tests, use ``make test`` or ``make qa``. +To run all tests, use ``python3 -m nox``. The tests currently assume that you are using GCC 5 and have set up a :ref:`development environment `. -You can select a different GCC version by setting the CC argument. +You can select a different GCC version by setting the CC environment variable. Supported versions are ``CC=gcc-5``, ``CC=gcc-6``, ``CC=gcc-8`` and ``clang-10``. -You can run the tests with additional options by setting ``TEST_OPTS`` variable. -Run all tests after each change is a bit slow, therefore you can limit the tests -to a specific test file, example project, or output format. +You can run the tests with additional options by setting the environment variable +``TEST_OPTS``. Run all tests after each change is a bit slow, therefore you can +limit the tests to a specific test file, example project, or output format. For example: .. code:: bash # run only XML tests - make test TEST_OPTS="-k 'xml'" + export TEST_OPTS="-k 'xml'" + python3 -m nox --session tests # run the simple1 tests - make test TEST_OPTS="-k 'simple1'" + export TEST_OPTS="-k 'simple1'" + python3 -m nox --session tests # run the simple1 tests only for XML - make test TEST_OPTS="-k 'xml and simple1'" + export TEST_OPTS="-k 'xml and simple1'" + python3 -m nox --session tests To see which tests would be run, add the ``--collect-only`` option: .. code:: bash #see which tests would be run - make test TEST_OPTS="--collect-only" + export TEST_OPTS="--collect-only" + python3 -m nox --session tests Sometimes during development you need to create reference files for new test or update the current reference files. To do this you have to @@ -348,13 +343,16 @@ For example: .. code:: bash # run tests and generate references for simple1 example - make test TEST_OPTS="-k 'simple1' --generate_reference" + export TEST_OPTS="-k 'simple1' --generate_reference" + python3 -m nox --session tests # run tests and update xml references for simple1 example - make test TEST_OPTS="-k 'xml and simple1' --update_reference" + export TEST_OPTS="-k 'xml and simple1' --update_reference" + python3 -m nox --session tests # run only XML tests and do not remove generated files - make test TEST_OPTS="-k 'xml' --skip_clean" + export TEST_OPTS="-k 'xml' --skip_clean" + python3 -m nox --session tests When the currently generated output reports differ to the reference files you can create a ZIP archive named ``diff.zip`` in the tests directory @@ -365,7 +363,11 @@ with the differences as an artifact. .. code:: bash # run tests and generate a ZIP archive when there were differences - make test TEST_OPTS="--archive_differences" + export TEST_OPTS="--archive_differences" + python3 -m nox --session tests + +.. versionchanged:: NEXT + Change how to start test from ``make test`` to ``python3 -m nox --session test`` .. versionadded:: 5.0 Added test options `--generate_reference`, `--update_reference`, @@ -382,15 +384,21 @@ First, build the container image: .. code:: bash - make docker-qa-build + python3 -m nox --session docker_qa_build + +Then, run the container, which executes ``python3 -m nox`` within the container: + +.. code:: bash + + python3 -m nox --session docker_qa_run -Then, run the container, which executes ``make qa`` within the container: +Or to build and run the container in one step: .. code:: bash - make docker-qa + python3 -m nox --session docker_qa -You can select the gcc version to use inside the docker by setting the make +You can select the gcc version to use inside the docker by setting the environment variable CC to gcc-5 (default), gcc-6, gcc-8 or clang-10 .. _join: From a9528d7d4ea40216adc827bc07c3e69fa848fd48 Mon Sep 17 00:00:00 2001 From: Spacetown Date: Tue, 21 Sep 2021 22:08:54 +0200 Subject: [PATCH 05/10] Move building of wheel to noxfile.py Remove requirements.txt --- .github/workflows/deploy.yml | 7 +++---- admin/Dockerfile.qa | 2 -- doc/README.txt | 2 +- noxfile.py | 30 ++++++++++++++++++++++++------ requirements.txt | 13 ------------- 5 files changed, 28 insertions(+), 26 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cec63f7ca..89ffb3df6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -45,7 +45,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install nox wheel + python -m pip install nox - name: Lint with flake8 run: | python -m nox --session lint @@ -57,8 +57,7 @@ jobs: python -m nox --session doc - name: Build run: | - python setup.py sdist bdist_wheel - twine check dist/* + python -m nox --session build_wheel - name: Upload distribution if: ${{ success() }} uses: actions/upload-artifact@v2 @@ -71,4 +70,4 @@ jobs: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - twine upload dist/* + python -m nox --session upload_wheel diff --git a/admin/Dockerfile.qa b/admin/Dockerfile.qa index 017a5fe6f..ec9f5c7fc 100644 --- a/admin/Dockerfile.qa +++ b/admin/Dockerfile.qa @@ -10,8 +10,6 @@ RUN \ apt-get clean WORKDIR /gcovr -COPY requirements.txt . -COPY doc/requirements.txt doc/ ENV CC=$CC CXX=$CXX GCOVR_ISOLATED_TEST=zkQEVaBpXF1i diff --git a/doc/README.txt b/doc/README.txt index d6c3af863..63c21a04e 100644 --- a/doc/README.txt +++ b/doc/README.txt @@ -3,7 +3,7 @@ sphinx. The necessary python packages have to be installed, e.g. with pip: - pip install -r requirements.txt + pip install nox The command diff --git a/noxfile.py b/noxfile.py index edce60db2..4853d70ff 100644 --- a/noxfile.py +++ b/noxfile.py @@ -51,13 +51,11 @@ def lint(session): else: args = DEFAULT_TEST_DIRECTORIES session.run("flake8", *args) - + if session.posargs: session.run("python", "-m", "black", *session.posargs) else: - session.run( - "python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES - ) + session.run("python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES) session.run("python", "-m", "black", "--diff", *DEFAULT_TEST_DIRECTORIES) @@ -73,7 +71,6 @@ def black(session): @nox.session def doc(session): - session.install("-r", "requirements.txt") session.install("-r", "doc/requirements.txt") session.install("-e", ".") session.run("bash", "-c", "cd doc && make html O=-W", external=True) @@ -97,7 +94,15 @@ def tests_all_versions(session): @nox.session @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) def tests_version(session, version): - session.install("-r", "requirements.txt") + session.install( + "jinja2", + "lxml", + "pygments == 2.7.4", + "pytest", + "pytest-cov", + "cmake", + "yaxmldiff", + ) session.install("-e", ".") set_environment(session, version) session.run("bash", "-c", "cd gcovr/tests && make --silent clean", external=True) @@ -110,6 +115,19 @@ def tests_version(session, version): session.run("python", *args) +@nox.session +def build_wheel(session): + session.install("wheel", "twine") + session.run("python", "setup.py", "sdist", "bdist_wheel") + session.run("twine", "check", "dist/*", external=True) + + +@nox.session +def upload_wheel(session): + session.install("twine") + session.run("twine", "upload", "dist/*", external=True) + + def docker_container_id(version): return "gcovr-qa-{}".format(version) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8084f9efd..000000000 --- a/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -black; implementation_name == "cpython" -cmake -codecov -coverage -flake8 -jinja2 -lxml -pygments == 2.7.4 -pytest -pytest-cov -twine -wheel -yaxmldiff From 6c97c576f247e4a74f5269ee47dcc2f04de42ccf Mon Sep 17 00:00:00 2001 From: Spacetown Date: Tue, 21 Sep 2021 22:27:26 +0200 Subject: [PATCH 06/10] Fix CI errors. Remove doc/requirements.txt --- .editorconfig | 1 + .github/workflows/deploy.yml | 9 ++-- .github/workflows/test.yml | 12 ++--- admin/Dockerfile.qa | 3 +- doc/requirements.txt | 4 -- noxfile.py | 98 ++++++++++++++++++++++++------------ 6 files changed, 76 insertions(+), 51 deletions(-) delete mode 100644 doc/requirements.txt diff --git a/.editorconfig b/.editorconfig index f3f205471..e803b0fd7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,7 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true +# for the makefiles use tabs [Makefile] indent_style = tab diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 89ffb3df6..c42380bbd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -44,20 +44,19 @@ jobs: uses: seanmiddleditch/gha-setup-ninja@master - name: Install dependencies run: | - python -m pip install --upgrade pip python -m pip install nox - name: Lint with flake8 run: | - python -m nox --session lint + python -m nox --non-interactive --session lint - name: Test with pytest run: | - python -m nox --session "tests_version($CC)" + python -m nox --non-interactive --session "tests_version($CC)" - name: Generate documentation run: | - python -m nox --session doc + python -m nox --non-interactive --session doc - name: Build run: | - python -m nox --session build_wheel + python -m nox --non-interactive --session build_wheel - name: Upload distribution if: ${{ success() }} uses: actions/upload-artifact@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 049235115..b74c8afca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -131,20 +131,19 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python3 -m pip install --upgrade pip python3 -m pip install nox codecov - name: Lint files run: | - python3 -m nox --session lint + python3 -m nox --non-interactive --session lint - name: Check format of files if: ${{ ( matrix.python-version != 'pypy3' ) }} # Currently fail of this job is OK. continue-on-error: true run: | - python -m nox --session black + python -m nox --non-interactive --session black - name: Test with pytest run: | - python -m nox --session "tests_version(${{ matrix.gcc }})" + python -m nox --non-interactive --session "tests_version(${{ matrix.gcc }})" - name: Upload pytest test results if: ${{ failure() }} uses: actions/upload-artifact@v2 @@ -171,15 +170,14 @@ jobs: steps: - name: Install dependencies run: | - python3 -m pip install --upgrade pip python3 -m pip install nox - uses: actions/checkout@v2 - name: Build Docker run: | - python3 -m nox --session "docker_qa_build_version(${{ matrix.gcc }})" + python3 -m nox --non-interactive --session "docker_qa_build_version(${{ matrix.gcc }})" - name: Run Docker run: | - python3 -m nox --session "docker_qa_run_version(${{ matrix.gcc }})" + python3 -m nox --non-interactive --session "docker_qa_run_version(${{ matrix.gcc }})" - name: Upload pytest test results if: ${{ failure() }} uses: actions/upload-artifact@v2 diff --git a/admin/Dockerfile.qa b/admin/Dockerfile.qa index ec9f5c7fc..7491399c3 100644 --- a/admin/Dockerfile.qa +++ b/admin/Dockerfile.qa @@ -14,7 +14,6 @@ WORKDIR /gcovr ENV CC=$CC CXX=$CXX GCOVR_ISOLATED_TEST=zkQEVaBpXF1i RUN \ - python3 -m pip install --no-cache-dir --upgrade pip && \ python3 -m pip install --no-cache-dir nox # Create new user "docker" and set password to "docker" @@ -30,4 +29,4 @@ ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 CMD ( echo docker | sudo -S -p "Running chmod with sudo" chown -R docker:docker /gcovr ) && \ echo "" && \ - python3 -m nox + python3 -m nox --non-interactive diff --git a/doc/requirements.txt b/doc/requirements.txt deleted file mode 100644 index 6da1ceef8..000000000 --- a/doc/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -sphinx -sphinx_rtd_theme -sphinxcontrib-autoprogram == 0.1.5 ; python_version == "3.6" -sphinxcontrib-autoprogram >= 0.1.5 ; python_version >= "3.7" diff --git a/noxfile.py b/noxfile.py index 4853d70ff..bdb498dde 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,4 +1,5 @@ import os +import platform import shutil import nox @@ -19,7 +20,7 @@ ] -def set_environment(session, cc, check=True): +def set_environment(session: "nox.session", cc: str, check: bool = True) -> None: if check and (shutil.which(cc) is None): session.env["CC_REFERENCE"] = cc cc = "gcc" @@ -27,7 +28,10 @@ def set_environment(session, cc, check=True): gcov = "gcov" else: cxx = cc.replace("clang", "clang++").replace("gcc", "g++") - gcov = cc.replace("clang", "llvm-cov").replace("gcc", "gcov") + if cc.startswith("clang"): + gcov = cc.replace("clang", "llvm-cov") + " gcov" + else: + gcov = cc.replace("gcc", "gcov") session.env["GCOVR_TEST_SUITE"] = "1" session.env["CC"] = cc session.env["CFLAGS"] = "--this_flag_does_not_exist" @@ -37,30 +41,37 @@ def set_environment(session, cc, check=True): @nox.session -def qa(session): +def qa(session: "nox.session") -> None: for session_id in nox.options.sessions: session.log("Notify session {}".format(session_id)) session.notify(session_id) @nox.session -def lint(session): - session.install("flake8", "black") +def lint(session: "nox.session") -> None: + session.install("flake8") + if platform.python_implementation() == "CPython": + session.install("black") if session.posargs: args = session.posargs else: args = DEFAULT_TEST_DIRECTORIES session.run("flake8", *args) - if session.posargs: - session.run("python", "-m", "black", *session.posargs) + if platform.python_implementation() == "CPython": + if session.posargs: + session.run("python", "-m", "black", *session.posargs) + else: + session.run( + "python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES + ) + session.run("python", "-m", "black", "--diff", *DEFAULT_TEST_DIRECTORIES) else: - session.run("python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES) - session.run("python", "-m", "black", "--diff", *DEFAULT_TEST_DIRECTORIES) + session.log(f"Skip black because of platform {platform.python_implementation()}.") @nox.session -def black(session): +def black(session: "nox.session") -> None: session.install("black") if session.posargs: args = session.posargs @@ -70,21 +81,26 @@ def black(session): @nox.session -def doc(session): - session.install("-r", "doc/requirements.txt") +def doc(session: "nox.session") -> None: + session.install( + "sphinx", + "sphinx_rtd_theme", + "sphinxcontrib-autoprogram==0.1.5 ; python_version=='3.6'", + "sphinxcontrib-autoprogram>=0.1.5 ; python_version>='3.7'", + ) session.install("-e", ".") session.run("bash", "-c", "cd doc && make html O=-W", external=True) @nox.session -def tests(session): +def tests(session: "nox.session") -> None: session_id = "tests_version({})".format(GCC_VERSION2USE) session.log("Notify session {}".format(session_id)) session.notify(session_id) @nox.session -def tests_all_versions(session): +def tests_all_versions(session: "nox.session") -> None: for version in GCC_VERSIONS: session_id = "tests_version({})".format(version) session.log("Notify session {}".format(session_id)) @@ -93,22 +109,36 @@ def tests_all_versions(session): @nox.session @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def tests_version(session, version): +def tests_version(session: "nox.session", version: str) -> None: session.install( "jinja2", "lxml", - "pygments == 2.7.4", + "pygments==2.7.4", "pytest", - "pytest-cov", "cmake", "yaxmldiff", ) + coverage_args = [] + if os.environ.get("USE_COVERAGE") == "true": + session.install("pytest-cov") + coverage_args = ["--cov=gcovr", "--cov-branch"] session.install("-e", ".") set_environment(session, version) + session.log("Print tool versions") + session.run("python", "--version") + session.run(session.env["CC"], "--version", external=True) + session.run(session.env["CXX"], "--version", external=True) + session.run( + session.env["GCOV"].replace(" gcov", "") + if "llvm-cov" in session.env["GCOV"] + else session.env["GCOV"], + "--version", + external=True, + ) + session.run("bash", "-c", "cd gcovr/tests && make --silent clean", external=True) args = ["-m", "pytest"] - if os.environ.get("USE_COVERAGE") == "true": - args += ["--cov=gcovr", "--cov-branch"] + args += coverage_args args += session.posargs if "--" not in args: args += ["--", "gcovr", "doc/examples"] @@ -116,31 +146,31 @@ def tests_version(session, version): @nox.session -def build_wheel(session): +def build_wheel(session: "nox.session") -> None: session.install("wheel", "twine") session.run("python", "setup.py", "sdist", "bdist_wheel") session.run("twine", "check", "dist/*", external=True) @nox.session -def upload_wheel(session): +def upload_wheel(session: "nox.session") -> None: session.install("twine") session.run("twine", "upload", "dist/*", external=True) -def docker_container_id(version): +def docker_container_id(version: str) -> None: return "gcovr-qa-{}".format(version) @nox.session -def docker_qa_build(session): +def docker_qa_build(session: "nox.session") -> None: session_id = "docker_qa__build_version({})".format(GCC_VERSION2USE) session.log("Notify session {}".format(session_id)) session.notify(session_id) @nox.session -def docker_qa_build_all_versions(session): +def docker_qa_build_all_versions(session: "nox.session") -> None: for version in GCC_VERSIONS: session_id = "docker_qa_build_version({})".format(version) session.log("Notify session {}".format(session_id)) @@ -149,8 +179,8 @@ def docker_qa_build_all_versions(session): @nox.session @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_build_version(session, version): - set_environment(session, version, True) +def docker_qa_build_version(session: "nox.session", version: str) -> None: + set_environment(session, version, False) session.run( "bash", "-c", @@ -176,14 +206,14 @@ def docker_qa_build_version(session, version): @nox.session -def docker_qa_run(session): +def docker_qa_run(session: "nox.session") -> None: session_id = "docker_qa_run_version({})".format(GCC_VERSION2USE) session.log("Notify session {}".format(session_id)) session.notify(session_id) @nox.session -def docker_qa_run_all_versions(session): +def docker_qa_run_all_versions(session: "nox.session") -> None: for version in GCC_VERSIONS: session_id = "docker_qa_run_version({})".format(version) session.log("Notify session {}".format(session_id)) @@ -192,8 +222,8 @@ def docker_qa_run_all_versions(session): @nox.session @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_run_version(session, version): - set_environment(session, version, True) +def docker_qa_run_version(session: "nox.session", version: str) -> None: + set_environment(session, version, False) session.run( "bash", "-c", @@ -204,6 +234,8 @@ def docker_qa_run_version(session, version): "--rm", "-e", "TESTOPTS", + "-e", + "CC", "-v", "{}:/gcovr".format(os.getcwd()), docker_container_id(version), @@ -214,7 +246,7 @@ def docker_qa_run_version(session, version): @nox.session -def docker_qa(session): +def docker_qa(session: "nox.session") -> None: session_id = "docker_qa_build_version({})".format(GCC_VERSION2USE) session.log("Notify session {}".format(session_id)) session.notify(session_id) @@ -224,7 +256,7 @@ def docker_qa(session): @nox.session -def docker_qa_all_versions(session): +def docker_qa_all_versions(session: "nox.session") -> None: for version in GCC_VERSIONS: session_id = "docker_qa_build_version({})".format(version) session.log("Notify session {}".format(session_id)) @@ -236,7 +268,7 @@ def docker_qa_all_versions(session): @nox.session @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_version(session, version): +def docker_qa_version(session: "nox.session", version: str) -> None: session_id = "docker_qa_build_version({})".format(version) session.log("Notify session {}".format(session_id)) session.notify(session_id) From 1035d9c7d7c32aaab06ee4788469ab9112654b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=C3=B6rderer?= Date: Thu, 23 Sep 2021 06:34:00 +0200 Subject: [PATCH 07/10] Make black happy. --- gcovr/gcov.py | 8 ++++---- noxfile.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gcovr/gcov.py b/gcovr/gcov.py index 3651431de..328cf71ce 100644 --- a/gcovr/gcov.py +++ b/gcovr/gcov.py @@ -28,7 +28,9 @@ from .gcov_parser import parse_metadata, parse_coverage, ParserFlags output_re = re.compile(r"[Cc]reating [`'](.*)'$") -source_re = re.compile(r"(?:[Cc](?:annot|ould not) open (?:source|graph|output) file|: No such file or directory)") +source_re = re.compile( + r"(?:[Cc](?:annot|ould not) open (?:source|graph|output) file|: No such file or directory)" +) unknown_cla_re = re.compile(r"Unknown command line argument") exclude_line_flag = "_EXCL_" @@ -442,9 +444,7 @@ def run_gcov_and_process_files( return done -def select_gcov_files_from_stdout( - out, gcov_filter, gcov_exclude, logger, chdir -): +def select_gcov_files_from_stdout(out, gcov_filter, gcov_exclude, logger, chdir): active_files = [] all_files = [] diff --git a/noxfile.py b/noxfile.py index bdb498dde..943ba635a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -67,7 +67,9 @@ def lint(session: "nox.session") -> None: ) session.run("python", "-m", "black", "--diff", *DEFAULT_TEST_DIRECTORIES) else: - session.log(f"Skip black because of platform {platform.python_implementation()}.") + session.log( + f"Skip black because of platform {platform.python_implementation()}." + ) @nox.session From 527f185862345c9ebd76227050f297f76ed624c9 Mon Sep 17 00:00:00 2001 From: Spacetown Date: Tue, 14 Dec 2021 16:32:15 +0100 Subject: [PATCH 08/10] Add review remarks. --- .github/workflows/deploy.yml | 10 +- .github/workflows/test.yml | 11 +- .gitignore | 2 + CONTRIBUTING.rst | 37 +++--- admin/Dockerfile.qa | 6 +- doc/requirements.txt | 4 + noxfile.py | 237 ++++++++++++++++++----------------- 7 files changed, 154 insertions(+), 153 deletions(-) create mode 100644 doc/requirements.txt diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c42380bbd..dd6b4bc45 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,7 +20,7 @@ jobs: - name: Run release_checklist run: | admin/release_checklist 5.0 - + deploy: runs-on: ubuntu-18.04 needs: release-check @@ -47,16 +47,16 @@ jobs: python -m pip install nox - name: Lint with flake8 run: | - python -m nox --non-interactive --session lint + nox --non-interactive --session lint - name: Test with pytest run: | - python -m nox --non-interactive --session "tests_version($CC)" + nox --non-interactive --session "tests_compiler($CC)" - name: Generate documentation run: | - python -m nox --non-interactive --session doc + nox --non-interactive --session doc - name: Build run: | - python -m nox --non-interactive --session build_wheel + nox --non-interactive --session build_wheel - name: Upload distribution if: ${{ success() }} uses: actions/upload-artifact@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b74c8afca..1656566af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -105,7 +105,6 @@ jobs: - name: Setup environment run: | echo "USE_COVERAGE=${{ ( ( matrix.os == 'windows-2019' ) && ( matrix.python-version == '3.7' ) ) || ( ( matrix.os == 'ubuntu-18.04' ) && ( matrix.gcc == 'gcc-6' ) && ( matrix.python-version == '3.8' ) ) }}" >> $GITHUB_ENV - echo "TEST_OPTS=--archive_differences" >> $GITHUB_ENV shell: bash - name: Install msys with GCC (Windows) if: ${{ startsWith(matrix.os,'windows-') }} @@ -134,16 +133,16 @@ jobs: python3 -m pip install nox codecov - name: Lint files run: | - python3 -m nox --non-interactive --session lint + nox --non-interactive --session lint - name: Check format of files if: ${{ ( matrix.python-version != 'pypy3' ) }} # Currently fail of this job is OK. continue-on-error: true run: | - python -m nox --non-interactive --session black + nox --non-interactive --session black - name: Test with pytest run: | - python -m nox --non-interactive --session "tests_version(${{ matrix.gcc }})" + nox --non-interactive --session "tests_compiler(${{ matrix.gcc }})" -- --archive_differences - name: Upload pytest test results if: ${{ failure() }} uses: actions/upload-artifact@v2 @@ -174,10 +173,10 @@ jobs: - uses: actions/checkout@v2 - name: Build Docker run: | - python3 -m nox --non-interactive --session "docker_qa_build_version(${{ matrix.gcc }})" + python3 -m nox --non-interactive --session "docker_qa_build_compiler(${{ matrix.gcc }})" - name: Run Docker run: | - python3 -m nox --non-interactive --session "docker_qa_run_version(${{ matrix.gcc }})" + python3 -m nox --non-interactive --session "docker_qa_run_compiler(${{ matrix.gcc }})" - name: Upload pytest test results if: ${{ failure() }} uses: actions/upload-artifact@v2 diff --git a/.gitignore b/.gitignore index a8b6f3bd0..7bfd4d9b7 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,8 @@ gcovr-*/ # VS Code .vscode +*.code-workspace # PyCharm .idea + diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 5d91cddc7..81a9d3a21 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -243,7 +243,10 @@ The QA process (``python3 -m nox``) consists of multiple parts: - documentation build (``python3 -m nox --session doc``) The tests are in the ``gcovr/tests`` directory. -You can run the tests with ``python3 -m nox --session tests_version($CC)``. +You can run the tests with ``python3 -m nox --session tests`` +for the default GCC version (used from environment ``CC``iv availabele, else gcc-5. +You can also select the gcc version if you run the tests with e.g. +``python3 -m nox --session tests_compiler(gcc-8)``. There are unit tests for some parts of gcovr, and a comprehensive corpus of example projects @@ -305,54 +308,47 @@ and have set up a :ref:`development environment `. You can select a different GCC version by setting the CC environment variable. Supported versions are ``CC=gcc-5``, ``CC=gcc-6``, ``CC=gcc-8`` and ``clang-10``. -You can run the tests with additional options by setting the environment variable -``TEST_OPTS``. Run all tests after each change is a bit slow, therefore you can +You can run the tests with additional options by adding ``--`` and then the options +to the test invocation. Run all tests after each change is a bit slow, therefore you can limit the tests to a specific test file, example project, or output format. For example: .. code:: bash # run only XML tests - export TEST_OPTS="-k 'xml'" - python3 -m nox --session tests + python3 -m nox --session tests -- -k 'xml' # run the simple1 tests - export TEST_OPTS="-k 'simple1'" - python3 -m nox --session tests + python3 -m nox --session tests -- -k 'simple1' # run the simple1 tests only for XML - export TEST_OPTS="-k 'xml and simple1'" - python3 -m nox --session tests + python3 -m nox --session tests -- -k 'xml and simple1' To see which tests would be run, add the ``--collect-only`` option: .. code:: bash #see which tests would be run - export TEST_OPTS="--collect-only" - python3 -m nox --session tests + python3 -m nox --session tests -- --collect-only Sometimes during development you need to create reference files for new test or update the current reference files. To do this you have to add ``--generate_reference`` or ``--update-reference`` option -to the ``TEST_OPTS`` variable. +to the test invocation. By default generated output files are automatically removed after test run. -To skip this process you can add ``--skip_clean`` option the ``TEST_OPTS``. +To skip this process you can add ``--skip_clean`` option the test invocation. For example: .. code:: bash # run tests and generate references for simple1 example - export TEST_OPTS="-k 'simple1' --generate_reference" - python3 -m nox --session tests + python3 -m nox --session tests -- -k 'simple1' --generate_reference # run tests and update xml references for simple1 example - export TEST_OPTS="-k 'xml and simple1' --update_reference" - python3 -m nox --session tests + python3 -m nox --session tests -- -k 'xml and simple1' --update_reference # run only XML tests and do not remove generated files - export TEST_OPTS="-k 'xml' --skip_clean" - python3 -m nox --session tests + python3 -m nox --session tests -- -k 'xml' --skip_clean When the currently generated output reports differ to the reference files you can create a ZIP archive named ``diff.zip`` in the tests directory @@ -363,8 +359,7 @@ with the differences as an artifact. .. code:: bash # run tests and generate a ZIP archive when there were differences - export TEST_OPTS="--archive_differences" - python3 -m nox --session tests + python3 -m nox --session tests -- --archive_differences .. versionchanged:: NEXT Change how to start test from ``make test`` to ``python3 -m nox --session test`` diff --git a/admin/Dockerfile.qa b/admin/Dockerfile.qa index 7491399c3..7a23624de 100644 --- a/admin/Dockerfile.qa +++ b/admin/Dockerfile.qa @@ -27,6 +27,6 @@ USER docker:docker # Unicode is necessary for some tools like "black" to work. ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 -CMD ( echo docker | sudo -S -p "Running chmod with sudo" chown -R docker:docker /gcovr ) && \ - echo "" && \ - python3 -m nox --non-interactive +CMD ( echo docker | sudo -S -p "Running chmod with sudo..." chown -R docker:docker /gcovr/gcovr ) && \ + echo "\ndone\nStarting test..." && \ + python3 -m nox --envdir /tmp/envs --non-interactive diff --git a/doc/requirements.txt b/doc/requirements.txt new file mode 100644 index 000000000..6da1ceef8 --- /dev/null +++ b/doc/requirements.txt @@ -0,0 +1,4 @@ +sphinx +sphinx_rtd_theme +sphinxcontrib-autoprogram == 0.1.5 ; python_version == "3.6" +sphinxcontrib-autoprogram >= 0.1.5 ; python_version >= "3.7" diff --git a/noxfile.py b/noxfile.py index 943ba635a..fcb1a00a3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,6 +1,7 @@ import os import platform import shutil +import shlex import nox GCC_VERSIONS = ["gcc-5", "gcc-6", "gcc-8", "clang-10"] @@ -12,15 +13,11 @@ "gcovr/gcov_parser.py", ] -nox.options.sessions = [ - "qa", - "lint", - "doc", - "tests_version({})".format(GCC_VERSION2USE), -] + +nox.options.sessions = ["qa"] -def set_environment(session: "nox.session", cc: str, check: bool = True) -> None: +def set_environment(session: nox.session, cc: str, check: bool = True) -> None: if check and (shutil.which(cc) is None): session.env["CC_REFERENCE"] = cc cc = "gcc" @@ -40,16 +37,25 @@ def set_environment(session: "nox.session", cc: str, check: bool = True) -> None session.env["GCOV"] = gcov -@nox.session -def qa(session: "nox.session") -> None: - for session_id in nox.options.sessions: - session.log("Notify session {}".format(session_id)) - session.notify(session_id) +@nox.session(python=False) +def qa(session: nox.session) -> None: + """Run the quality tests.""" + session_id = "lint" + session.log(f"Notify session {session_id}") + session.notify(session_id, []) + session_id = "doc" + session.log(f"Notify session {session_id}") + session.notify(session_id, []) + session_id = f"tests_compiler({GCC_VERSION2USE})" + session.log(f"Notify session {session_id}") + session.notify(session_id) @nox.session -def lint(session: "nox.session") -> None: +def lint(session: nox.session) -> None: + """Run the lint (flake8 and black).""" session.install("flake8") + # Black installs under Pypy but doesn't necessarily run (cf psf/black#2559). if platform.python_implementation() == "CPython": session.install("black") if session.posargs: @@ -73,7 +79,8 @@ def lint(session: "nox.session") -> None: @nox.session -def black(session: "nox.session") -> None: +def black(session: nox.session) -> None: + """Run black, a code formatter and format checker.""" session.install("black") if session.posargs: args = session.posargs @@ -83,35 +90,35 @@ def black(session: "nox.session") -> None: @nox.session -def doc(session: "nox.session") -> None: - session.install( - "sphinx", - "sphinx_rtd_theme", - "sphinxcontrib-autoprogram==0.1.5 ; python_version=='3.6'", - "sphinxcontrib-autoprogram>=0.1.5 ; python_version>='3.7'", - ) +def doc(session: nox.session) -> None: + """Generate the documentation.""" + session.install("-r", "doc/requirements.txt") session.install("-e", ".") - session.run("bash", "-c", "cd doc && make html O=-W", external=True) + session.chdir("doc") + session.run("make", "html", "O=-W", external=True) -@nox.session -def tests(session: "nox.session") -> None: - session_id = "tests_version({})".format(GCC_VERSION2USE) - session.log("Notify session {}".format(session_id)) +@nox.session(python=False) +def tests(session: nox.session) -> None: + """Run the tests with the default GCC version.""" + session_id = f"tests_compiler({GCC_VERSION2USE})" + session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session -def tests_all_versions(session: "nox.session") -> None: +@nox.session(python=False) +def tests_all_compiler(session: nox.session) -> None: + """Run the tests with all GCC versions.""" for version in GCC_VERSIONS: - session_id = "tests_version({})".format(version) - session.log("Notify session {}".format(session_id)) + session_id = f"tests_compiler({version})" + session.log(f"Notify session {session_id}") session.notify(session_id) @nox.session @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def tests_version(session: "nox.session", version: str) -> None: +def tests_compiler(session: nox.session, version: str) -> None: + """Run the test with a specifiv GCC version.""" session.install( "jinja2", "lxml", @@ -130,150 +137,144 @@ def tests_version(session: "nox.session", version: str) -> None: session.run("python", "--version") session.run(session.env["CC"], "--version", external=True) session.run(session.env["CXX"], "--version", external=True) - session.run( - session.env["GCOV"].replace(" gcov", "") - if "llvm-cov" in session.env["GCOV"] - else session.env["GCOV"], - "--version", - external=True, - ) + session.run(*shlex.split(session.env["GCOV"]), "--version", external=True) - session.run("bash", "-c", "cd gcovr/tests && make --silent clean", external=True) + session.chdir("gcovr/tests") + session.run("make", "--silent", "clean", external=True) + session.chdir("../..") args = ["-m", "pytest"] args += coverage_args args += session.posargs + # For docker tests + if "NOX_POSARGS" in os.environ: + args += shlex.split(os.environ["NOX_POSARGS"]) if "--" not in args: args += ["--", "gcovr", "doc/examples"] session.run("python", *args) @nox.session -def build_wheel(session: "nox.session") -> None: +def build_wheel(session: nox.session) -> None: + """Build a wheel.""" session.install("wheel", "twine") session.run("python", "setup.py", "sdist", "bdist_wheel") session.run("twine", "check", "dist/*", external=True) @nox.session -def upload_wheel(session: "nox.session") -> None: +def upload_wheel(session: nox.session) -> None: + """Upload the wheel.""" session.install("twine") session.run("twine", "upload", "dist/*", external=True) -def docker_container_id(version: str) -> None: - return "gcovr-qa-{}".format(version) +def docker_container_id(version: str) -> str: + """Get the docker container ID.""" + return f"gcovr-qa-{version}-uid_{os.geteuid()}" -@nox.session -def docker_qa_build(session: "nox.session") -> None: - session_id = "docker_qa__build_version({})".format(GCC_VERSION2USE) - session.log("Notify session {}".format(session_id)) +@nox.session(python=False) +def docker_qa_build(session: nox.session) -> None: + """Build the docker container for the default GCC version.""" + session_id = f"docker_qa_build_compiler({GCC_VERSION2USE})" + session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session -def docker_qa_build_all_versions(session: "nox.session") -> None: +@nox.session(python=False) +def docker_qa_build_all_compiler(session: nox.session) -> None: + """Build the docker containers vor all GCC versions.""" for version in GCC_VERSIONS: - session_id = "docker_qa_build_version({})".format(version) - session.log("Notify session {}".format(session_id)) + session_id = f"docker_qa_build_compiler({version})" + session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session +@nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_build_version(session: "nox.session", version: str) -> None: +def docker_qa_build_compiler(session: nox.session, version: str) -> None: + """Build the docker container for a specific GCC version.""" set_environment(session, version, False) session.run( - "bash", - "-c", - " ".join( - [ - "docker", - "build", - "--tag", - docker_container_id(version), - "--build-arg", - "USERID={}".format(os.geteuid()), - "--build-arg", - "CC=${CC}", - "--build-arg", - "CXX=${CXX}", - "--file", - "admin/Dockerfile.qa", - ".", - ] - ), + "docker", + "build", + "--tag", + docker_container_id(version), + "--build-arg", + f"USERID={os.geteuid()}", + "--build-arg", + f"CC={session.env['CC']}", + "--build-arg", + f"CXX={session.env['CXX']}", + "--file", + "admin/Dockerfile.qa", + ".", external=True, ) -@nox.session -def docker_qa_run(session: "nox.session") -> None: - session_id = "docker_qa_run_version({})".format(GCC_VERSION2USE) - session.log("Notify session {}".format(session_id)) +@nox.session(python=False) +def docker_qa_run(session: nox.session) -> None: + """Run the docker container for the default GCC version.""" + session_id = f"docker_qa_run_compiler({GCC_VERSION2USE})" + session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session -def docker_qa_run_all_versions(session: "nox.session") -> None: +@nox.session(python=False) +def docker_qa_run_all_compiler(session: nox.session) -> None: + """Run the docker container for the all GCC versions.""" for version in GCC_VERSIONS: - session_id = "docker_qa_run_version({})".format(version) - session.log("Notify session {}".format(session_id)) + session_id = f"docker_qa_run_compiler({version})" + session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session +@nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_run_version(session: "nox.session", version: str) -> None: +def docker_qa_run_compiler(session: nox.session, version: str) -> None: + """Run the docker container for a specific GCC version.""" set_environment(session, version, False) + session.env["NOX_POSARGS"] = " ".join([repr(a) for a in session.posargs]) session.run( - "bash", - "-c", - " ".join( - [ - "docker", - "run", - "--rm", - "-e", - "TESTOPTS", - "-e", - "CC", - "-v", - "{}:/gcovr".format(os.getcwd()), - docker_container_id(version), - ] - ), + "docker", + "run", + "--rm", + "-e", + "CC", + "-e", + "NOX_POSARGS", + "-v", + f"{os.getcwd()}:/gcovr", + docker_container_id(version), external=True, ) -@nox.session -def docker_qa(session: "nox.session") -> None: - session_id = "docker_qa_build_version({})".format(GCC_VERSION2USE) - session.log("Notify session {}".format(session_id)) - session.notify(session_id) - session_id = "docker_qa_run_version({})".format(GCC_VERSION2USE) - session.log("Notify session {}".format(session_id)) +@nox.session(python=False) +def docker_qa(session: nox.session) -> None: + """Build and run the docker container for the default GCC version.""" + session_id = f"docker_qa_compiler({GCC_VERSION2USE})" + session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session -def docker_qa_all_versions(session: "nox.session") -> None: +@nox.session(python=False) +def docker_qa_all_compiler(session: nox.session) -> None: + """Build and run the docker container for the all GCC versions.""" for version in GCC_VERSIONS: - session_id = "docker_qa_build_version({})".format(version) - session.log("Notify session {}".format(session_id)) - session.notify(session_id) - session_id = "docker_qa_run_version({})".format(version) - session.log("Notify session {}".format(session_id)) + session_id = f"docker_qa_compiler({version})" + session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session +@nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_version(session: "nox.session", version: str) -> None: - session_id = "docker_qa_build_version({})".format(version) - session.log("Notify session {}".format(session_id)) +def docker_qa_compiler(session: nox.session, version: str) -> None: + """Build and run the docker container for a specific GCC version.""" + session_id = "docker_qa_build_compiler({})".format(version) + session.log(f"Notify session {session_id}") session.notify(session_id) - session_id = "docker_qa_run_version({})".format(version) - session.log("Notify session {}".format(session_id)) + session_id = f"docker_qa_run_compiler({version})" + session.log(f"Notify session {session_id}") session.notify(session_id) From fd987c30357c154843c7f101548ddd94d0a75126 Mon Sep 17 00:00:00 2001 From: Spacetown Date: Wed, 15 Dec 2021 21:09:56 +0100 Subject: [PATCH 09/10] Add review remarks part II. Co-authored-by: Lukas Atkinson --- .github/workflows/deploy.yml | 9 +++++++ .github/workflows/test.yml | 15 ++++++----- CONTRIBUTING.rst | 2 +- admin/Dockerfile.qa | 4 +-- doc/README.txt | 8 +++++- noxfile.py | 52 ++++++++++++++++++------------------ 6 files changed, 54 insertions(+), 36 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dd6b4bc45..46107b0a1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -35,6 +35,15 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ env.PYTHON_VERSION }} + - name: Cache pip + uses: actions/cache@v2 + with: + # This path is specific to Ubuntu + path: ~/.cache/pip + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-pip-${{ hashFiles('noxfile.py', 'doc/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- - name: Install GCC run: | sudo apt update diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1656566af..33087fc12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -128,18 +128,21 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Cache pip + uses: actions/cache@v2 + with: + # This path is specific to Ubuntu + path: ~/.cache/pip + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-pip-${{ hashFiles('noxfile.py', 'doc/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- - name: Install dependencies run: | python3 -m pip install nox codecov - name: Lint files run: | nox --non-interactive --session lint - - name: Check format of files - if: ${{ ( matrix.python-version != 'pypy3' ) }} - # Currently fail of this job is OK. - continue-on-error: true - run: | - nox --non-interactive --session black - name: Test with pytest run: | nox --non-interactive --session "tests_compiler(${{ matrix.gcc }})" -- --archive_differences diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 81a9d3a21..0f2cc99ac 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -244,7 +244,7 @@ The QA process (``python3 -m nox``) consists of multiple parts: The tests are in the ``gcovr/tests`` directory. You can run the tests with ``python3 -m nox --session tests`` -for the default GCC version (used from environment ``CC``iv availabele, else gcc-5. +for the default GCC version (specified via ``CC`` environment variable, defaults to gcc-5). You can also select the gcc version if you run the tests with e.g. ``python3 -m nox --session tests_compiler(gcc-8)``. diff --git a/admin/Dockerfile.qa b/admin/Dockerfile.qa index 7a23624de..59d25b845 100644 --- a/admin/Dockerfile.qa +++ b/admin/Dockerfile.qa @@ -11,7 +11,7 @@ RUN \ WORKDIR /gcovr -ENV CC=$CC CXX=$CXX GCOVR_ISOLATED_TEST=zkQEVaBpXF1i +ENV CC=$CC CXX=$CXX GCOVR_ISOLATED_TEST=zkQEVaBpXF1i NOX_ENV_DIR=/gcovr/.nox-containerized.$CC.uid_$USERID RUN \ python3 -m pip install --no-cache-dir nox @@ -29,4 +29,4 @@ ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 CMD ( echo docker | sudo -S -p "Running chmod with sudo..." chown -R docker:docker /gcovr/gcovr ) && \ echo "\ndone\nStarting test..." && \ - python3 -m nox --envdir /tmp/envs --non-interactive + python3 -m nox --envdir $NOX_ENV_DIR --non-interactive diff --git a/doc/README.txt b/doc/README.txt index 63c21a04e..d68b86456 100644 --- a/doc/README.txt +++ b/doc/README.txt @@ -3,7 +3,7 @@ sphinx. The necessary python packages have to be installed, e.g. with pip: - pip install nox + pip install -r requirements.txt The command @@ -11,6 +11,12 @@ The command creates the documentation in the folder build/html. +If you're using nox you can alos call: + + nox -s doc + +This will install the reuirements in a virtual environment and run the make process. + When updating for a new gcovr version, the screenshots will have to be regenerated. If you have wkhtmltopdf installed, run diff --git a/noxfile.py b/noxfile.py index fcb1a00a3..03383ec0c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -17,7 +17,7 @@ nox.options.sessions = ["qa"] -def set_environment(session: nox.session, cc: str, check: bool = True) -> None: +def set_environment(session: nox.Session, cc: str, check: bool = True) -> None: if check and (shutil.which(cc) is None): session.env["CC_REFERENCE"] = cc cc = "gcc" @@ -38,7 +38,7 @@ def set_environment(session: nox.session, cc: str, check: bool = True) -> None: @nox.session(python=False) -def qa(session: nox.session) -> None: +def qa(session: nox.Session) -> None: """Run the quality tests.""" session_id = "lint" session.log(f"Notify session {session_id}") @@ -52,7 +52,7 @@ def qa(session: nox.session) -> None: @nox.session -def lint(session: nox.session) -> None: +def lint(session: nox.Session) -> None: """Run the lint (flake8 and black).""" session.install("flake8") # Black installs under Pypy but doesn't necessarily run (cf psf/black#2559). @@ -66,12 +66,10 @@ def lint(session: nox.session) -> None: if platform.python_implementation() == "CPython": if session.posargs: - session.run("python", "-m", "black", *session.posargs) - else: session.run( "python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES ) - session.run("python", "-m", "black", "--diff", *DEFAULT_TEST_DIRECTORIES) + session.run("python", "-m", "black", "--diff", *args) else: session.log( f"Skip black because of platform {platform.python_implementation()}." @@ -79,18 +77,20 @@ def lint(session: nox.session) -> None: @nox.session -def black(session: nox.session) -> None: +def black(session: nox.Session) -> None: """Run black, a code formatter and format checker.""" session.install("black") if session.posargs: - args = session.posargs + session.run("python", "-m", "black", *session.posargs) else: - raise RuntimeError("Please add the files to format as argument.") - session.run("python", "-m", "black", *args) + session.run( + "python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES + ) + session.run("python", "-m", "black", "--diff", *DEFAULT_TEST_DIRECTORIES) @nox.session -def doc(session: nox.session) -> None: +def doc(session: nox.Session) -> None: """Generate the documentation.""" session.install("-r", "doc/requirements.txt") session.install("-e", ".") @@ -99,7 +99,7 @@ def doc(session: nox.session) -> None: @nox.session(python=False) -def tests(session: nox.session) -> None: +def tests(session: nox.Session) -> None: """Run the tests with the default GCC version.""" session_id = f"tests_compiler({GCC_VERSION2USE})" session.log(f"Notify session {session_id}") @@ -107,7 +107,7 @@ def tests(session: nox.session) -> None: @nox.session(python=False) -def tests_all_compiler(session: nox.session) -> None: +def tests_all_compiler(session: nox.Session) -> None: """Run the tests with all GCC versions.""" for version in GCC_VERSIONS: session_id = f"tests_compiler({version})" @@ -117,7 +117,7 @@ def tests_all_compiler(session: nox.session) -> None: @nox.session @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def tests_compiler(session: nox.session, version: str) -> None: +def tests_compiler(session: nox.Session, version: str) -> None: """Run the test with a specifiv GCC version.""" session.install( "jinja2", @@ -154,7 +154,7 @@ def tests_compiler(session: nox.session, version: str) -> None: @nox.session -def build_wheel(session: nox.session) -> None: +def build_wheel(session: nox.Session) -> None: """Build a wheel.""" session.install("wheel", "twine") session.run("python", "setup.py", "sdist", "bdist_wheel") @@ -162,7 +162,7 @@ def build_wheel(session: nox.session) -> None: @nox.session -def upload_wheel(session: nox.session) -> None: +def upload_wheel(session: nox.Session) -> None: """Upload the wheel.""" session.install("twine") session.run("twine", "upload", "dist/*", external=True) @@ -174,7 +174,7 @@ def docker_container_id(version: str) -> str: @nox.session(python=False) -def docker_qa_build(session: nox.session) -> None: +def docker_qa_build(session: nox.Session) -> None: """Build the docker container for the default GCC version.""" session_id = f"docker_qa_build_compiler({GCC_VERSION2USE})" session.log(f"Notify session {session_id}") @@ -182,7 +182,7 @@ def docker_qa_build(session: nox.session) -> None: @nox.session(python=False) -def docker_qa_build_all_compiler(session: nox.session) -> None: +def docker_qa_build_all_compiler(session: nox.Session) -> None: """Build the docker containers vor all GCC versions.""" for version in GCC_VERSIONS: session_id = f"docker_qa_build_compiler({version})" @@ -192,7 +192,7 @@ def docker_qa_build_all_compiler(session: nox.session) -> None: @nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_build_compiler(session: nox.session, version: str) -> None: +def docker_qa_build_compiler(session: nox.Session, version: str) -> None: """Build the docker container for a specific GCC version.""" set_environment(session, version, False) session.run( @@ -214,7 +214,7 @@ def docker_qa_build_compiler(session: nox.session, version: str) -> None: @nox.session(python=False) -def docker_qa_run(session: nox.session) -> None: +def docker_qa_run(session: nox.Session) -> None: """Run the docker container for the default GCC version.""" session_id = f"docker_qa_run_compiler({GCC_VERSION2USE})" session.log(f"Notify session {session_id}") @@ -222,7 +222,7 @@ def docker_qa_run(session: nox.session) -> None: @nox.session(python=False) -def docker_qa_run_all_compiler(session: nox.session) -> None: +def docker_qa_run_all_compiler(session: nox.Session) -> None: """Run the docker container for the all GCC versions.""" for version in GCC_VERSIONS: session_id = f"docker_qa_run_compiler({version})" @@ -232,10 +232,10 @@ def docker_qa_run_all_compiler(session: nox.session) -> None: @nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_run_compiler(session: nox.session, version: str) -> None: +def docker_qa_run_compiler(session: nox.Session, version: str) -> None: """Run the docker container for a specific GCC version.""" set_environment(session, version, False) - session.env["NOX_POSARGS"] = " ".join([repr(a) for a in session.posargs]) + session.env["NOX_POSARGS"] = shlex.join(session.posargs) session.run( "docker", "run", @@ -252,7 +252,7 @@ def docker_qa_run_compiler(session: nox.session, version: str) -> None: @nox.session(python=False) -def docker_qa(session: nox.session) -> None: +def docker_qa(session: nox.Session) -> None: """Build and run the docker container for the default GCC version.""" session_id = f"docker_qa_compiler({GCC_VERSION2USE})" session.log(f"Notify session {session_id}") @@ -260,7 +260,7 @@ def docker_qa(session: nox.session) -> None: @nox.session(python=False) -def docker_qa_all_compiler(session: nox.session) -> None: +def docker_qa_all_compiler(session: nox.Session) -> None: """Build and run the docker container for the all GCC versions.""" for version in GCC_VERSIONS: session_id = f"docker_qa_compiler({version})" @@ -270,7 +270,7 @@ def docker_qa_all_compiler(session: nox.session) -> None: @nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_compiler(session: nox.session, version: str) -> None: +def docker_qa_compiler(session: nox.Session, version: str) -> None: """Build and run the docker container for a specific GCC version.""" session_id = "docker_qa_build_compiler({})".format(version) session.log(f"Notify session {session_id}") From df6e35ea241ae8a4a047ad1a266ddef173dc69c6 Mon Sep 17 00:00:00 2001 From: Spacetown Date: Wed, 15 Dec 2021 21:36:01 +0100 Subject: [PATCH 10/10] Use shlex.join for Python >= 3.8 --- noxfile.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 03383ec0c..870972bd8 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,6 +2,7 @@ import platform import shutil import shlex +import sys import nox GCC_VERSIONS = ["gcc-5", "gcc-6", "gcc-8", "clang-10"] @@ -235,7 +236,11 @@ def docker_qa_run_all_compiler(session: nox.Session) -> None: def docker_qa_run_compiler(session: nox.Session, version: str) -> None: """Run the docker container for a specific GCC version.""" set_environment(session, version, False) - session.env["NOX_POSARGS"] = shlex.join(session.posargs) + if sys.version_info >= (3, 8): + session.env["NOX_POSARGS"] = shlex.join(session.posargs) + else: + # Code for join taken from Python 3.9 + session.env["NOX_POSARGS"] = ' '.join(shlex.quote(arg) for arg in session.posargs) session.run( "docker", "run",