diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..f648169 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,6 @@ +[target.aarch64-apple-darwin] + +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] diff --git a/.gitignore b/.gitignore index ae8e28a..38f9946 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ build/ dist/ *.so out*/ + +# Rust +target/ +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3318581 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,20 @@ +[workspace] +members = [ + "actuator/rust", +] +resolver = "2" + +[workspace.package] +version = "0.1.0" +edition = "2021" + +description = "Actuator Python bindings" +authors = ["K-Scale Labs "] +repository = "https://github.com/kscalelabs/actuator" +license = "MIT" +readme = "README.md" + +[workspace.dependencies] +pyo3 = { version = ">= 0.21.0", features = ["extension-module"] } +pyo3-stub-gen = ">= 0.6.0" +env_logger = "0.11.5" diff --git a/actuator/.gitignore b/actuator/.gitignore deleted file mode 100644 index ce416c2..0000000 --- a/actuator/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# .gitignore - -# Rust -target/ -Cargo.lock diff --git a/actuator/cli.py b/actuator/cli.py new file mode 100644 index 0000000..08c4461 --- /dev/null +++ b/actuator/cli.py @@ -0,0 +1,13 @@ +"""Defines the CLI for the actuator project.""" + +from actuator.rust.lib import hello_world, sum + + +def main() -> None: + hello_world() + print(sum([1, 2, 3, 4, 5])) + + +if __name__ == "__main__": + # python -m actuator.cli + main() diff --git a/actuator/rust/.gitignore b/actuator/rust/.gitignore deleted file mode 100644 index c3cb797..0000000 --- a/actuator/rust/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# .gitignore - -*.so -*.pyi diff --git a/actuator/rust/Cargo.toml b/actuator/rust/Cargo.toml index e47b0a0..35ea6d5 100644 --- a/actuator/rust/Cargo.toml +++ b/actuator/rust/Cargo.toml @@ -1,12 +1,17 @@ [package] name = "lib" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true [lib] name = "lib" crate-type = ["cdylib", "rlib"] [dependencies] -pyo3 = { version = "0.21", features = ["extension-module"] } -pyo3-stub-gen = "0.6.0" +env_logger.workspace = true +pyo3-stub-gen.workspace = true +pyo3.workspace = true + +[[bin]] +name = "stub_gen" +doc = false diff --git a/actuator/rust/__init__.py b/actuator/rust/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/actuator/rust/lib.pyi b/actuator/rust/lib.pyi new file mode 100644 index 0000000..e83bd5f --- /dev/null +++ b/actuator/rust/lib.pyi @@ -0,0 +1,11 @@ +# This file is automatically generated by pyo3_stub_gen +# ruff: noqa: E501, F401 + +import typing + +def hello_world() -> None: + ... + +def sum(v:typing.Sequence[int]) -> int: + ... + diff --git a/actuator/rust/pyproject.toml b/actuator/rust/pyproject.toml new file mode 100644 index 0000000..f080922 --- /dev/null +++ b/actuator/rust/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = ["maturin>=1.1,<2.0"] +build-backend = "maturin" + +[project] +name = "lib" +requires-python = ">=3.9" + +[project.optional-dependencies] +test = ["pytest", "pyright", "ruff"] diff --git a/actuator/rust/src/bin/stub_gen.rs b/actuator/rust/src/bin/stub_gen.rs index e48e995..a01eef0 100644 --- a/actuator/rust/src/bin/stub_gen.rs +++ b/actuator/rust/src/bin/stub_gen.rs @@ -1,7 +1,7 @@ use pyo3_stub_gen::Result; fn main() -> Result<()> { - let stub = pure::stub_info()?; + let stub = lib::stub_info()?; stub.generate()?; Ok(()) } diff --git a/actuator/rust/src/lib.rs b/actuator/rust/src/lib.rs index b1b579d..a78adfe 100644 --- a/actuator/rust/src/lib.rs +++ b/actuator/rust/src/lib.rs @@ -1,19 +1,23 @@ use pyo3::prelude::*; use pyo3_stub_gen::{define_stub_info_gatherer, derive::gen_stub_pyfunction}; +#[gen_stub_pyfunction] #[pyfunction] fn hello_world() { println!("Hello, world!"); } +#[gen_stub_pyfunction] #[pyfunction] -fn add(a: i64, b: i64) -> i64 { - a + b +fn sum(v: Vec) -> u32 { + v.iter().sum() } #[pymodule] -fn lib(py: Python, m: &PyModule) -> PyResult<()> { +fn lib(m: &Bound) -> PyResult<()> { m.add_function(wrap_pyfunction!(hello_world, m)?)?; - m.add_function(wrap_pyfunction!(add, m)?)?; + m.add_function(wrap_pyfunction!(sum, m)?)?; Ok(()) } + +define_stub_info_gatherer!(stub_info); diff --git a/setup.py b/setup.py index 8736746..1f492df 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,8 @@ """Setup script for the project.""" import re -import subprocess -from setuptools import Command, setup +from setuptools import setup from setuptools_rust import Binding, RustExtension with open("README.md", "r", encoding="utf-8") as f: @@ -26,22 +25,6 @@ version: str = version_re.group(1) -class PostInstallCommand(Command): - """Post-installation for installation mode.""" - - description = "Run stub_gen after installation" - user_options = [] - - def initialize_options(self) -> None: - pass - - def finalize_options(self) -> None: - pass - - def run(self) -> None: - subprocess.check_call(["cargo", "run", "--bin", "stub_gen"], cwd="actuator/rust") - - setup( name="actuator", version=version, @@ -53,12 +36,9 @@ def run(self) -> None: target="actuator.rust.lib", path="actuator/rust/Cargo.toml", binding=Binding.PyO3, - ) - ], - setup_requires=[ - "setuptools-rust", - "mypy", # For stubgen + ), ], + setup_requires=["setuptools-rust"], include_package_data=True, zip_safe=False, long_description=long_description, @@ -67,7 +47,4 @@ def run(self) -> None: install_requires=requirements, tests_require=requirements_dev, extras_require={"dev": requirements_dev}, - cmdclass={ - "post_install": PostInstallCommand, - }, )