From 670ee4cb46d7fe8ec1d5717080be9688a0846b86 Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Fri, 20 Sep 2024 17:51:55 +0800 Subject: [PATCH] boilerplate --- MANIFEST.in | 6 +++++- actuator/.gitignore | 5 +++++ actuator/rust/.gitignore | 4 ++++ actuator/rust/Cargo.toml | 11 +++++++++++ actuator/rust/src/lib.rs | 7 +++++++ pyproject.toml | 5 +++++ setup.py | 29 +++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 actuator/.gitignore create mode 100644 actuator/rust/.gitignore create mode 100644 actuator/rust/Cargo.toml create mode 100644 actuator/rust/src/lib.rs diff --git a/MANIFEST.in b/MANIFEST.in index a4d5c59..cbdb094 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,5 @@ -recursive-include actuator/ *.py *.txt py.typed MANIFEST.in +include actuator/rust/Cargo.toml +include actuator/rust/Cargo.lock +include actuator/rust/*.so +include actuator/rust/*.pyi +recursive-include actuator/rust/src *.rs diff --git a/actuator/.gitignore b/actuator/.gitignore new file mode 100644 index 0000000..ce416c2 --- /dev/null +++ b/actuator/.gitignore @@ -0,0 +1,5 @@ +# .gitignore + +# Rust +target/ +Cargo.lock diff --git a/actuator/rust/.gitignore b/actuator/rust/.gitignore new file mode 100644 index 0000000..c3cb797 --- /dev/null +++ b/actuator/rust/.gitignore @@ -0,0 +1,4 @@ +# .gitignore + +*.so +*.pyi diff --git a/actuator/rust/Cargo.toml b/actuator/rust/Cargo.toml new file mode 100644 index 0000000..9e843a8 --- /dev/null +++ b/actuator/rust/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "lib" +version = "0.1.0" +edition = "2021" + +[lib] +name = "lib" +crate-type = ["cdylib"] + +[dependencies] +pyo3 = { version = "0.17", features = ["extension-module"] } diff --git a/actuator/rust/src/lib.rs b/actuator/rust/src/lib.rs new file mode 100644 index 0000000..9ec676b --- /dev/null +++ b/actuator/rust/src/lib.rs @@ -0,0 +1,7 @@ +use pyo3::prelude::*; + +#[pymodule] +fn lib(_py: Python, _m: &PyModule) -> PyResult<()> { + println!("Hello, world!"); + Ok(()) +} diff --git a/pyproject.toml b/pyproject.toml index 2c277aa..8158121 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,3 +70,8 @@ combine-as-imports = true [tool.ruff.lint.pydocstyle] convention = "google" + +[build-system] + +requires = ["setuptools>=42", "wheel", "setuptools-rust>=1.5.2"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 963c70d..25e1f44 100644 --- a/setup.py +++ b/setup.py @@ -2,9 +2,24 @@ #!/usr/bin/env python """Setup script for the project.""" +import os import re +import subprocess from setuptools import setup +from setuptools.command.build_ext import build_ext as _build_ext +from setuptools_rust import Binding, RustExtension + + +class BuildExtWithStubgen(_build_ext): + def run(self) -> None: + super().run() + + module_name = "actuator.rust.lib" + output_dir = os.path.dirname(__file__) + os.makedirs(output_dir, exist_ok=True) + subprocess.run(["stubgen", "-m", module_name, "-o", output_dir], check=False) + with open("README.md", "r", encoding="utf-8") as f: long_description: str = f.read() @@ -30,6 +45,20 @@ description="The actuator project", author="Benjamin Bolte", url="https://github.com/kscalelabs/actuator", + rust_extensions=[ + RustExtension( + target="actuator.rust.lib", + path="actuator/rust/Cargo.toml", + binding=Binding.PyO3, + ) + ], + cmdclass={"build_ext": BuildExtWithStubgen}, + setup_requires=[ + "setuptools-rust", + "mypy", # For stubgen + ], + include_package_data=True, + zip_safe=False, long_description=long_description, long_description_content_type="text/markdown", python_requires=">=3.11",