Skip to content

IDEA: plugin system #61

Description

@henryiii

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions