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}")