Skip to content
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

Stub pyi file autogen using pyo3-stub-gen #237

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 189 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "README.md"

[lib]
name = "egobox"
crate-type = ["cdylib"]
crate-type = ["cdylib", "rlib"]

[features]
default = []
Expand Down Expand Up @@ -48,3 +48,8 @@ serde_json.workspace = true
ctrlc.workspace = true

argmin_testfunctions.workspace = true
pyo3-stub-gen = { path = "../../pyo3-stub-gen/pyo3-stub-gen", features = ["numpy"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change in Jij-Inc/pyo3-stub-gen#142 required.


[[bin]]
name = "stub_gen"
doc = false
3 changes: 2 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ build-backend = "maturin"
requires = ["maturin>=1.0, <2.0"]

[tool.maturin]
python-source = "./"
python-source = "egobox"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will make pyo3-stub-gen to put egobox.pyi inside python/egobox, I hope it is corrected?

module-name = "egobox"
features = ["pyo3/extension-module"]
# Optional usage of BLAS backend
# cargo-extra-args = "--features linfa/intel-mkl-static"
Expand Down
8 changes: 8 additions & 0 deletions python/src/bin/stub_gen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use pyo3_stub_gen::Result;

fn main() -> Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().filter_or("RUST_LOG", "info")).init();
let stub = egobox::stub_info()?;
stub.generate()?;
Ok(())
}
5 changes: 5 additions & 0 deletions python/src/egor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ndarray::{concatenate, Array1, Array2, ArrayView2, Axis};
use numpy::{IntoPyArray, PyArray1, PyArray2, PyArrayMethods, PyReadonlyArray2, ToPyArray};
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pyfunction, gen_stub_pymethods};

/// Utility function converting `xlimits` float data list specifying bounds of x components
/// to x specified as a list of XType.Float types [egobox.XType]
Expand All @@ -25,6 +26,7 @@ use pyo3::prelude::*;
///
/// # Returns
/// xtypes: nx-size list of XSpec(XType(FLOAT), [lower_bound, upper_bounds]) where `nx` is the dimension of x
#[gen_stub_pyfunction]
#[pyfunction]
pub(crate) fn to_specs(py: Python, xlimits: Vec<Vec<f64>>) -> PyResult<PyObject> {
if xlimits.is_empty() || xlimits[0].is_empty() {
Expand Down Expand Up @@ -149,6 +151,7 @@ pub(crate) fn to_specs(py: Python, xlimits: Vec<Vec<f64>>) -> PyResult<PyObject>
/// seed (int >= 0)
/// Random generator seed to allow computation reproducibility.
///
#[gen_stub_pyclass]
#[pyclass]
pub(crate) struct Egor {
pub xspecs: PyObject,
Expand All @@ -174,6 +177,7 @@ pub(crate) struct Egor {
pub seed: Option<u64>,
}

#[gen_stub_pyclass]
#[pyclass]
pub(crate) struct OptimResult {
#[pyo3(get)]
Expand All @@ -186,6 +190,7 @@ pub(crate) struct OptimResult {
y_doe: Py<PyArray2<f64>>,
}

#[gen_stub_pymethods]
#[pymethods]
impl Egor {
#[new]
Expand Down
Loading
Loading