Skip to content

Add GHA and several test fixes #2321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- master
- stable
- v*

jobs:
standard:
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]
python:
- 2.7
- 3.5
- 3.8
- 3.9-dev
- pypy2
- pypy3

include:
- os: ubuntu
python: 3.6
- os: macos
python: 3.7

exclude:
# Currently 32bit only, and we build 64bit
- os: windows
python: pypy2
- os: windows
python: pypy3

# Currently can't build due to warning, fixed in CPython > 3.9b5
- os: macos
python: 3.9-dev

# Currently broken on embed_test
- os: windows
python: 3.8
- os: windows
python: 3.9-dev

name: Python ${{ matrix.python }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest

steps:
- uses: actions/checkout@v2

- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Prepare env
run: python -m pip install -r tests/requirements.txt

- name: Configure
shell: bash
run: >
cmake -S . -B build
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")

- name: Build
run: cmake --build build -j 2

- name: Python tests
run: cmake --build build --target pytest -j 2 -v

- name: C++ tests
run: cmake --build build --target cpptest -j 2 -v

- name: Interface test
run: cmake --build build --target test_cmake_build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ MANIFEST
sosize-*.txt
pybind11Config*.cmake
pybind11Targets.cmake
/*env*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the leading slash intentional?

Copy link
Collaborator Author

@henryiii henryiii Jul 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm assuming a virtual environment would be in the main directory or in a build directory (which should be already ignored)

12 changes: 10 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ function(pybind11_enable_warnings target_name)
target_compile_options(${target_name} PRIVATE -Werror)
endif()
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND PYTHON_VERSION VERSION_LESS 3.0)
if(CMAKE_CXX_STANDARD STREQUAL "14")
target_compile_options(${target_name} PUBLIC -Wno-deprecated-register)
elseif(NOT CMAKE_CXX_STANDARD VERSION_LESS 17)
target_compile_options(${target_name} PUBLIC -Wno-register)
endif()
endif()
endfunction()

set(test_targets pybind11_tests)
Expand Down Expand Up @@ -203,10 +211,10 @@ foreach(target ${test_targets})

# 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 ${testdir})
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${testdir}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought cmake doesn't care about quotes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, without quotes spaces turn into separate arguments. All filename variables need to have quotes. We aren't testing with a space in the name of a directory, but I expect this would fail without quotes.

foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config)
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} ${testdir})
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} "${testdir}")
endforeach()
endif()
endforeach()
Expand Down
3 changes: 3 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010/
numpy; platform_python_implementation!="PyPy" or sys_platform!="darwin" or python_version<"3.0"
pytest
1 change: 1 addition & 0 deletions tests/test_cmake_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function(pybind11_add_build_test name)
set(build_options "-DCMAKE_PREFIX_PATH=${PROJECT_BINARY_DIR}/mock_install"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DPYBIND11_CPP_STANDARD=${PYBIND11_CPP_STANDARD}")
if(NOT ARG_INSTALL)
list(APPEND build_options "-DPYBIND11_PROJECT_DIR=${PROJECT_SOURCE_DIR}")
Expand Down
16 changes: 10 additions & 6 deletions tests/test_embed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@ add_executable(test_embed
catch.cpp
test_interpreter.cpp
)
target_include_directories(test_embed PRIVATE ${CATCH_INCLUDE_DIR})
target_include_directories(test_embed PRIVATE "${CATCH_INCLUDE_DIR}")
pybind11_enable_warnings(test_embed)

if(NOT CMAKE_VERSION VERSION_LESS 3.0)
target_link_libraries(test_embed PRIVATE pybind11::embed)
else()
target_include_directories(test_embed PRIVATE ${PYBIND11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
target_compile_options(test_embed PRIVATE ${PYBIND11_CPP_STANDARD})
target_link_libraries(test_embed PRIVATE ${PYTHON_LIBRARIES})
target_include_directories(test_embed PRIVATE "${PYBIND11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}")
target_compile_options(test_embed PRIVATE "${PYBIND11_CPP_STANDARD}")
target_link_libraries(test_embed PRIVATE "${PYTHON_LIBRARIES}")
endif()

find_package(Threads REQUIRED)
target_link_libraries(test_embed PUBLIC ${CMAKE_THREAD_LIBS_INIT})

add_custom_target(cpptest COMMAND $<TARGET_FILE:test_embed>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

pybind11_add_module(external_module THIN_LTO external_module.cpp)
set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config)
set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} "${CMAKE_CURRENT_SOURCE_DIR}")
endforeach()
add_dependencies(cpptest external_module)

add_dependencies(check cpptest)
7 changes: 7 additions & 0 deletions tests/test_kwargs_and_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import pytest
from pybind11_tests import kwargs_and_defaults as m

import platform
import sys

pypy = platform.python_implementation() == "PyPy"


def test_function_signatures(doc):
assert doc(m.kw_func0) == "kw_func0(arg0: int, arg1: int) -> str"
Expand Down Expand Up @@ -146,6 +151,8 @@ def test_keyword_only_args(msg):
"""


@pytest.mark.xfail(pypy and sys.version_info < (3, 0),
reason="PyPy2 doesn't seem to double count")
def test_args_refcount():
"""Issue/PR #1216 - py::args elements get double-inc_ref()ed when combined with regular
arguments"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ def test_memoryview_from_buffer_empty_shape():
assert view.format == 'B'
if sys.version_info.major < 3:
# Python 2 behavior is weird, but Python 3 (the future) is fine.
assert bytes(view).startswith(b'<memory at ')
# PyPy3 has <memoryview, while CPython 2 has <memory
assert bytes(view).startswith(b'<memory')
else:
assert bytes(view) == b''

Expand Down