Jij-Inc / pyo3-stub-gen

Stub file (*.pyi) generator for PyO3
Apache License 2.0
39 stars 5 forks source link

Create stubs without a `pyproject.toml` #71

Open abrisco opened 2 weeks ago

abrisco commented 2 weeks ago

Hi, would it be possible/realistic to configure StubInfo and StubInfoBuilder to work without needing a pyproject.toml? I would like to integrate this into Bazel which does not use pyproject.toml and it doesn't appear that I have any other means of defining the output location for pyi files, nor can I specify the module name. It would be great if I could explicitly specify both of these so I could write something like this:

fn main() -> pyo3_stub_gen::Result<()> {
    env_logger::Builder::from_env(env_logger::Env::default().filter_or("RUST_LOG", "info")).init();

    let stub = pyo3_stub_gen::StubInfo::new(
        /* module_name = */ env!("CUSTOM_MODULE_NAME"),
        /* output = */ PathBuff::from(env!("CUSTOM_OUTPUT")),
    );

    stub.generate()?;

    Ok(())
}

Does this sound roughly like an acceptable idea and do maintainers have thoughts on the additions/changes to the existing interface?

Thanks!

termoshtt commented 2 weeks ago

It is potentially possible to initialize StubInfo without pyproject.toml. As you say, what we need is the module name and where the stub file is generated. Rather, I never try to build PyO3 project by Bazel (or other than maturin). Could you share a link describing how to setup Bazel based PyO3 project? It could help to support resolving this issue.

abrisco commented 2 weeks ago

@termoshtt I have created https://github.com/abrisco/rules_pyo3/pull/3 to try and integrate this tool into some Bazel rules I wrote and am stuck at the point where I need to figure out how to write stubs to a specific location https://github.com/abrisco/rules_pyo3/blob/5a9b1dffaa8a6840446c0387dd7b0c56e9db7fdb/pyo3/private/pyo3_stub_generator.rs#L1-L11

The command line arguments to this script are currently that argv[1] is the output location and my hope was that I can deduce the module name from the crate itself. Hopefully this gives you the insight you needed into my desired use case.

abrisco commented 4 days ago

@termoshtt friendly ping 😄