Skip to content

Commit 32b536f

Browse files
committed
Use scikit build
1 parent 42cade9 commit 32b536f

5 files changed

Lines changed: 175 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[build-system]
2+
requires = ["scikit-build-core>=0.10", "pybind11"]
3+
build-backend = "scikit_build_core.build"
4+
5+
6+
[project]
7+
name = "libcachesim"
8+
version = "0.0.1"
9+
description="Python bindings for libCacheSim"
10+
readme = "README.md"
11+
requires-python = ">=3.9"
12+
13+
[project.optional-dependencies]
14+
test = ["pytest"]
15+
16+
17+
[tool.scikit-build]
18+
wheel.expand-macos-universal-tags = true
19+
minimum-version = "build-system.requires"
20+
21+
22+
[tool.pytest.ini_options]
23+
minversion = "8.0"
24+
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
25+
xfail_strict = true
26+
log_cli_level = "INFO"
27+
filterwarnings = [
28+
"error",
29+
"ignore::pytest.PytestCacheWarning",
30+
]
31+
testpaths = ["tests"]
32+
33+
34+
[tool.cibuildwheel]
35+
build-frontend = "build[uv]"
36+
test-command = "pytest {project}/tests"
37+
test-extras = ["test"]
38+
39+
[tool.cibuildwheel.pyodide]
40+
build-frontend = {name = "build", args = ["--exports", "whole_archive"]}
41+
42+
[tool.ruff.lint]
43+
extend-select = [
44+
"B", # flake8-bugbear
45+
"I", # isort
46+
"ARG", # flake8-unused-arguments
47+
"C4", # flake8-comprehensions
48+
"EM", # flake8-errmsg
49+
"ICN", # flake8-import-conventions
50+
"G", # flake8-logging-format
51+
"PGH", # pygrep-hooks
52+
"PIE", # flake8-pie
53+
"PL", # pylint
54+
"PT", # flake8-pytest-style
55+
"PTH", # flake8-use-pathlib
56+
"RET", # flake8-return
57+
"RUF", # Ruff-specific
58+
"SIM", # flake8-simplify
59+
"T20", # flake8-print
60+
"UP", # pyupgrade
61+
"YTT", # flake8-2020
62+
"EXE", # flake8-executable
63+
"NPY", # NumPy specific rules
64+
"PD", # pandas-vet
65+
]
66+
ignore = [
67+
"PLR09", # Too many X
68+
"PLR2004", # Magic comparison
69+
]
70+
isort.required-imports = ["from __future__ import annotations"]
71+
72+
[tool.ruff.lint.per-file-ignores]
73+
"tests/**" = ["T20"]

python/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Modified from https://github.com/pybind/scikit_build_example/blob/master/CMakeLists.txt
2+
cmake_minimum_required(VERSION 3.15...3.27)
3+
4+
project(
5+
${SKBUILD_PROJECT_NAME}
6+
VERSION ${SKBUILD_PROJECT_VERSION}
7+
LANGUAGES CXX)
8+
9+
# find python and pybind11
10+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
11+
find_package(pybind11 CONFIG REQUIRED)
12+
13+
# add libCacheSim library
14+
add_subdirectory(.. ${CMAKE_CURRENT_BINARY_DIR}/libCacheSim)
15+
16+
# create python module
17+
python_add_library(_libcachesim MODULE
18+
src/pylibcachesim.cpp
19+
WITH_SOABI
20+
)
21+
22+
target_link_libraries(_libcachesim PRIVATE
23+
pybind11::headers
24+
libCacheSim # link libCacheSim
25+
)
26+
27+
target_compile_definitions(_libcachesim PRIVATE VERSION_INFO=${PROJECT_VERSION})
28+
29+
# install to wheel directory
30+
install(TARGETS _libcachesim DESTINATION libcachesim)

python/libcachesim/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from __future__ import annotations
2+
3+
4+
# TODO(haocheng): add meaningful methods
5+
from ._libcachesim import *
6+
7+
__all__ = ["__doc__", "__version__"]

python/libcachesim/__init__.pyi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
libCacheSim Python bindings
3+
--------------------------
4+
5+
.. currentmodule:: libcachesim
6+
7+
.. autosummary::
8+
:toctree: _generate
9+
10+
TODO(haocheng): add meaningful methods
11+
add
12+
subtract
13+
"""
14+
15+
def add(i: int, j: int) -> int:
16+
"""
17+
Add two numbers
18+
19+
Some other explanation about the add function.
20+
"""

python/src/pylibcachesim.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <pybind11/pybind11.h>
2+
#include "libCacheSim.h"
3+
4+
#define STRINGIFY(x) #x
5+
#define MACRO_STRINGIFY(x) STRINGIFY(x)
6+
7+
// int add(int i, int j) {
8+
// return i + j;
9+
// }
10+
11+
namespace py = pybind11;
12+
13+
PYBIND11_MODULE(_libcachesim, m) {
14+
m.doc() = R"pbdoc(
15+
libCacheSim Python bindings
16+
--------------------------
17+
18+
.. currentmodule:: libcachesim
19+
20+
.. autosummary::
21+
:toctree: _generate
22+
23+
TODO(haocheng): add meaningful methods
24+
add
25+
subtract
26+
)pbdoc";
27+
28+
// m.def("add", &add, R"pbdoc(
29+
// Add two numbers
30+
31+
// Some other explanation about the add function.
32+
// )pbdoc");
33+
34+
// m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc(
35+
// Subtract two numbers
36+
37+
// Some other explanation about the subtract function.
38+
// )pbdoc");
39+
40+
#ifdef VERSION_INFO
41+
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
42+
#else
43+
m.attr("__version__") = "dev";
44+
#endif
45+
}

0 commit comments

Comments
 (0)