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

Add test for wrapping C++ library #26

Merged
merged 49 commits into from Oct 8, 2020
Merged

Conversation

mcflugen
Copy link
Member

@mcflugen mcflugen commented Oct 2, 2020

This pull request does a couple things: add tests for wrapping C++ libraries, changes babel.toml (while maintaining backward compatibility).

The main change to babel.toml is to the library section: it is now a dictionary of dictionaries (or table of tables) and removes the entry_point key. The new format (in toml) looks like the following:

[library.HeatBMI]  # HeatBMI is the name of the class in Python
language = "c++"
library = "heat_bmi"  # the library being wrapped, e.g. libheat_bmi.so
header = "heat_bmi.hxx"  # header file that declares the BMI class
class = "Heat"  # the name of the class that implements a BMI

In yaml land this would be,

library: {
    HeatBMI: {
        language: c++,
        library: heat_bmi,
        header: heat_bmi.hxx,
        class: Heat,
    }
}

Using the old-style entry_points, the above is equivalent to HeatBMI=heat_bmi:Heat (notice the old-style doesn't specify a header file, which is a problem for some languages). Multiple [library.*] sections can be provided but, as of now, they all have to be of the same language.

Another change is that the plugin section is now called package as it describes the newly-created Python package. The keys are the same, i.e.

[package]
name = "heat"
requirements = []

The way things are right now, the above would create a new package called pymt_heat but I think we should change it so that a user proves the full name of the package (i.e. name = pymt_heat).

@mcflugen mcflugen requested a review from mdpiper October 2, 2020 00:28
@mdpiper
Copy link
Member

mdpiper commented Oct 2, 2020

@mcflugen This is awesome! I'll update the docs with these changes.

@mcflugen
Copy link
Member Author

mcflugen commented Oct 3, 2020

@mdpiper I ended up changing the package section so that name refers to the full name of the new package. That is, if you want the new package to be called pymt_heat, you would do the following

[package]
name = "pymt_heat"

rather than name = "heat".

For babelize generate I added new options to specify values in the library section and removed the --entry-points option. The example in the README now becomes,

$ babelize generate babel.toml \
    --no-input \
    --package=pymt_hydrotrend \
    --summary="PyMT plugin for hydrotrend" \
    --langauge=c \
    --library=bmi_hydrotrend \
    --header=bmi_hydrotrend.h \
    --class=register_bmi_hydrotrend \
    --name=Hydrotrend \
    --requirement=hydrotrend

Only a single library can be specified with babelize generate. I realize it's not great and isn't concise but it works to get someone started. I'm happy to consider alternatives, if you have ideas.

@mdpiper
Copy link
Member

mdpiper commented Oct 5, 2020

@mcflugen Thanks for doing this. I'll update the README and the docs to use the new syntax.

@mcflugen mcflugen merged commit 11d329b into develop Oct 8, 2020
@mcflugen mcflugen deleted the mcflugen/add-cxx-test branch October 8, 2020 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants