From f816654ca9cf1bdae58bec577bde54637a23cc7c Mon Sep 17 00:00:00 2001 From: ayeankit Date: Thu, 3 Aug 2023 23:07:37 +0530 Subject: [PATCH 01/33] add pybind11 build-system as option --- README.md | 9 +- docs/guide.md | 5 +- src/scicookie/cookiecutter.json | 3 +- src/scicookie/hooks/post_gen_project.py | 17 ++- src/scicookie/profiles/base.yaml | 1 + .../build-system/pybind11-pyproject.toml | 128 ++++++++++++++++++ .../build-system/skcdemo.cpp | 2 +- .../conda/dev.yaml | 3 + .../docs/contributing.md | 4 + tests/smoke/base.sh | 8 ++ tests/smoke/build-system.sh | 1 + 11 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml diff --git a/README.md b/README.md index 67b5b07d..528c8a95 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,11 @@ for a Python package. [Flit](https://flit.pypa.io), [meson-python](https://meson-python.readthedocs.io/en/latest/index.html), [Setuptools](https://setuptools.pypa.io/en/latest/), - [PDM](https://pdm.fming.dev/) or - [Hatch](https://hatch.pypa.io) - [Maturin](https://pypi.org/project/maturin/0.8.2/) - [scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/) + [PDM](https://pdm.fming.dev/), + [Hatch](https://hatch.pypa.io), + [Maturin](https://pypi.org/project/maturin/0.8.2/), + [scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/) or + [pybind11](https://pybind11.readthedocs.io/en/stable/) based on your preference. - The structure of the project can use the *src layout* or *flat layout*. The “src layout” moving the code that is intended to be diff --git a/docs/guide.md b/docs/guide.md index 475c949e..65516829 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -334,7 +334,10 @@ packages. SciCookie support the following: build requirements. With its capabilities, it facilitates cross-platform builds using CMake and effortless integration with C/C++ libraries, making it a valuable asset for research software engineers. - + +- [**Pybind11**](https://pybind11.readthedocs.io/en/stable/): It's build system designed + for C++ library that simplifies the creation of Python bindings for C++ code, enabling easy integration of C++ functions and classes into Python scripts. It acts as a bridge between the two languages, allowing C++ algorithms and functionality to be directly called from Python as if they were native Python modules. Pybind11's user-friendly syntax reduces boilerplate code, making binding generation more straightforward, while standard C++ build systems like CMake or Make facilitate the compilation of projects using pybind11. Its efficiency, ease of use, and strong community support have made it a popular choice for projects requiring seamless interoperability between C++ and Python, ranging from scientific computing to game development and automation. Staying up-to-date with the latest pybind11 documentation ensures the best practices are followed. + The idea behind the options in SciCookie is that you can choose from some of the most popular system compilers to suit your needs and preferences for developing Python packages. If you think we should add more options, you can submit your diff --git a/src/scicookie/cookiecutter.json b/src/scicookie/cookiecutter.json index 0339ea83..5ca4240e 100644 --- a/src/scicookie/cookiecutter.json +++ b/src/scicookie/cookiecutter.json @@ -51,7 +51,8 @@ "pdm", "hatch", "maturin", - "scikit-build-core" + "scikit-build-core", + "pybind11" ], "use_bandit": "yes", "use_black": "no", diff --git a/src/scicookie/hooks/post_gen_project.py b/src/scicookie/hooks/post_gen_project.py index 5313b755..da62f53e 100644 --- a/src/scicookie/hooks/post_gen_project.py +++ b/src/scicookie/hooks/post_gen_project.py @@ -67,6 +67,8 @@ BUILD_SYSTEM = "maturin" {% elif cookiecutter.build_system == "scikit-build-core" -%} BUILD_SYSTEM = "scikit-build-core" +{% elif cookiecutter.build_system == "pybind11" -%} +BUILD_SYSTEM = "pybind11" {%- else %} BUILD_SYSTEM = None {%- endif %} @@ -214,7 +216,20 @@ def clean_up_build_system(): shutil.move( build_system_dir / "skcdemo.cpp", PROJECT_DIRECTORY / 'skcdemo.cpp' - ) + ) + elif BUILD_SYSTEM == "pybind11": + shutil.move( + build_system_dir / "pybind11-pyproject.toml", + PROJECT_DIRECTORY / 'pyproject.toml' + ) + shutil.move( + build_system_dir / "CMakeLists.txt", + PROJECT_DIRECTORY / 'CMakeLists.txt' + ) + shutil.move( + build_system_dir / "skcdemo.cpp", + PROJECT_DIRECTORY / 'skcdemo.cpp' + ) else: shutil.move( build_system_dir / "base-pyproject.toml", diff --git a/src/scicookie/profiles/base.yaml b/src/scicookie/profiles/base.yaml index ca70ed90..7e54f691 100644 --- a/src/scicookie/profiles/base.yaml +++ b/src/scicookie/profiles/base.yaml @@ -89,6 +89,7 @@ build_system: - hatch - maturin - scikit-build-core + - pybind11 enabled: false command_line_interface: diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml new file mode 100644 index 00000000..5c584f61 --- /dev/null +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml @@ -0,0 +1,128 @@ +[build-system] +requires = ["setuptools>=42", "wheel", "pybind11~=2.6.1"] +build-backend = "setuptools.build_meta" + +[project] +name = "{{ cookiecutter.project_slug }}" +authors = [ + { name = "{{ cookiecutter.author_full_name }}", email = "{{ cookiecutter.author_email }}" }, +] +description = "{{ cookiecutter.project_short_description }}" +readme = "README.md" +classifiers = [ + "Development Status :: 1 - Planning", + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", +{%- if cookiecutter.project_license == "MIT" %} + "License :: OSI Approved :: MIT License", +{%- elif cookiecutter.project_license == "BSD 3 Clause" %} + "License :: OSI Approved :: BSD License", +{%- elif cookiecutter.project_license == "Apache Software License 2.0" %} + "License :: OSI Approved :: Apache Software License", +{%- elif cookiecutter.project_license == "GNU General Public License v3" %} + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", +{%- endif %} + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Scientific/Engineering", + "Typing :: Typed", +] +dynamic = ["version"] +requires-python = ">=3.8.1" +dependencies = [ +{# keep this line here #} +{%- if cookiecutter.use_pytest == "yes" -%} + "pytest >= 7.3.2", +{% if cookiecutter.use_coverage == "yes" -%} + "pytest-cov >= 4.1.0", +{% endif %} +{%- endif -%}{#- end of use_pytest -#} +{%- if cookiecutter.use_hypothesis == "yes" -%} + "hypothesis >= 6.0", +{% endif %} +{%- if cookiecutter.use_coverage == "yes" -%} + "coverage >= 7.2.7", +{% endif %} +{%- if cookiecutter.use_blue == "yes" -%} + "blue >= 0.9.1", +{% endif %} +{%- if cookiecutter.use_black == "yes" -%} + "black >= 23.3.0", +{% endif %} +{%- if cookiecutter.use_isort == "yes" -%} + "isort >= 5.12.0", +{% endif %} +{%- if cookiecutter.use_pre_commit -%} + "pre-commit >= 3.3.2", +{% endif %} +{%- if cookiecutter.use_flake8 == "yes" -%} + "flake8 >= 4.0.1, < 7", +{% endif %} +{%- if cookiecutter.use_ruff == "yes" -%} + "ruff >= 0.0.272", +{% endif %} +{%- if cookiecutter.use_mypy == "yes" -%} + "mypy >= 1.3.0", +{% endif %} +{%- if cookiecutter.use_bandit == "yes" -%} + "bandit >= 1.7.5", +{% endif %} +{%- if cookiecutter.use_pydocstyle == "yes" -%} + "pydocstyle >= 6.3.0", +{% endif %} +{%- if cookiecutter.use_vulture == "yes" -%} + "vulture >= 2.7", +{% endif %} +{%- if cookiecutter.use_mccabe == "yes" -%} + "mccabe >= 0.6.1", +{% endif %} +{%- if cookiecutter.use_containers in ['Docker', 'Podman'] -%} +# if you want to use docker-compose from your system, remove compose-go here + "compose-go >= 2.18.1", +{% endif %} +{%- if cookiecutter.documentation_engine == 'mkdocs' -%} + "Jinja2 >= 3.1.2", + "mkdocs >= 1.4.3", + "mkdocs-exclude >= 1.0.2", + "mkdocs-jupyter >= 0.24.1", + "mkdocs-literate-nav >= 0.6.0", + "mkdocs-macros-plugin >= 0.7.0, < 1", + "mkdocs-material >= 9.1.15", + "mkdocstrings >= 0.21.2", + "mkdocstrings-python >= 1.1.2", +{% elif cookiecutter.documentation_engine == 'sphinx' -%} + "Sphinx >= 6.2.1", + "sphinx-rtd-theme >= 1.2.2", + "importlib-metadata >= 6.5.1", + "myst-parser >= 0.19.2", + "nbsphinx >= 0.9.2", + "pandoc >= 2.3", +{% elif cookiecutter.documentation_engine == 'jupyter-book' -%} + "jupyter-book >= 0.15.1", + "myst-parser >= 0.18.1", +{% endif %} +] + +[project.urls] +Homepage = "{{ cookiecutter.project_url }}" +"Bug Tracker" = "{{ cookiecutter.project_url }}/issues" +Discussions = "{{ cookiecutter.project_url }}/discussions" +Changelog = "{{ cookiecutter.project_url }}/releases" + +[tool.hatch.version] +{# keep this line here #} +{%- if cookiecutter.project_layout == 'flat' -%} +path = "{{ cookiecutter.package_slug }}/__init__.py" +{% elif cookiecutter.project_layout == 'src' -%} +path = "src/{{ cookiecutter.package_slug }}/__init__.py" +{% endif %} + +{% include "build-system/base-pyproject.toml" %} +{#- keep this line at the end of the file -#} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp b/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp index 1f5fb882..0a3fe0a5 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp @@ -4,6 +4,6 @@ namespace py = pybind11; PYBIND11_MODULE(skcdemo, m) { m.def("hello", [](){ - py::print("Hello, scikit-build-core!"); + py::print("Hello !!!"); }); } diff --git a/src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml b/src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml index c2fbe180..969474d5 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml +++ b/src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml @@ -23,6 +23,9 @@ dependencies: {%- elif cookiecutter.build_system == "scikit-build-core" %} - scikit-build-core - cmake +{%- elif cookiecutter.build_system == "pybind11" %} + - pybind11 + - cmake {%- endif %} - nodejs # used by semantic-release - shellcheck diff --git a/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md b/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md index de1d374a..5a1f6699 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md +++ b/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md @@ -59,6 +59,10 @@ In addition, you should know that to build our package we use {%- elif cookiecutter.build_system == "scikit-build-core" -%} In addition, you should know that to build our package we use [scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/): It's a Python packaging tool and build system an improved build system generator for CPython C extensions. It provides better support for additional compilers, build systems, cross compilation, and locating dependencies and their associated build requirements.This tool improves package management in the scientific Python ecosystem, enabling cross-platform builds with CMake, and seamless integration with C/C++ libraries for research software engineers. +{%- elif cookiecutter.build_system == "pybind11" -%} +In addition, you should know that to build our package we use +[pybind11](https://pybind11.readthedocs.io/en/stable/): It's a Python packaging tool for C++ build system that simplifies creating Python bindings for C++ code, allowing easy integration of C++ functions and classes into Python scripts. Acting as a bridge between the two languages, it enables direct calls to C++ functionality from Python as if it were a native Python module. Its user-friendly syntax reduces boilerplate code, while standard C++ build systems like CMake or Make aid in project compilation. Pybind11's efficiency and strong community support make it a popular choice for projects requiring seamless interoperability between C++ and Python, from scientific computing to game development. + {%- endif %} Contributions are welcome, and they are greatly appreciated! Every little bit diff --git a/tests/smoke/base.sh b/tests/smoke/base.sh index fb17410e..bed4f72f 100755 --- a/tests/smoke/base.sh +++ b/tests/smoke/base.sh @@ -55,6 +55,14 @@ elif command -v maturin &> /dev/null; then pip install -e . elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then pip install -e . +elif [ "$(pip list|grep -c pybind11)" -ne "0" ]; then + # Assuming you are inside the root of the CMake source directory + mkdir build + cd build + cmake .. + cmake --build . + cd .. + pip install -e . else # use setuptools pip install --editable . diff --git a/tests/smoke/build-system.sh b/tests/smoke/build-system.sh index 655c9325..9206404c 100755 --- a/tests/smoke/build-system.sh +++ b/tests/smoke/build-system.sh @@ -10,3 +10,4 @@ SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" . ${SMOKE_DIR}/base.sh "build_system=hatch" . ${SMOKE_DIR}/base.sh "build_system=maturin" . ${SMOKE_DIR}/base.sh "build_system=scikit-build-core" +. ${SMOKE_DIR}/base.sh "build_system=pybind11" From e9c622637a05826c8e1b5467d3d4b43f4898a298 Mon Sep 17 00:00:00 2001 From: ayeankit Date: Fri, 4 Aug 2023 20:29:08 +0530 Subject: [PATCH 02/33] added setup.py --- src/scicookie/hooks/post_gen_project.py | 10 +++++++--- .../build-system/CMakeLists.txt | 14 ++++++++++++++ .../build-system/pybind11-pyproject.toml | 7 ------- .../build-system/pybind11.cpp | 9 +++++++++ .../build-system/setup.py | 17 +++++++++++++++++ .../build-system/skcdemo.cpp | 2 +- 6 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp create mode 100644 src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py diff --git a/src/scicookie/hooks/post_gen_project.py b/src/scicookie/hooks/post_gen_project.py index da62f53e..f0668de7 100644 --- a/src/scicookie/hooks/post_gen_project.py +++ b/src/scicookie/hooks/post_gen_project.py @@ -227,9 +227,13 @@ def clean_up_build_system(): PROJECT_DIRECTORY / 'CMakeLists.txt' ) shutil.move( - build_system_dir / "skcdemo.cpp", - PROJECT_DIRECTORY / 'skcdemo.cpp' - ) + build_system_dir / "setup.py", + PROJECT_DIRECTORY / 'setup.py' + ) + shutil.move( + build_system_dir / "pybind11.cpp", + PROJECT_DIRECTORY / 'pybind11.cpp' + ) else: shutil.move( build_system_dir / "base-pyproject.toml", diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt index aa7a3da9..a67b0d1b 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt @@ -1,3 +1,4 @@ +{% if cookiecutter.build_system == "scikit-build-core" -%} cmake_minimum_required(VERSION 3.15...3.26) project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) @@ -7,3 +8,16 @@ find_package(pybind11 CONFIG REQUIRED) pybind11_add_module(skcdemo MODULE skcdemo.cpp) install(TARGETS skcdemo DESTINATION .) + +{% elif cookiecutter.build_system == "pybind11" -%} +cmake_minimum_required(VERSION 3.15...3.26) + +project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) + +find_package(pybind11 CONFIG REQUIRED) + +pybind11_add_module(pybind11 MODULE pybind11.cpp) + +install(TARGETS pybind11 DESTINATION .) + +{%- endif %} \ No newline at end of file diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml index 5c584f61..d25c209c 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml @@ -116,13 +116,6 @@ Homepage = "{{ cookiecutter.project_url }}" Discussions = "{{ cookiecutter.project_url }}/discussions" Changelog = "{{ cookiecutter.project_url }}/releases" -[tool.hatch.version] -{# keep this line here #} -{%- if cookiecutter.project_layout == 'flat' -%} -path = "{{ cookiecutter.package_slug }}/__init__.py" -{% elif cookiecutter.project_layout == 'src' -%} -path = "src/{{ cookiecutter.package_slug }}/__init__.py" -{% endif %} {% include "build-system/base-pyproject.toml" %} {#- keep this line at the end of the file -#} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp new file mode 100644 index 00000000..ca105a1b --- /dev/null +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp @@ -0,0 +1,9 @@ +#include + +namespace py = pybind11; + +PYBIND11_MODULE(skcdemo, m) { + m.def("hello", [](){ + py::print("Hello, pybind11!"); + }); +} \ No newline at end of file diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py new file mode 100644 index 00000000..91f72d1e --- /dev/null +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -0,0 +1,17 @@ +# Available at setup time due to pyproject.toml +from pybind11.setup_helpers import Pybind11Extension +from setuptools import setup + + +setup( + name="OSL Python package", + author="{{cookiecutter.author_full_name}}", + author_email="{{cookiecutter.author_email}}", + url="https://{{ cookiecutter.project_slug }}.com", + description="A test project using pybind11", + long_description="", + #extras_require={"test": "pytest"}, + # Currently, build_ext only provides an optional "highest supported C++ + # level" feature, but in the future it may provide more features. + python_requires=">=3.7", +) \ No newline at end of file diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp b/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp index 0a3fe0a5..1f5fb882 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/skcdemo.cpp @@ -4,6 +4,6 @@ namespace py = pybind11; PYBIND11_MODULE(skcdemo, m) { m.def("hello", [](){ - py::print("Hello !!!"); + py::print("Hello, scikit-build-core!"); }); } From ff88a54a4ba0833a85f1ae9662499263fa262aa8 Mon Sep 17 00:00:00 2001 From: ayeankit Date: Fri, 4 Aug 2023 21:20:33 +0530 Subject: [PATCH 03/33] added setup.py --- .../{{cookiecutter.project_slug}}/build-system/CMakeLists.txt | 2 +- .../{{cookiecutter.project_slug}}/build-system/pybind11.cpp | 2 +- .../{{cookiecutter.project_slug}}/build-system/setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt index a67b0d1b..5d4bb980 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt @@ -20,4 +20,4 @@ pybind11_add_module(pybind11 MODULE pybind11.cpp) install(TARGETS pybind11 DESTINATION .) -{%- endif %} \ No newline at end of file +{%- endif %} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp index ca105a1b..4d1190d5 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp @@ -6,4 +6,4 @@ PYBIND11_MODULE(skcdemo, m) { m.def("hello", [](){ py::print("Hello, pybind11!"); }); -} \ No newline at end of file +} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index 91f72d1e..e2c9d130 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -14,4 +14,4 @@ # Currently, build_ext only provides an optional "highest supported C++ # level" feature, but in the future it may provide more features. python_requires=">=3.7", -) \ No newline at end of file +) From 7e83d2263633df789b165d1176cffe0fe65ff988 Mon Sep 17 00:00:00 2001 From: ayeankit Date: Sat, 5 Aug 2023 19:36:48 +0530 Subject: [PATCH 04/33] added setup.py --- src/scicookie/hooks/post_gen_project.py | 12 ++++--- .../{{cookiecutter.project_slug}}/Makefile | 3 ++ .../build-system/CMakeLists.txt | 10 +++--- .../build-system/main.cpp | 28 ++++++++++++++++ .../build-system/pybind11.cpp | 9 ------ .../build-system/setup.py | 32 +++++++++++-------- tests/smoke/base.sh | 5 --- 7 files changed, 62 insertions(+), 37 deletions(-) create mode 100644 src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp delete mode 100644 src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp diff --git a/src/scicookie/hooks/post_gen_project.py b/src/scicookie/hooks/post_gen_project.py index f0668de7..fe2bff71 100644 --- a/src/scicookie/hooks/post_gen_project.py +++ b/src/scicookie/hooks/post_gen_project.py @@ -229,10 +229,6 @@ def clean_up_build_system(): shutil.move( build_system_dir / "setup.py", PROJECT_DIRECTORY / 'setup.py' - ) - shutil.move( - build_system_dir / "pybind11.cpp", - PROJECT_DIRECTORY / 'pybind11.cpp' ) else: shutil.move( @@ -298,6 +294,14 @@ def add_binding_source_files(): else: os.makedir(src_system_dir) shutil.move(build_system_dir / "lib.rs", src_system_dir) + elif BUILD_SYSTEM == "pybind11" : + build_system_dir = PROJECT_DIRECTORY / "build-system" + src_system_dir = PROJECT_DIRECTORY/ "src" + if USE_SRC_LAYOUT : + shutil.move(build_system_dir / "main.cpp", "src") + else: + os.makedir(src_system_dir) + shutil.move(build_system_dir / "main.cpp", src_system_dir) else: pass diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index adc9c2d9..c179b470 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -115,6 +115,9 @@ build: hatch build {%- elif cookiecutter.build_system == "maturin" %} maturin build +{%- elif cookiecutter.build_system == "pybind11" %} + pybind11 build + {%- endif %} .PHONY:release-ci diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt index 5d4bb980..cb37fdaf 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt @@ -1,8 +1,9 @@ -{% if cookiecutter.build_system == "scikit-build-core" -%} cmake_minimum_required(VERSION 3.15...3.26) project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) +{% if cookiecutter.build_system == "scikit-build-core" -%} + find_package(pybind11 CONFIG REQUIRED) pybind11_add_module(skcdemo MODULE skcdemo.cpp) @@ -10,14 +11,11 @@ pybind11_add_module(skcdemo MODULE skcdemo.cpp) install(TARGETS skcdemo DESTINATION .) {% elif cookiecutter.build_system == "pybind11" -%} -cmake_minimum_required(VERSION 3.15...3.26) - -project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) find_package(pybind11 CONFIG REQUIRED) -pybind11_add_module(pybind11 MODULE pybind11.cpp) +pybind11_add_module(_core MODULE src/main.cpp) -install(TARGETS pybind11 DESTINATION .) +install(TARGETS _core DESTINATION .) {%- endif %} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp b/src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp new file mode 100644 index 00000000..736960ce --- /dev/null +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp @@ -0,0 +1,28 @@ +#include + +int add(int i, int j) { return i + j; } + +namespace py = pybind11; + +PYBIND11_MODULE(_core, m) { + m.doc() = R"pbdoc( + Pybind11 example plugin + ----------------------- + .. currentmodule:: python_example + .. autosummary:: + :toctree: _generate + add + subtract + )pbdoc"; + + m.def("add", &add, R"pbdoc( + Add two numbers + Some other explanation about the add function. + )pbdoc"); + + m.def( + "subtract", [](int i, int j) { return i - j; }, R"pbdoc( + Subtract two numbers + Some other explanation about the subtract function. + )pbdoc"); +} \ No newline at end of file diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp deleted file mode 100644 index 4d1190d5..00000000 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -namespace py = pybind11; - -PYBIND11_MODULE(skcdemo, m) { - m.def("hello", [](){ - py::print("Hello, pybind11!"); - }); -} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index e2c9d130..df6f3b87 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -1,17 +1,23 @@ +from __future__ import annotations + +from setuptools import setup # isort:skip + # Available at setup time due to pyproject.toml -from pybind11.setup_helpers import Pybind11Extension -from setuptools import setup +from pybind11.setup_helpers import Pybind11Extension # isort:skip + +# Note: +# Sort input source files if you glob sources to ensure bit-for-bit +# reproducible builds (https://github.com/pybind/python_example/pull/53) + +ext_modules = [ + Pybind11Extension( + "{{ cookiecutter.project_slug }}._core", + ["src/main.cpp"], + cxx_std=11, + ), +] setup( - name="OSL Python package", - author="{{cookiecutter.author_full_name}}", - author_email="{{cookiecutter.author_email}}", - url="https://{{ cookiecutter.project_slug }}.com", - description="A test project using pybind11", - long_description="", - #extras_require={"test": "pytest"}, - # Currently, build_ext only provides an optional "highest supported C++ - # level" feature, but in the future it may provide more features. - python_requires=">=3.7", -) + ext_modules=ext_modules, +) \ No newline at end of file diff --git a/tests/smoke/base.sh b/tests/smoke/base.sh index bed4f72f..a693e027 100755 --- a/tests/smoke/base.sh +++ b/tests/smoke/base.sh @@ -57,11 +57,6 @@ elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then pip install -e . elif [ "$(pip list|grep -c pybind11)" -ne "0" ]; then # Assuming you are inside the root of the CMake source directory - mkdir build - cd build - cmake .. - cmake --build . - cd .. pip install -e . else # use setuptools From 2e84ac2919f6aae6f2b0152affdac00152272a34 Mon Sep 17 00:00:00 2001 From: ayeankit Date: Sat, 5 Aug 2023 19:44:52 +0530 Subject: [PATCH 05/33] added setup.py --- .../{{cookiecutter.project_slug}}/build-system/main.cpp | 2 +- .../{{cookiecutter.project_slug}}/build-system/setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp b/src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp index 736960ce..2b8ed183 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp @@ -25,4 +25,4 @@ PYBIND11_MODULE(_core, m) { Subtract two numbers Some other explanation about the subtract function. )pbdoc"); -} \ No newline at end of file +} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index df6f3b87..bceddf12 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -20,4 +20,4 @@ setup( ext_modules=ext_modules, -) \ No newline at end of file +) From 1f04f8eadf45dd6882dfa7f5ba1e718491b03970 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Sat, 5 Aug 2023 19:48:46 +0530 Subject: [PATCH 06/33] Update guide.md --- docs/guide.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/guide.md b/docs/guide.md index 65516829..75c4aa12 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -336,7 +336,17 @@ packages. SciCookie support the following: it a valuable asset for research software engineers. - [**Pybind11**](https://pybind11.readthedocs.io/en/stable/): It's build system designed - for C++ library that simplifies the creation of Python bindings for C++ code, enabling easy integration of C++ functions and classes into Python scripts. It acts as a bridge between the two languages, allowing C++ algorithms and functionality to be directly called from Python as if they were native Python modules. Pybind11's user-friendly syntax reduces boilerplate code, making binding generation more straightforward, while standard C++ build systems like CMake or Make facilitate the compilation of projects using pybind11. Its efficiency, ease of use, and strong community support have made it a popular choice for projects requiring seamless interoperability between C++ and Python, ranging from scientific computing to game development and automation. Staying up-to-date with the latest pybind11 documentation ensures the best practices are followed. + for C++ library that simplifies the creation of Python bindings for C++ code, + enabling easy integration of C++ functions and classes into Python scripts. It + acts as a bridge between the two languages, allowing C++ algorithms and functionality + to be directly called from Python as if they were native Python modules. Pybind11's + user-friendly syntax reduces boilerplate code, making binding generation more + straightforward, while standard C++ build systems like CMake or Make facilitate the + compilation of projects using pybind11. Its efficiency, ease of use, and strong community + support have made it a popular choice for projects requiring seamless interoperability + between C++ and Python, ranging from scientific computing to game development and + automation. Staying up-to-date with the latest pybind11 documentation ensures the + best practices are followed. The idea behind the options in SciCookie is that you can choose from some of the most popular system compilers to suit your needs and preferences for developing From 40433a465d139d3b1facde12aed3917f36ea93df Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:19:33 +0530 Subject: [PATCH 07/33] Update setup.py --- .../{{cookiecutter.project_slug}}/build-system/setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index bceddf12..eeb9e823 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from setuptools import setup # isort:skip # Available at setup time due to pyproject.toml From 7625f4ea4c05b91eb090bca4e5c6a8103a84eadd Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:20:30 +0530 Subject: [PATCH 08/33] Update CMakeLists.txt --- .../{{cookiecutter.project_slug}}/build-system/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt index cb37fdaf..314db3ee 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt @@ -14,7 +14,7 @@ install(TARGETS skcdemo DESTINATION .) find_package(pybind11 CONFIG REQUIRED) -pybind11_add_module(_core MODULE src/main.cpp) +pybind11_add_module(_core MODULE src/{{cookiecutter.project_slug}}/main.cpp) install(TARGETS _core DESTINATION .) From 5e78f261c81e9e29a87f99a2034778219623d56b Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:21:29 +0530 Subject: [PATCH 09/33] Update pybind11-pyproject.toml --- .../build-system/pybind11-pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml index d25c209c..a57786d4 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=42", "wheel", "pybind11~=2.6.1"] +requires = ["setuptools>=65", "wheel", "pybind11~=2.6.1"] build-backend = "setuptools.build_meta" [project] From a61dfc6bef296d13be34e5fe6080b0939bf6d1f0 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:22:30 +0530 Subject: [PATCH 10/33] Update base.sh --- tests/smoke/base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke/base.sh b/tests/smoke/base.sh index a693e027..aaf37c32 100755 --- a/tests/smoke/base.sh +++ b/tests/smoke/base.sh @@ -57,7 +57,7 @@ elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then pip install -e . elif [ "$(pip list|grep -c pybind11)" -ne "0" ]; then # Assuming you are inside the root of the CMake source directory - pip install -e . + pip install . else # use setuptools pip install --editable . From 4c4877c30318dda6292d23449c4cc2e25e587454 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 23:12:42 +0530 Subject: [PATCH 11/33] Update base.sh --- tests/smoke/base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke/base.sh b/tests/smoke/base.sh index aaf37c32..a693e027 100755 --- a/tests/smoke/base.sh +++ b/tests/smoke/base.sh @@ -57,7 +57,7 @@ elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then pip install -e . elif [ "$(pip list|grep -c pybind11)" -ne "0" ]; then # Assuming you are inside the root of the CMake source directory - pip install . + pip install -e . else # use setuptools pip install --editable . From 5dfb8c52fba4d9613ed2c311819c8b875023dda2 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 23:13:27 +0530 Subject: [PATCH 12/33] Update setup.py --- .../{{cookiecutter.project_slug}}/build-system/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index eeb9e823..6c0f46bf 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -10,7 +10,7 @@ ext_modules = [ Pybind11Extension( "{{ cookiecutter.project_slug }}._core", - ["src/main.cpp"], + ["src/{{cookiecutter.project_slug}}/main.cpp"], cxx_std=11, ), ] From 0b252fc7538040451d13ff5feb0d4598e7731f0f Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 23:35:12 +0530 Subject: [PATCH 13/33] Update base.sh --- tests/smoke/base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke/base.sh b/tests/smoke/base.sh index a693e027..aaf37c32 100755 --- a/tests/smoke/base.sh +++ b/tests/smoke/base.sh @@ -57,7 +57,7 @@ elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then pip install -e . elif [ "$(pip list|grep -c pybind11)" -ne "0" ]; then # Assuming you are inside the root of the CMake source directory - pip install -e . + pip install . else # use setuptools pip install --editable . From c95ebadd104616415e53c4699b0a54835ab50b21 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Mon, 7 Aug 2023 23:36:06 +0530 Subject: [PATCH 14/33] Update setup.py --- .../{{cookiecutter.project_slug}}/build-system/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index 6c0f46bf..eeb9e823 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -10,7 +10,7 @@ ext_modules = [ Pybind11Extension( "{{ cookiecutter.project_slug }}._core", - ["src/{{cookiecutter.project_slug}}/main.cpp"], + ["src/main.cpp"], cxx_std=11, ), ] From c5930050b8fbc02d7f7761362e64e2f90cec874c Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Tue, 8 Aug 2023 02:26:21 +0530 Subject: [PATCH 15/33] Update CMakeLists.txt --- .../{{cookiecutter.project_slug}}/build-system/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt index 314db3ee..aa6dc7aa 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/CMakeLists.txt @@ -16,6 +16,6 @@ find_package(pybind11 CONFIG REQUIRED) pybind11_add_module(_core MODULE src/{{cookiecutter.project_slug}}/main.cpp) -install(TARGETS _core DESTINATION .) +install(TARGETS _core DESTINATION src/{{cookiecutter.project_slug}}/main.cpp ) {%- endif %} From 653e0499e1ef8c949fe4c984efcea5860a7e099e Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 02:22:16 +0530 Subject: [PATCH 16/33] Update pybind11-pyproject.toml --- .../build-system/pybind11-pyproject.toml | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml index a57786d4..3c627f29 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=65", "wheel", "pybind11~=2.6.1"] +requires = ["setuptools>=65", "wheel", "pybind11~=2.11.1"] build-backend = "setuptools.build_meta" [project] @@ -39,74 +39,76 @@ requires-python = ">=3.8.1" dependencies = [ {# keep this line here #} {%- if cookiecutter.use_pytest == "yes" -%} - "pytest >= 7.3.2", + "pytest >= 7.3.2,<8", {% if cookiecutter.use_coverage == "yes" -%} - "pytest-cov >= 4.1.0", + "pytest-cov >= 4.1.0,<5", {% endif %} {%- endif -%}{#- end of use_pytest -#} {%- if cookiecutter.use_hypothesis == "yes" -%} - "hypothesis >= 6.0", + "hypothesis >= 6.0,<7", {% endif %} {%- if cookiecutter.use_coverage == "yes" -%} - "coverage >= 7.2.7", + "coverage >= 7.2.7,<8", {% endif %} {%- if cookiecutter.use_blue == "yes" -%} - "blue >= 0.9.1", + "blue >= 0.9.1,<1", {% endif %} {%- if cookiecutter.use_black == "yes" -%} - "black >= 23.3.0", + "black >= 23.3.0,<24", {% endif %} {%- if cookiecutter.use_isort == "yes" -%} - "isort >= 5.12.0", + "isort >= 5.12.0,<6", {% endif %} {%- if cookiecutter.use_pre_commit -%} - "pre-commit >= 3.3.2", + "pre-commit >= 3.3.2,<4", {% endif %} {%- if cookiecutter.use_flake8 == "yes" -%} "flake8 >= 4.0.1, < 7", {% endif %} {%- if cookiecutter.use_ruff == "yes" -%} - "ruff >= 0.0.272", + "ruff >= 0.0.272,<1", {% endif %} {%- if cookiecutter.use_mypy == "yes" -%} - "mypy >= 1.3.0", + "mypy >= 1.3.0,<2", {% endif %} {%- if cookiecutter.use_bandit == "yes" -%} - "bandit >= 1.7.5", + "bandit >= 1.7.5,<2", {% endif %} {%- if cookiecutter.use_pydocstyle == "yes" -%} - "pydocstyle >= 6.3.0", + "pydocstyle >= 6.3.0,<7", {% endif %} {%- if cookiecutter.use_vulture == "yes" -%} - "vulture >= 2.7", + "vulture >= 2.7,<3", {% endif %} {%- if cookiecutter.use_mccabe == "yes" -%} - "mccabe >= 0.6.1", + "mccabe >= 0.6.1,<1", {% endif %} {%- if cookiecutter.use_containers in ['Docker', 'Podman'] -%} # if you want to use docker-compose from your system, remove compose-go here - "compose-go >= 2.18.1", + "compose-go >= 2.18.1,<3", {% endif %} + "ipython < 8", + "ipykernel >=6.0.0", {%- if cookiecutter.documentation_engine == 'mkdocs' -%} - "Jinja2 >= 3.1.2", - "mkdocs >= 1.4.3", - "mkdocs-exclude >= 1.0.2", - "mkdocs-jupyter >= 0.24.1", - "mkdocs-literate-nav >= 0.6.0", + "Jinja2 >=3.1.2,<4", + "mkdocs >=1.4.3,<2", + "mkdocs-exclude >= 1.0.2,<2", + "mkdocs-jupyter >= 0.24.1,<1", + "mkdocs-literate-nav >= 0.6.0,<1", "mkdocs-macros-plugin >= 0.7.0, < 1", - "mkdocs-material >= 9.1.15", - "mkdocstrings >= 0.21.2", - "mkdocstrings-python >= 1.1.2", + "mkdocs-material >= 9.1.15,<10", + "mkdocstrings >= 0.21.2,< 1", + "mkdocstrings-python >= 1.1.2,<2", {% elif cookiecutter.documentation_engine == 'sphinx' -%} - "Sphinx >= 6.2.1", - "sphinx-rtd-theme >= 1.2.2", - "importlib-metadata >= 6.5.1", - "myst-parser >= 0.19.2", - "nbsphinx >= 0.9.2", - "pandoc >= 2.3", + "Sphinx >= 6.2.1,<7", + "sphinx-rtd-theme >= 1.2.2,<2", + "importlib-metadata >= 6.5.1,<7", + "myst-parser >= 0.19.2,<1", + "nbsphinx >= 0.9.2,<1", + "pandoc >= 2.3,<3", {% elif cookiecutter.documentation_engine == 'jupyter-book' -%} - "jupyter-book >= 0.15.1", - "myst-parser >= 0.18.1", + "jupyter-book >= 0.15.1,<1", + "myst-parser >= 0.18.1,<1", {% endif %} ] From 535c090f86fc88026350d9314a44ec6ce355abe3 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:01:54 +0530 Subject: [PATCH 17/33] Update setup.py --- .../{{cookiecutter.project_slug}}/build-system/setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index eeb9e823..25aab6e3 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -17,5 +17,8 @@ setup( + name="{{cookiecutter.project_slug}}", + version="{{cookiecutter.project_version}}", + packages=["{{cookiecutter.project_slug}}"], ext_modules=ext_modules, ) From 83dc6e0c814944c55a784ddb92fa76053f09b08c Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:14:48 +0530 Subject: [PATCH 18/33] Update setup.py --- .../{{cookiecutter.project_slug}}/build-system/setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py index 25aab6e3..eeb9e823 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py @@ -17,8 +17,5 @@ setup( - name="{{cookiecutter.project_slug}}", - version="{{cookiecutter.project_version}}", - packages=["{{cookiecutter.project_slug}}"], ext_modules=ext_modules, ) From 5359d5c8404a83728bba5f4dc73dd11985b0bce9 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:19:12 +0530 Subject: [PATCH 19/33] Update Makefile --- src/scicookie/{{cookiecutter.project_slug}}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index c179b470..3871548f 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -116,7 +116,7 @@ build: {%- elif cookiecutter.build_system == "maturin" %} maturin build {%- elif cookiecutter.build_system == "pybind11" %} - pybind11 build + python3 -m build {%- endif %} From c79bb3b618c9b5d554878683604c9b533c4a9abd Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:03:48 +0530 Subject: [PATCH 20/33] Create pybind11 --- .../{{cookiecutter.project_slug}}/build-system/pybind11 | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 @@ -0,0 +1 @@ + From 4ec2dfe06fb80a61c182fb5309d5125d36bcb3a9 Mon Sep 17 00:00:00 2001 From: ayeankit Date: Wed, 9 Aug 2023 22:38:28 +0530 Subject: [PATCH 21/33] pre-commit clear --- src/scicookie/{{cookiecutter.project_slug}}/Makefile | 2 +- .../{{cookiecutter.project_slug}}/build-system/pybind11 | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index 3871548f..c179b470 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -116,7 +116,7 @@ build: {%- elif cookiecutter.build_system == "maturin" %} maturin build {%- elif cookiecutter.build_system == "pybind11" %} - python3 -m build + pybind11 build {%- endif %} diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 deleted file mode 100644 index 8b137891..00000000 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11 +++ /dev/null @@ -1 +0,0 @@ - From bf7529d15caa74bd367064f5decedbd4d12880d9 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 22:54:08 +0530 Subject: [PATCH 22/33] Update Makefile --- src/scicookie/{{cookiecutter.project_slug}}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index c179b470..d54535e8 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -116,7 +116,7 @@ build: {%- elif cookiecutter.build_system == "maturin" %} maturin build {%- elif cookiecutter.build_system == "pybind11" %} - pybind11 build + python3 -m pip install build {%- endif %} From bf5d323f7ea21dfd1e08a323af38a0d96e3d2cd7 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:26:56 +0530 Subject: [PATCH 23/33] Update src/scicookie/{{cookiecutter.project_slug}}/Makefile Co-authored-by: Saransh Chopra --- src/scicookie/{{cookiecutter.project_slug}}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index d54535e8..559a458f 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -116,7 +116,7 @@ build: {%- elif cookiecutter.build_system == "maturin" %} maturin build {%- elif cookiecutter.build_system == "pybind11" %} - python3 -m pip install build + python -m build {%- endif %} From bcff6678d27e0b4c8ba37246ff72d3c4c9b56796 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:31:14 +0530 Subject: [PATCH 24/33] Update pybind11-pyproject.toml --- .../build-system/pybind11-pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml index 3c627f29..55c93aba 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=65", "wheel", "pybind11~=2.11.1"] +requires = ["setuptools>=65", "wheel", "pybind11~=2.11.1","build"] build-backend = "setuptools.build_meta" [project] From 11ccc2837b81d24b6a136fa8e1defae977f54d21 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:32:53 +0530 Subject: [PATCH 25/33] Update guide.md --- docs/guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide.md b/docs/guide.md index 75c4aa12..bc917ffe 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -335,7 +335,7 @@ packages. SciCookie support the following: builds using CMake and effortless integration with C/C++ libraries, making it a valuable asset for research software engineers. -- [**Pybind11**](https://pybind11.readthedocs.io/en/stable/): It's build system designed +- [**setuptools + pybind11**](https://pybind11.readthedocs.io/en/stable/): It's build system designed for C++ library that simplifies the creation of Python bindings for C++ code, enabling easy integration of C++ functions and classes into Python scripts. It acts as a bridge between the two languages, allowing C++ algorithms and functionality From 4ce85f48e814b2ef12820f83507c520f810d4bfd Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Wed, 9 Aug 2023 23:55:42 +0530 Subject: [PATCH 26/33] Update pybind11-pyproject.toml --- .../build-system/pybind11-pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml index 55c93aba..a414449b 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=65", "wheel", "pybind11~=2.11.1","build"] +requires = ["setuptools>=65", "wheel", "pybind11~=2.11.1","build>=0.10.0"] build-backend = "setuptools.build_meta" [project] From 410d29d10eedc383a80fedfb4c54c7f1596029ed Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:10:55 +0530 Subject: [PATCH 27/33] Update Makefile --- src/scicookie/{{cookiecutter.project_slug}}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index 559a458f..7a37d02e 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -116,7 +116,7 @@ build: {%- elif cookiecutter.build_system == "maturin" %} maturin build {%- elif cookiecutter.build_system == "pybind11" %} - python -m build + python -m pip install build {%- endif %} From a18f98dcd5f6301963d19afca720d1096ea5c315 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:11:47 +0530 Subject: [PATCH 28/33] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 528c8a95..089ff339 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ for a Python package. [Hatch](https://hatch.pypa.io), [Maturin](https://pypi.org/project/maturin/0.8.2/), [scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/) or - [pybind11](https://pybind11.readthedocs.io/en/stable/) + [setuptools + pybind11](https://pybind11.readthedocs.io/en/stable/) based on your preference. - The structure of the project can use the *src layout* or *flat layout*. The “src layout” moving the code that is intended to be From cd8ed24dec5da92b88f0beef91fd294443d8e60a Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:12:32 +0530 Subject: [PATCH 29/33] Update contributing.md --- .../{{cookiecutter.project_slug}}/docs/contributing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md b/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md index 5a1f6699..6f37ced5 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md +++ b/src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md @@ -61,7 +61,7 @@ In addition, you should know that to build our package we use [scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/): It's a Python packaging tool and build system an improved build system generator for CPython C extensions. It provides better support for additional compilers, build systems, cross compilation, and locating dependencies and their associated build requirements.This tool improves package management in the scientific Python ecosystem, enabling cross-platform builds with CMake, and seamless integration with C/C++ libraries for research software engineers. {%- elif cookiecutter.build_system == "pybind11" -%} In addition, you should know that to build our package we use -[pybind11](https://pybind11.readthedocs.io/en/stable/): It's a Python packaging tool for C++ build system that simplifies creating Python bindings for C++ code, allowing easy integration of C++ functions and classes into Python scripts. Acting as a bridge between the two languages, it enables direct calls to C++ functionality from Python as if it were a native Python module. Its user-friendly syntax reduces boilerplate code, while standard C++ build systems like CMake or Make aid in project compilation. Pybind11's efficiency and strong community support make it a popular choice for projects requiring seamless interoperability between C++ and Python, from scientific computing to game development. +[setuptools + pybind11](https://pybind11.readthedocs.io/en/stable/): It's a Python packaging tool for C++ build system that simplifies creating Python bindings for C++ code, allowing easy integration of C++ functions and classes into Python scripts. Acting as a bridge between the two languages, it enables direct calls to C++ functionality from Python as if it were a native Python module. Its user-friendly syntax reduces boilerplate code, while standard C++ build systems like CMake or Make aid in project compilation. Pybind11's efficiency and strong community support make it a popular choice for projects requiring seamless interoperability between C++ and Python, from scientific computing to game development. {%- endif %} From b885513e1d7b85e79cebd4a1a070a003834ebfdd Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:57:41 +0530 Subject: [PATCH 30/33] Update tests/smoke/base.sh Co-authored-by: Ivan Ogasawara --- tests/smoke/base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke/base.sh b/tests/smoke/base.sh index ba858ace..ac8147f1 100755 --- a/tests/smoke/base.sh +++ b/tests/smoke/base.sh @@ -54,7 +54,7 @@ elif command -v hatch &> /dev/null; then elif command -v maturin &> /dev/null; then pip install . elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then - pip install -e . + pip install . elif [ "$(pip list|grep -c pybind11)" -ne "0" ]; then # Assuming you are inside the root of the CMake source directory pip install . From b52b882ebee4ba51d416492ad0a5951832c53e73 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Thu, 10 Aug 2023 01:02:25 +0530 Subject: [PATCH 31/33] Update Makefile --- src/scicookie/{{cookiecutter.project_slug}}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index 7a37d02e..559a458f 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -116,7 +116,7 @@ build: {%- elif cookiecutter.build_system == "maturin" %} maturin build {%- elif cookiecutter.build_system == "pybind11" %} - python -m pip install build + python -m build {%- endif %} From d7114a61bc304e7c393b5364489d156af0cc9167 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Thu, 10 Aug 2023 01:15:59 +0530 Subject: [PATCH 32/33] Update Makefile --- src/scicookie/{{cookiecutter.project_slug}}/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/Makefile b/src/scicookie/{{cookiecutter.project_slug}}/Makefile index 559a458f..3e230a4c 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/Makefile +++ b/src/scicookie/{{cookiecutter.project_slug}}/Makefile @@ -117,7 +117,6 @@ build: maturin build {%- elif cookiecutter.build_system == "pybind11" %} python -m build - {%- endif %} .PHONY:release-ci From 2e4cbf719a02a3c214ecb4f33b547acd02e0b749 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <72691866+ayeankit@users.noreply.github.com> Date: Thu, 10 Aug 2023 02:07:42 +0530 Subject: [PATCH 33/33] added build as dependency --- .../build-system/pybind11-pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml index a414449b..e6c5c05e 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml +++ b/src/scicookie/{{cookiecutter.project_slug}}/build-system/pybind11-pyproject.toml @@ -38,6 +38,7 @@ dynamic = ["version"] requires-python = ">=3.8.1" dependencies = [ {# keep this line here #} + "build>=0.10.0", {%- if cookiecutter.use_pytest == "yes" -%} "pytest >= 7.3.2,<8", {% if cookiecutter.use_coverage == "yes" -%}