-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat(template): Added pybind11 as an option for build system #163
Changes from 10 commits
f816654
e9c6226
ff88a54
7e83d22
2e84ac2
1f04f8e
40433a4
7625f4e
5e78f26
a61dfc6
4c4877c
5dfb8c5
0b252fc
c95ebad
c593005
653e049
535c090
83dc6e0
5359d5c
c79bb3b
642b9ba
4ec2dfe
bf7529d
bf5d323
bcff667
11ccc28
4ce85f4
410d29d
a18f98d
cd8ed24
b885513
b52b882
d7114a6
2e4cbf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 / "setup.py", | ||
PROJECT_DIRECTORY / 'setup.py' | ||
) | ||
else: | ||
shutil.move( | ||
build_system_dir / "base-pyproject.toml", | ||
|
@@ -279,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" | ||
Comment on lines
+310
to
+311
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an interesting discussion ... maybe we can return to this discussion to check how we should proceed not just for this build-system but maybe for all build-systems. |
||
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 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,9 @@ build: | |
hatch build | ||
{%- elif cookiecutter.build_system == "maturin" %} | ||
maturin build | ||
{%- elif cookiecutter.build_system == "pybind11" %} | ||
pybind11 build | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this command exists? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can use something like ensure you have |
||
|
||
{%- endif %} | ||
|
||
.PHONY:release-ci | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <pybind11/pybind11.h> | ||
|
||
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"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
[build-system] | ||
requires = ["setuptools>=65", "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" | ||
|
||
|
||
{% include "build-system/base-pyproject.toml" %} | ||
{#- keep this line at the end of the file -#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from setuptools import setup # isort:skip | ||
|
||
# Available at setup time due to pyproject.toml | ||
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"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should take a look at the path here again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an interesting discussion .. but I think we can have this discussion after we merge this PR |
||
cxx_std=11, | ||
), | ||
] | ||
|
||
|
||
setup( | ||
ext_modules=ext_modules, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,9 @@ elif command -v maturin &> /dev/null; then | |
pip install -e . | ||
elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then | ||
pip install -e . | ||
ayeankit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif [ "$(pip list|grep -c pybind11)" -ne "0" ]; then | ||
# Assuming you are inside the root of the CMake source directory | ||
pip install . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should still be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in my last PR I removed |
||
else | ||
# use setuptools | ||
pip install --editable . | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call it something like
setuptools + pybind11
to be more clear, given thatpybind11
itself is not a backend?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or atleast using "setuptools + pybind11" in all the user-facing locations, and just "pybind11" in the internals of
scicookie
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that be confusing since we are using setuptools as default build-sytem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really ... setuptools is the default option because it was the first one historically, but a lot of people want to kill that. That is why a bunch of project are looking for new alternatives.
but for c/c++ code setuptools is still a great option.
so specifying setuptools + pybind11 makes a lot of sense, because it is clear about its structure.