From 6a79a04d15959adfa87af27bd384dccdcc7dac18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=C3=B6rderer?= Date: Wed, 15 Dec 2021 21:45:40 +0100 Subject: [PATCH] Add nox to run test and environment (#516) * Add noxfile.py for test. * Move building of wheel to noxfile.py * Update GitHub actions Co-authored-by: Lukas Atkinson --- .editorconfig | 1 + .github/workflows/deploy.yml | 24 ++- .github/workflows/test.yml | 24 ++- .gitignore | 2 + CHANGELOG.rst | 1 + CONTRIBUTING.rst | 93 ++++++------ Makefile | 127 ---------------- admin/Dockerfile.qa | 13 +- doc/README.txt | 6 + gcovr/gcov.py | 8 +- gcovr/tests/test_gcovr.py | 2 +- noxfile.py | 285 +++++++++++++++++++++++++++++++++++ requirements.txt | 13 -- 13 files changed, 378 insertions(+), 221 deletions(-) delete mode 100644 Makefile create mode 100644 noxfile.py delete mode 100644 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 5f3076c7c..46107b0a1 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 @@ -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 @@ -44,20 +53,19 @@ jobs: uses: seanmiddleditch/gha-setup-ninja@master - name: Install dependencies run: | - make setup-dev PYTHON=python + python -m pip install nox - name: Lint with flake8 run: | - make lint PYTHON=python + nox --non-interactive --session lint - name: Test with pytest run: | - make test CC=$CC PYTHON=python + nox --non-interactive --session "tests_compiler($CC)" - name: Generate documentation run: | - make doc PYTHON=python + nox --non-interactive --session doc - name: Build run: | - python setup.py sdist bdist_wheel - twine check dist/* + nox --non-interactive --session build_wheel - name: Upload distribution if: ${{ success() }} uses: actions/upload-artifact@v2 @@ -70,4 +78,4 @@ jobs: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - twine upload dist/* + python -m nox --session upload_wheel diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d705c2e45..33087fc12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -105,8 +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 "CC=${{ matrix.gcc }}" >> $GITHUB_ENV - echo "PYTHON=python" >> $GITHUB_ENV shell: bash - name: Install msys with GCC (Windows) if: ${{ startsWith(matrix.os,'windows-') }} @@ -136,25 +134,18 @@ jobs: # 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') }} + key: ${{ runner.os }}-pip-${{ hashFiles('noxfile.py', 'doc/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - ${{ runner.os }}- - name: Install dependencies run: | - make setup-dev + python3 -m pip install nox codecov - name: Lint files run: | - make 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 + nox --non-interactive --session lint - name: Test with pytest run: | - make test TEST_OPTS="--archive_differences" + nox --non-interactive --session "tests_compiler(${{ matrix.gcc }})" -- --archive_differences - name: Upload pytest test results if: ${{ failure() }} uses: actions/upload-artifact@v2 @@ -179,13 +170,16 @@ jobs: gcc: [gcc-5, gcc-6, gcc-8, clang-10] steps: + - name: Install dependencies + run: | + python3 -m pip install nox - uses: actions/checkout@v2 - name: Build Docker run: | - make docker-qa-build CC=${{ matrix.gcc }} + python3 -m nox --non-interactive --session "docker_qa_build_compiler(${{ matrix.gcc }})" - name: Run Docker run: | - make docker-qa TEST_OPTS="--archive_differences" CC=${{ 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/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..0f2cc99ac 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,32 @@ 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`` +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)``. 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,53 +302,53 @@ 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 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 - make test TEST_OPTS="-k 'xml'" + python3 -m nox --session tests -- -k 'xml' # run the simple1 tests - make test TEST_OPTS="-k 'simple1'" + python3 -m nox --session tests -- -k 'simple1' # run the simple1 tests only for XML - make test TEST_OPTS="-k 'xml and simple1'" + 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 - make test TEST_OPTS="--collect-only" + 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 - make test TEST_OPTS="-k 'simple1' --generate_reference" + python3 -m nox --session tests -- -k 'simple1' --generate_reference # run tests and update xml references for simple1 example - make test TEST_OPTS="-k 'xml and simple1' --update_reference" + python3 -m nox --session tests -- -k 'xml and simple1' --update_reference # run only XML tests and do not remove generated files - make test TEST_OPTS="-k 'xml' --skip_clean" + 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 @@ -365,7 +359,10 @@ 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" + python3 -m nox --session tests -- --archive_differences + +.. 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 +379,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: 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..59d25b845 100644 --- a/admin/Dockerfile.qa +++ b/admin/Dockerfile.qa @@ -10,14 +10,11 @@ RUN \ apt-get clean 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 NOX_ENV_DIR=/gcovr/.nox-containerized.$CC.uid_$USERID 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 nox # Create new user "docker" and set password to "docker" RUN addgroup docker @@ -30,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 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/gcovr ) && \ + echo "\ndone\nStarting test..." && \ + python3 -m nox --envdir $NOX_ENV_DIR --non-interactive diff --git a/doc/README.txt b/doc/README.txt index d6c3af863..d68b86456 100644 --- a/doc/README.txt +++ b/doc/README.txt @@ -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/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/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 new file mode 100644 index 000000000..870972bd8 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,285 @@ +import os +import platform +import shutil +import shlex +import sys +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", + "gcovr/gcov.py", + "gcovr/gcov_parser.py", +] + + +nox.options.sessions = ["qa"] + + +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" + cxx = "g++" + gcov = "gcov" + else: + cxx = cc.replace("clang", "clang++").replace("gcc", "g++") + 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" + session.env["CXX"] = cxx + session.env["CXXFLAGS"] = "--this_flag_does_not_exist" + session.env["GCOV"] = gcov + + +@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: + """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: + args = session.posargs + else: + args = DEFAULT_TEST_DIRECTORIES + session.run("flake8", *args) + + if platform.python_implementation() == "CPython": + if session.posargs: + session.run( + "python", "-m", "black", "--diff", "--check", *BLACK_CONFORM_FILES + ) + session.run("python", "-m", "black", "--diff", *args) + else: + session.log( + f"Skip black because of platform {platform.python_implementation()}." + ) + + +@nox.session +def black(session: nox.Session) -> None: + """Run black, a code formatter and format checker.""" + session.install("black") + 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 doc(session: nox.Session) -> None: + """Generate the documentation.""" + session.install("-r", "doc/requirements.txt") + session.install("-e", ".") + session.chdir("doc") + session.run("make", "html", "O=-W", external=True) + + +@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(python=False) +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})" + 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_compiler(session: nox.Session, version: str) -> None: + """Run the test with a specifiv GCC version.""" + session.install( + "jinja2", + "lxml", + "pygments==2.7.4", + "pytest", + "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(*shlex.split(session.env["GCOV"]), "--version", 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: + """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: + """Upload the wheel.""" + session.install("twine") + session.run("twine", "upload", "dist/*", external=True) + + +def docker_container_id(version: str) -> str: + """Get the docker container ID.""" + return f"gcovr-qa-{version}-uid_{os.geteuid()}" + + +@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(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 = f"docker_qa_build_compiler({version})" + session.log(f"Notify session {session_id}") + session.notify(session_id) + + +@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: + """Build the docker container for a specific GCC version.""" + set_environment(session, version, False) + session.run( + "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(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(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 = f"docker_qa_run_compiler({version})" + session.log(f"Notify session {session_id}") + session.notify(session_id) + + +@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: + """Run the docker container for a specific GCC version.""" + set_environment(session, version, False) + 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", + "--rm", + "-e", + "CC", + "-e", + "NOX_POSARGS", + "-v", + f"{os.getcwd()}:/gcovr", + docker_container_id(version), + external=True, + ) + + +@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(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 = f"docker_qa_compiler({version})" + session.log(f"Notify session {session_id}") + session.notify(session_id) + + +@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: + """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 = f"docker_qa_run_compiler({version})" + session.log(f"Notify session {session_id}") + session.notify(session_id) 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