From c957053ec2969f1508a3975b7fde19341492a88e Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Sat, 26 Dec 2020 17:18:30 +0100 Subject: [PATCH 01/11] Add codecov --- .coveragerc | 8 ++++++++ .github/workflows/ci.yml | 3 +++ .ycm_extra_conf.py | 2 ++ CMakeLists.txt | 4 ++++ codecov.yml | 12 ++++++++++++ tests/CMakeLists.txt | 1 + tests/requirements.txt | 3 +++ 7 files changed, 33 insertions(+) create mode 100644 .coveragerc create mode 100644 .ycm_extra_conf.py create mode 100644 codecov.yml diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000000..432fc5dff0 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,8 @@ +[run] +parallel = True +source = + tests + +[paths] +source = + tests/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e67c8f924..a85634547f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,6 +115,9 @@ jobs: - name: Interface test C++11 run: cmake --build . --target test_cmake_build + - name: codecov + run: CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} codecov --name testing_testing_one_two_3 + - name: Clean directory run: git clean -fdx diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py new file mode 100644 index 0000000000..6fe0bd7cdb --- /dev/null +++ b/.ycm_extra_conf.py @@ -0,0 +1,2 @@ +def Settings(**kwargs): + return { 'flags': ['-xc++', '-std=c++20', '-isystem/usr/include/python3.9'] } diff --git a/CMakeLists.txt b/CMakeLists.txt index ded4dad9c9..ab0f4fb151 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,10 @@ else() cmake_policy(VERSION 3.18) endif() +if(NOT MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage") +endif() + # Extract project version from source file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h" pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ") diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..be9a17bfa6 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,12 @@ +codecov: + notify: + after_n_builds: 1 + +coverage: + precision: 2 + round: down + range: 70...100 + +comment: + layout: "header, diff, changes, uncovered" + behavior: default # update if exists else create new diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3bfd5f1cae..0dca10f6f2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -389,6 +389,7 @@ set(PYBIND11_TEST_PREFIX_COMMAND add_custom_target( pytest COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest + --cov=pybind11 ${PYBIND11_ABS_PYTEST_FILES} DEPENDS ${test_targets} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" diff --git a/tests/requirements.txt b/tests/requirements.txt index 0b383bf5c3..d90d02e2c1 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -7,3 +7,6 @@ pytest==6.1.2; python_version=="3.5" pytest==6.2.1; python_version>="3.6" scipy==1.2.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version<"3.6" scipy==1.5.4; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10" +codecov>=2.0.5 +pytest-cov +coverage>=4.2 From ce8656c634fb82bc08f2b77d16bbd6c25cea4c90 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Tue, 12 Jan 2021 21:55:12 +0100 Subject: [PATCH 02/11] Name the uploads --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a85634547f..bf3adf5ead 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,7 +116,7 @@ jobs: run: cmake --build . --target test_cmake_build - name: codecov - run: CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} codecov --name testing_testing_one_two_3 + run: CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} codecov --name ${{ matrix.python }}-${{ matrix.runs-on }}-${{ matrix.args }} - name: Clean directory run: git clean -fdx From b53ca5c46cd96cee4a4a556e3e003cdd7a5a4e3b Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Wed, 13 Jan 2021 01:22:27 +0100 Subject: [PATCH 03/11] Install python3-pytest-cov --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf3adf5ead..b74d9c9134 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -276,7 +276,7 @@ jobs: - uses: actions/checkout@v2 - name: Add wget and python3 - run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev + run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev python3-pytest-cov - name: Configure shell: bash @@ -311,7 +311,7 @@ jobs: # tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND - name: Install 🐍 3 - run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-numpy + run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-numpy python3-pytest-cov - name: Configure run: cmake -S . -B build -DPYBIND11_CUDA_TESTS=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON @@ -334,7 +334,7 @@ jobs: # - uses: actions/checkout@v2 # # - name: Add Python 3 and a few requirements -# run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules +# run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules python3-pytest-cov # # - name: Install CMake with pip # run: | @@ -438,7 +438,7 @@ jobs: - uses: actions/checkout@v1 - name: Add Python 3 - run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev + run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev python3-pytest-cov - name: Update pip run: python3 -m pip install --upgrade pip From 812542103d740418269a9c6861d9d6c8ca9747bc Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Wed, 13 Jan 2021 01:38:57 +0100 Subject: [PATCH 04/11] Fix builds --- tests/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0dca10f6f2..e6553ba534 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,6 +16,9 @@ else() cmake_policy(VERSION 3.18) endif() +if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") +endif() # Only needed for CMake < 3.5 support include(CMakeParseArguments) From dac44a9d44859045e2b566ae537322daab9a23ca Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Mon, 25 Jan 2021 21:07:58 +0100 Subject: [PATCH 05/11] Stop pre-commit/the format CI job from whining --- .ycm_extra_conf.py | 3 ++- tests/CMakeLists.txt | 5 ++--- tests/requirements.txt | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index 6fe0bd7cdb..1c6213230c 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -1,2 +1,3 @@ +# -*- coding: utf-8 -*- def Settings(**kwargs): - return { 'flags': ['-xc++', '-std=c++20', '-isystem/usr/include/python3.9'] } + return {"flags": ["-xc++", "-std=c++20", "-isystem/usr/include/python3.9"]} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e6553ba534..23c6e24258 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,7 +16,7 @@ else() cmake_policy(VERSION 3.18) endif() -if (MSVC) +if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") endif() # Only needed for CMake < 3.5 support @@ -391,8 +391,7 @@ set(PYBIND11_TEST_PREFIX_COMMAND # A single command to compile and run the tests add_custom_target( pytest - COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest - --cov=pybind11 + COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest --cov=pybind11 ${PYBIND11_ABS_PYTEST_FILES} DEPENDS ${test_targets} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" diff --git a/tests/requirements.txt b/tests/requirements.txt index d90d02e2c1..a0fb0e4bbb 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,12 +1,12 @@ --extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010/ +codecov>=2.0.5 +coverage>=4.2 numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" numpy==1.18.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version>="3.6" numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10" pytest==4.6.9; python_version<"3.5" pytest==6.1.2; python_version=="3.5" pytest==6.2.1; python_version>="3.6" +pytest-cov scipy==1.2.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version<"3.6" scipy==1.5.4; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10" -codecov>=2.0.5 -pytest-cov -coverage>=4.2 From bf3fea97f7fc8c8a03c8f4d37b24d0bd3a4f5d97 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Mon, 25 Jan 2021 21:45:19 +0100 Subject: [PATCH 06/11] Remove .ycm_extra_conf.py and try renaming codecov.yml to .codecov.yml --- codecov.yml => .codecov.yml | 0 .ycm_extra_conf.py | 3 --- 2 files changed, 3 deletions(-) rename codecov.yml => .codecov.yml (100%) delete mode 100644 .ycm_extra_conf.py diff --git a/codecov.yml b/.codecov.yml similarity index 100% rename from codecov.yml rename to .codecov.yml diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py deleted file mode 100644 index 1c6213230c..0000000000 --- a/.ycm_extra_conf.py +++ /dev/null @@ -1,3 +0,0 @@ -# -*- coding: utf-8 -*- -def Settings(**kwargs): - return {"flags": ["-xc++", "-std=c++20", "-isystem/usr/include/python3.9"]} From 13e9f5288754eab4e6238635d2afe54d67e8dd16 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Mon, 25 Jan 2021 21:56:04 +0100 Subject: [PATCH 07/11] Remove .codecov.yml for now --- .codecov.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index be9a17bfa6..0000000000 --- a/.codecov.yml +++ /dev/null @@ -1,12 +0,0 @@ -codecov: - notify: - after_n_builds: 1 - -coverage: - precision: 2 - round: down - range: 70...100 - -comment: - layout: "header, diff, changes, uncovered" - behavior: default # update if exists else create new From 517f8c035558c8359185990d8a22295fb3476398 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Mon, 25 Jan 2021 22:23:19 +0100 Subject: [PATCH 08/11] Fix use of Codecov token --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b74d9c9134..9b92f9b9bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,8 +115,8 @@ jobs: - name: Interface test C++11 run: cmake --build . --target test_cmake_build - - name: codecov - run: CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} codecov --name ${{ matrix.python }}-${{ matrix.runs-on }}-${{ matrix.args }} + - name: Upload to Codecov + run: codecov --token "${{ secrets.CODECOV_TOKEN }}" --name "${{ matrix.python }}-${{ matrix.runs-on }}-${{ matrix.args }}" - name: Clean directory run: git clean -fdx From f046ac21d5361c8ada6bf5e23cddd18b9326e5bb Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Mon, 25 Jan 2021 23:30:05 +0100 Subject: [PATCH 09/11] Only add --cov=pybind11 when PYBIND11_TEST_COVERAGE is set --- .github/workflows/ci.yml | 1 + CMakeLists.txt | 4 ---- tests/CMakeLists.txt | 19 +++++++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b92f9b9bb..7f15d5172c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,6 +98,7 @@ jobs: -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON + -DPYBIND11_TEST_COVERAGE=ON -DCMAKE_CXX_STANDARD=11 ${{ matrix.args }} diff --git a/CMakeLists.txt b/CMakeLists.txt index ab0f4fb151..ded4dad9c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,6 @@ else() cmake_policy(VERSION 3.18) endif() -if(NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage") -endif() - # Extract project version from source file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h" pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 23c6e24258..a527fa28d0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -311,6 +311,10 @@ if(PYBIND11_CUDA_TESTS) set_property(SOURCE ${PYBIND11_TEST_FILES} PROPERTY LANGUAGE CUDA) endif() +set(PYBIND11_TEST_COVERAGE + OFF + CACHE BOOL "Collect test coverage for C++ and Python") + foreach(target ${test_targets}) set(test_files ${PYBIND11_TEST_FILES}) if(NOT "${target}" STREQUAL "pybind11_tests") @@ -352,6 +356,11 @@ foreach(target ${test_targets}) target_compile_definitions(${target} PRIVATE -DPYBIND11_TEST_BOOST) endif() + if(PYBIND11_TEST_COVERAGE AND NOT MSVC) + target_compile_options(${target} PRIVATE -coverage) + target_link_libraries(${target} PRIVATE -coverage) + endif() + # Always write the output file directly into the 'tests' directory (even on MSVC) if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY @@ -388,11 +397,17 @@ set(PYBIND11_TEST_PREFIX_COMMAND "" CACHE STRING "Put this before pytest, use for checkers and such") +if(PYBIND11_TEST_COVERAGE) + set(PYBIND11_PYTEST_EXTRA_FLAGS "--cov=pybind11") +else() + set(PYBIND11_PYTEST_EXTRA_FLAGS "") +endif() + # A single command to compile and run the tests add_custom_target( pytest - COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest --cov=pybind11 - ${PYBIND11_ABS_PYTEST_FILES} + COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest + ${PYBIND11_PYTEST_EXTRA_FLAGS} ${PYBIND11_ABS_PYTEST_FILES} DEPENDS ${test_targets} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" USES_TERMINAL) From a86957cb9a08e52239b27fd79e0e9b750fac902f Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Tue, 26 Jan 2021 00:40:36 +0100 Subject: [PATCH 10/11] Try uploading immediately after pytest target --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f15d5172c..7f59cc2a13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,7 +98,6 @@ jobs: -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON - -DPYBIND11_TEST_COVERAGE=ON -DCMAKE_CXX_STANDARD=11 ${{ matrix.args }} @@ -116,9 +115,6 @@ jobs: - name: Interface test C++11 run: cmake --build . --target test_cmake_build - - name: Upload to Codecov - run: codecov --token "${{ secrets.CODECOV_TOKEN }}" --name "${{ matrix.python }}-${{ matrix.runs-on }}-${{ matrix.args }}" - - name: Clean directory run: git clean -fdx @@ -129,6 +125,7 @@ jobs: -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON + -DPYBIND11_TEST_COVERAGE=ON -DCMAKE_CXX_STANDARD=17 ${{ matrix.args }} ${{ matrix.args2 }} @@ -139,6 +136,9 @@ jobs: - name: Python tests run: cmake --build build2 --target pytest + - name: Upload to Codecov + run: codecov --token "${{ secrets.CODECOV_TOKEN }}" --name "${{ matrix.python }}-${{ matrix.runs-on }}-${{ matrix.args }}" + - name: C++ tests # TODO: Figure out how to load the DLL on Python 3.8+ if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10-dev'))" From 2cb16304e9912c0b35f3792d1747f5753bfbf17a Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Tue, 26 Jan 2021 01:14:44 +0100 Subject: [PATCH 11/11] Try debug builds for code coverage --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f59cc2a13..645ec84d51 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,6 +125,7 @@ jobs: -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON + -DCMAKE_BUILD_TYPE=Debug -DPYBIND11_TEST_COVERAGE=ON -DCMAKE_CXX_STANDARD=17 ${{ matrix.args }}