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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2c319f8
Preparing release 0.3.0
mdpiper Sep 24, 2020
dc2cd5c
Merge branch 'develop' of github.com:csdms/babelizer into develop
mcflugen Sep 28, 2020
e3133c4
add bmi-example-cxx submodule
mcflugen Sep 28, 2020
db444f6
build bmi-example-cxx on Travis
mcflugen Sep 28, 2020
33fa3c0
use newest bmi.hxx
mcflugen Sep 28, 2020
9c77349
update BMI; use string and vector types
mcflugen Sep 28, 2020
17ff79a
clean up cookiecutter/jinja variables
mcflugen Sep 30, 2020
537aff7
allow multiple library sections, add optional keywords
mcflugen Sep 30, 2020
f84cfe3
update bmi-example-cxx to v2.1
mcflugen Sep 30, 2020
463c370
remove cookiecutter.entry_points variable
mcflugen Sep 30, 2020
d0a8fe0
add test for babelizing a c++ library
mcflugen Sep 30, 2020
b1e162f
rename plugin->package, pymt_class->babelized_class
mcflugen Oct 1, 2020
652593d
rename template folders for package
mcflugen Oct 1, 2020
7a1a3d7
handle old-style info, package vs. plugin
mcflugen Oct 1, 2020
f25741e
change remaining plugin to package
mcflugen Oct 1, 2020
8553f28
change library section to a dict of dicts
mcflugen Oct 1, 2020
dc11d89
update test babel.toml files
mcflugen Oct 1, 2020
f8f3441
update cli for new sections
mcflugen Oct 1, 2020
4338aa8
change plugin_name to package_name
mcflugen Oct 1, 2020
733ddf8
fix typo; entry_point, not entry_points
mcflugen Oct 1, 2020
8ba3326
remove lint
mcflugen Oct 1, 2020
377b447
check for lint in tests folder
mcflugen Oct 1, 2020
e8718da
make pretty with black
mcflugen Oct 1, 2020
a924a5e
remove bmi.h, bmi.c; call bmi methods in pyx file
mcflugen Oct 2, 2020
93feb82
remove unused bmi.hxx file
mcflugen Oct 2, 2020
3776a70
set bmi header to bmi_heat.h
mcflugen Oct 2, 2020
bc7c7ec
update bmi-example-c to v2.0.1
mcflugen Oct 2, 2020
d0b2bda
fix bmi_get_value_ptr, bmi_get_grid_type
mcflugen Oct 2, 2020
2cb3df4
remove pymt_ prefix from package name
mcflugen Oct 2, 2020
991044a
add pymt_ prefix to package name in babel.toml
mcflugen Oct 2, 2020
2c978d6
add bmi-c, bmi-cxx, bmi-fortran to requirements.txt
mcflugen Oct 2, 2020
16ed149
remove pymt_ prefix from renderer
mcflugen Oct 2, 2020
46c2ef1
add requirements-build.txt with package build requirements
mcflugen Oct 2, 2020
1b9b31e
add compilers to requirements-testing.txt
mcflugen Oct 2, 2020
db8b23b
removed entry_points, added separate library options
mcflugen Oct 3, 2020
78f3b2d
Update for new babelize generate options
mdpiper Oct 5, 2020
a2cd6a0
Reset changelog
mdpiper Oct 5, 2020
9bcaa7f
Fix typo and formatting
mdpiper Oct 5, 2020
745436f
Update heatc example
mdpiper Oct 5, 2020
4c11e03
change library.class to library.entry_point
mcflugen Oct 6, 2020
76a8587
Merge branch 'mcflugen/add-cxx-test' of github.com:csdms/babelizer in…
mcflugen Oct 6, 2020
2c78933
change --class option to --entry-point
mcflugen Oct 6, 2020
e251fe3
Update README and docs for entry_point option
mdpiper Oct 6, 2020
6fec7af
update test files for class -> entry_point
mcflugen Oct 6, 2020
86591b4
Merge branch 'mcflugen/add-cxx-test' of github.com:csdms/babelizer in…
mcflugen Oct 6, 2020
25d9da9
The option is entry-point, not entry_point
mdpiper Oct 6, 2020
7706772
Update Fortran test input file to latest format
mdpiper Oct 6, 2020
c505d49
check for extra files in an updated package
mcflugen Oct 8, 2020
ccc1b42
remove lint
mcflugen Oct 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -4,3 +4,6 @@
[submodule "external/bmi-example-fortran"]
path = external/bmi-example-fortran
url = https://github.com/csdms/bmi-example-fortran
[submodule "external/bmi-example-cxx"]
path = external/bmi-example-cxx
url = https://github.com/csdms/bmi-example-cxx
9 changes: 7 additions & 2 deletions .travis.yml
Expand Up @@ -45,7 +45,7 @@ before_install:
fi
- micromamba activate
- micromamba install mamba --yes -c conda-forge
- mamba create -n testing python=$PYTHON bmi-c bmi-fortran cmake pkg-config fortran-compiler c-compiler mamba --yes -c conda-forge
- mamba create -n testing python=$PYTHON --file=requirements-testing.txt --yes -c conda-forge
- source activate testing
- |
mkdir _build \
Expand All @@ -59,8 +59,13 @@ before_install:
&& cmake ../external/bmi-example-fortran -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
&& make install \
&& popd
- |
mkdir _buildcxx \
&& pushd _buildcxx \
&& cmake ../external/bmi-example-cxx -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
&& make install \
&& popd
install:
- mamba install --file=requirements-testing.txt --yes -c conda-forge
- pip install .
script:
- babelize --version
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,7 @@ Changelog for babelizer
0.3.2 (unreleased)
------------------

- Nothing changed yet.
- No changes yet


0.3.1 (2020-09-25)
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -52,11 +52,11 @@ clean-test: ## remove test and coverage artifacts
rm -fr .pytest_cache

lint: ## check style with flake8
flake8 babelizer
flake8 babelizer tests

pretty: ## reformat files to make them look pretty
isort --apply --recursive babelizer
black setup.py babelizer --exclude=babelizer/data
isort babelizer tests
black setup.py babelizer tests --exclude=babelizer/data


test: ## run tests quickly with the default Python
Expand Down
192 changes: 120 additions & 72 deletions README.rst
Expand Up @@ -87,14 +87,17 @@ Input file
**********

The *babelizer* requires a single, *toml*-formatted, input file that describes
the library you would like to wrap. This file is typically called, *babel.toml*.
the library you would like to wrap. This file is typically named *babel.toml*.
An example of a blank *babel.toml* file,

.. code:: toml

[library]
[library."<name>"]
language = "c"
entry_point = []
library = ""
header = ""
entry_point = ""

[build]
undef_macros = []
Expand All @@ -104,14 +107,15 @@ An example of a blank *babel.toml* file,
include_dirs = []
extra_compile_args = []

[plugin]
[package]
name = ""
requirements = []

[info]
plugin_author = "csdms"
github_username = "pymt-lab"
plugin_license = "MIT"
package_author = "csdms"
package_author_email = "csdms@colorado.edu"
package_license = "MIT"
summary = ""

You can generate *babel.toml* files using the *babelize generate* command.
Expand All @@ -121,107 +125,143 @@ For example, the above *babel.toml* was generated with,

$ babelize generate --no-input -

Library section
===============

Build section
=============

In the build section the user can specify flags to pass to the compiler
when building the extension.

Info section
============

Descriptive infomation about the package.
The *library* section specifies information about the library being babelized.

Github username
---------------
Name
----

The GitHub username or organization where this package will be hosted. This
is used in generating links to the CI, docs, etc.
The name of the babelized class.
This will be a Python class,
so it should follow Python naming conventions such as camel-case typing.

Author
------
Language
--------

Author of the wrapped package. Note that this is not the author of the
library being wrapped, just the code generated by the *babelizer*.
The programming language of the library (possible values are "c", "c++",
"fortran", and "python").

License
-------
.. code:: toml

Specify the Open Source license for the wrapped package. Note that this is not the
license for the library being wrapped, just for the code generated by the *babelizer*.
[library]
language = "c"

Summary
Library
-------

A short description of the wrapped library.
The name of the BMI library to wrap.
This is the text passed to the linker through the `-l` option;
for example, use "foo" for a library *libfoo.a*.

Library section
===============
Header
------

The *library* section specifies information about the library being babelized.
The name of the header file (*.h*, *.hxx*) declaring the BMI class.
This option is only needed when wrapping C and C++ libraries.

Entry point to the BMI
----------------------
Entry point
-----------

A list of one or more entry points into the library.
The name of the BMI entry point into the library.
For object-oriented languages,
this is typically the name of a class that implements the BMI.
For procedural languages,
this is typically a function.

The following will define a Python class *Hydrotrend* that wraps the function
*register_bmi_hydrotrend* defined in the library *bmi_hydrotrend*.
An example of a C++ library (*bmi_child*), exposing a class *BmiChild* (which
implements a BMI) might look like the following:

.. code:: toml

[library]
entry_point = [ "Hydrotrend=bmi_hydrotrend:register_bmi_hydrotrend",]
[library]
[library.Child]
language = "c++"
library = "bmi_child"
header = "bmi_child.hxx"
entry_point = "BmiChild"

An example of a C++ library (*bmi_child*), exposing a class *Child* (which
implemets a BMI) might look like the following,
whereas a C library (*bmi_cem*), exposing a function *register_bmi_cem* (which
implements a BMI) might look like:

.. code:: toml

[library]
entry_point = [ "Child=bmi_child:Child",]

Library language
----------------
[library]
[library.Cem]
language = "c"
library = "bmi_cem"
header = "bmi_cem.h"
entry_point = "register_bmi_cem"

The programming language of the library (possible values are "c", "c++",
"fortran", and "python").

.. code:: toml
Build section
=============

[library]
language = "c"
In the build section the user can specify flags to pass to the compiler
when building the extension.

Plugin section
==============
Package section
===============

Name and extra requirements needed to build the babelized library.

Name
----

Name to use for the wrapped package. This is used when create the new
package, *pymt_<plugin_name>*. For example, the following will create
Name to use for the wrapped package. This is used when creating the new
package *<package_name>*. For example, the following will create
a new package, *pymt_foo*.

.. code:: toml

[plugin]
name = "foo"
[package]
name = "pymt_foo"

Requirements
------------

List of packages required by the libaray being wrapped. For example, the
List of packages required by the library being wrapped. For example, the
following indicates that the packages *foo* and *bar* are dependencies
for the package.

.. code:: toml

[plugin]
[package]
requirements = [ "foo", "bar",]

Info section
============

Descriptive infomation about the package.

Github username
---------------

The GitHub username or organization where this package will be hosted. This
is used in generating links to the CI, docs, etc.

Author
------

Author of the wrapped package. Note that this is not the author of the
library being wrapped, just the code generated by the *babelizer*.

Email
-----

Contact email to use for the wrapped package.

License
-------

Specify the Open Source license for the wrapped package. Note that this is not the
license for the library being wrapped, just for the code generated by the *babelizer*.

Summary
-------

A short description of the wrapped library.


Example babel.toml
==================
Expand All @@ -234,8 +274,11 @@ called *hydrotrend*.
.. code:: toml

[library]
[library.Hydrotrend]
language = "c"
entry_point = [ "Hydrotrend=bmi_hydrotrend:register_bmi_hydrotrend",]
library = "bmi_hydrotrend"
header = "bmi_hydrotrend.h"
entry_point = "register_bmi_hydrotrend"

[build]
undef_macros = []
Expand All @@ -245,26 +288,31 @@ called *hydrotrend*.
include_dirs = []
extra_compile_args = []

[plugin]
name = "hydrotrend"
requirements = [ "hydrotrend",]
[package]
name = "pymt_hydrotrend"
requirements = ["hydrotrend"]

[info]
plugin_author = "csdms"
github_username = "pymt-lab"
plugin_license = "MIT"
package_author = "csdms"
package_author_email = "csdms@colorado.edu"
package_license = "MIT"
summary = "PyMT plugin for hydrotrend"

You can use the *babelize generate* command to generate *babel.toml* files.
You can use the ``babelize generate`` command to generate *babel.toml* files.
For example the above *babel.toml* can be generated with the following,

.. code:: bash

$ babelize generate babel.toml \
--summary="PyMT plugin for hydrotrend" \
--entry-point=Hydrotrend=bmi_hydrotrend:register_bmi_hydrotrend \
--name=hydrotrend \
--requirement=hydrotrend
$ babelize generate babel.toml \
--package=pymt_hydrotrend \
--summary="PyMT plugin for hydrotrend" \
--language=c \
--library=bmi_hydrotrend \
--header=bmi_hydrotrend.h \
--entry-point=register_bmi_hydrotrend \
--name=Hydrotrend \
--requirement=hydrotrend

***
Use
Expand Down
1 change: 0 additions & 1 deletion babelizer/__init__.py
@@ -1,4 +1,3 @@
import pkg_resources


__version__ = pkg_resources.get_distribution("babelizer").version