From ef5787cbf77ac59d8125d00e8d67416f5f2d8494 Mon Sep 17 00:00:00 2001 From: Hao Zhang <hzhangxyz@outlook.com> Date: Tue, 12 Dec 2023 22:56:51 +0800 Subject: [PATCH 1/4] Move pybind11 from submodule to pyproject.toml:build-system.requires. Since we can specify setup dependencies in pyproject.toml, pybind11 could be added here instead of placed directly under the root of the repo, which make the repo structure more compact. And the path of pybind11 cmake config could be set by pybind11_DIR in setup.py. --- .gitmodules | 4 ---- CMakeLists.txt | 2 +- pybind11 | 1 - pyproject.toml | 1 + setup.py | 3 +++ 5 files changed, 5 insertions(+), 6 deletions(-) delete mode 160000 pybind11 diff --git a/.gitmodules b/.gitmodules index ced1d11..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "pybind11"] - path = pybind11 - url = https://github.com/pybind/pybind11.git - branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index 69122df..8eb2c68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.4...3.18) project(cmake_example) -add_subdirectory(pybind11) +find_package(pybind11) pybind11_add_module(cmake_example src/main.cpp) # EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a diff --git a/pybind11 b/pybind11 deleted file mode 160000 index 914c06f..0000000 --- a/pybind11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 914c06fb252b6cc3727d0eedab6736e88a3fcb01 diff --git a/pyproject.toml b/pyproject.toml index fd92373..1dabc68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,7 @@ requires = [ "wheel", "ninja", "cmake>=3.12", + "pybind11>=2.9.2", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 03f97fb..066f232 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,8 @@ from setuptools import Extension, setup from setuptools.command.build_ext import build_ext +from pybind11 import get_cmake_dir + # Convert distutils Windows platform specifiers to CMake -A arguments PLAT_TO_CMAKE = { "win32": "Win32", @@ -46,6 +48,7 @@ def build_extension(self, ext: CMakeExtension) -> None: # from Python. cmake_args = [ f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", + f"-Dpybind11_DIR={get_cmake_dir()}", f"-DPYTHON_EXECUTABLE={sys.executable}", f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm ] From 8164ebffa947b0d0fdfb0492683afc032c7e18a3 Mon Sep 17 00:00:00 2001 From: Hao Zhang <hzhangxyz@outlook.com> Date: Tue, 12 Dec 2023 23:06:05 +0800 Subject: [PATCH 2/4] Make format check happy. --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 066f232..3037bce 100644 --- a/setup.py +++ b/setup.py @@ -4,11 +4,10 @@ import sys from pathlib import Path +from pybind11 import get_cmake_dir from setuptools import Extension, setup from setuptools.command.build_ext import build_ext -from pybind11 import get_cmake_dir - # Convert distutils Windows platform specifiers to CMake -A arguments PLAT_TO_CMAKE = { "win32": "Win32", From a18e5969abf36fd9dc3d2a244e68ecb9aa521e12 Mon Sep 17 00:00:00 2001 From: Hao Zhang <hzhangxyz@outlook.com> Date: Tue, 12 Dec 2023 23:13:21 +0800 Subject: [PATCH 3/4] Remove removed files in MANIFEST.in --- MANIFEST.in | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 71dbebb..a1240fd 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,3 @@ -include README.md LICENSE pybind11/LICENSE -graft pybind11/include -graft pybind11/tools +include README.md LICENSE graft src global-include CMakeLists.txt *.cmake From a312f74c68696121e85bd93f388cb79ee45d2761 Mon Sep 17 00:00:00 2001 From: Hao Zhang <hzhangxyz@outlook.com> Date: Thu, 14 Dec 2023 15:02:50 +0800 Subject: [PATCH 4/4] Add pybind11 as dependence when using mypy to process type checking. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23dc004..30e5773 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,7 +48,7 @@ repos: - id: mypy files: "setup.py" args: [] - additional_dependencies: [types-setuptools] + additional_dependencies: [types-setuptools, pybind11] # Changes tabs to spaces - repo: https://github.com/Lucas-C/pre-commit-hooks