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

IDEA: plugin system #61

Open
henryiii opened this issue Aug 26, 2021 · 1 comment
Open

IDEA: plugin system #61

henryiii opened this issue Aug 26, 2021 · 1 comment

Comments

@henryiii
Copy link

henryiii commented Aug 26, 2021

I really like cppimport for quick tests and local work. However, there's one irritating part I always have to look up:

/*
<%
setup_pybind11(cfg)
%>
*/

This has two issues - one it's a special, parsed magic that requires changing the C++ code, and two, it's hard-coded into cppimport; if someone wanted to support something besides pybind11, it would need a new function like this. I'd like to propose a plugin system that allows pybind11 to declare what it needs for setup that could also be used elsewhere. I can help get the pybind11 part into the pybind11 package. :)

The idea I'm currently thinking of is the following. Users could use:

# Global
cppimport.plugin.pybind11.import_hook
import foobar

# Local
foobar = cppimport.plugin.pybind11.imp("foobar")
foobar = cppimport.plugin.pybind11.imp_from_filepath("src/foobar.cpp")

It would be also available in cpp mode to support "classic" usage:

/*
<%
cppimport.plugin.pybind11.setup(cfg)
%>
*/

A package (pybind11 in this case) would implement an entrypoint, cppimport.setup: pybind11 = .... When you access cppimport.plugin.<attr>, it looks for <attr> item in the cppimport.setup entry points. If found, it calls it with some to-be-determined API, possibly just "cfg" like the current setup_pybind11. No modification or special magic comments needed in the source code.

Thoughts? Also, a way to set config options would be important, which I haven't addressed above. I think import_hook could be replaced with something callable, like setup_import_hook, which would take cfg options. imp* could take configuration options too.

@tbenthompson
Copy link
Owner

Sorry for such a delayed response! I would be supportive of a change like this. I think your proposed API is pretty reasonable. I won't have time to work on this, but I would happily review some changes! Thanks so much for thinking about this in detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants