Skip to content

Commit

Permalink
added setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeankit committed Aug 5, 2023
1 parent ff88a54 commit 7e83d22
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 37 deletions.
12 changes: 8 additions & 4 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{% 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)

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 %}
28 changes: 28 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/build-system/main.cpp
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");
}

This file was deleted.

32 changes: 19 additions & 13 deletions src/scicookie/{{cookiecutter.project_slug}}/build-system/setup.py
Original file line number Diff line number Diff line change
@@ -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,
)
5 changes: 0 additions & 5 deletions tests/smoke/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e83d22

Please sign in to comment.