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

Create stubs without a pyproject.toml #71

Open
abrisco opened this issue Aug 28, 2024 · 4 comments · May be fixed by #99
Open

Create stubs without a pyproject.toml #71

abrisco opened this issue Aug 28, 2024 · 4 comments · May be fixed by #99
Labels
enhancement New feature or request

Comments

@abrisco
Copy link

abrisco commented Aug 28, 2024

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
Copy link
Collaborator

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.

@termoshtt termoshtt added the enhancement New feature or request label Aug 29, 2024
@abrisco
Copy link
Author

abrisco commented Aug 31, 2024

@termoshtt I have created abrisco/rules_pyo3#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
Copy link
Author

abrisco commented Sep 10, 2024

@termoshtt friendly ping 😄

@abrisco
Copy link
Author

abrisco commented Sep 30, 2024

@termoshtt another ping. I'm happy to make a PR I just want sign-off on an implementation 🙏

@tvanbaak tvanbaak linked a pull request Nov 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants