Code Monkey home page Code Monkey logo

cppyy-bbhash's Introduction

cppyy-bbhash: cppyy-generated bindings for bbhash

Build Status

This repository is both a working set of cppyy bindings for bbhash and an example of a CMake workflow for automatically generating bindings and a python package with cppyy. Although it is based on the bundled cppyy cmake modules, it makes a number of improvements and changes:

  • genreflex and a selection XML are use instead of a direct rootcling invocation. This makes name selection much easier.
  • Python package files are generated using template files. This allows them to be customized for the particular library being wrapped.
  • The python package is more complete: it includes a MANIFEST, LICENSE, and README; it properly recognizes submodules; it includes a tests submodule for bindings tests; it directly copies a python module file and directory structure for its pure python code.
  • The cppyy initializor routine has basic support for packaging cppyy pythonizors. These are stored in the pythonizors/ submodule, in files of the form pythonize_*.py. The pythonizor routines themselves should be named pythonize_<NAMESPACE>_*.py, where <NAMESPACE> refers to the namespace the pythonizor will be added to in the cppyy.py.add_pythonization call. These will be automatically found and added by the initializor.

And example of cppyy's bundled cmake support can be found here; there is also a listing of cppyy example projects in the cppyy documentation.

Repo Structure

  • CMakeLists.txt: The CMake file for bindings generation.
  • selection.xml: The genreflex selection file.
  • interface.hh: The interface header used by genreflex. Should include the headers and template declarations desired in the bindings.
  • cmake/: CMake files for the build. Should not need to be modified.
  • pkg_templates/: Templates for the generated python package. Users can modify the templates to their liking; they will be configured and copied into the build and package directory.
  • py/: Python package structure that will be copied into the generated package. Add any pure python code you'd like include in your bindings package here.
  • py/initializor.py: The cppyy bindings initializor that will be copied in the package. Do not delete!

Example Usage

For this repository with anaconda:

conda create -n cppyy-example python=3 cmake cxx-compiler c-compiler clangdev libcxx libstdcxx-ng libgcc-ng pytest
conda activate cppyy-example 
pip install cppyy clang

git clone https://github.com/camillescott/cppyy-bbhash
cd cppyy-bbhash
git submodule update --init --recursive

mkdir build; cd build
cmake ..
make

python setup.py bdist_wheel
pip install dist/cppyy_bbhash-*.whl

And then to test:

py.test -v cppyy_bbhash/tests/test_bbhash_basic.py

To use this repo as a template for you own bindings, you'll want to modify the selection.xml, interface.hh, and CMakeLists.txt, as well as swap out the submodule.

TODOS

  • The CMake code for finding libclang is a bit fragile in conda environments.
  • Have CMake produce install commands to invoke setup.py and the pip install.
  • Create a PyPA package with a script to generate a repo using this this one as a template.
  • Use git hash in CMake for versioning.

cppyy-bbhash's People

Contributors

camillescott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cppyy-bbhash's Issues

py.test -v cppyy_bbhash/tests/test_bbhash_basic.py Fails

I have faithfully followed your directions, everything went ok except the tests.
Could you give me a hint as to what went wrong ?

Regards, Adrian

This is part of the test listing, it seems that ULong64_t and queries for int are not supported ??

(cppyy-example) a4@a3-Virtual-Machine:~/cppyy-bbhash/build$ py.test -v cppyy_bbhash/tests/test_bbhash_basic.py
======================================================================== test session starts ========================================================================
platform linux -- Python 3.9.0, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /home/a4/miniconda3/envs/cppyy-example/bin/python
cachedir: .pytest_cache
rootdir: /home/a4/cppyy-bbhash/build
collected 18 items

cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[ULong64_t-10] ERROR [ 5%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[ULong64_t-100] ERROR [ 11%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[ULong64_t-1000] ERROR [ 16%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[int-10] PASSED [ 22%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[int-100] PASSED [ 27%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[int-1000] PASSED [ 33%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[unsigned int-10] PASSED [ 38%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[unsigned int-100] PASSED [ 44%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_lookup[unsigned int-1000] PASSED [ 50%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[ULong64_t-10] ERROR [ 55%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[ULong64_t-100] ERROR [ 61%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[ULong64_t-1000] ERROR [ 66%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[int-10] FAILED [ 72%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[int-100] FAILED [ 77%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[int-1000] FAILED [ 83%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[unsigned int-10] FAILED [ 88%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[unsigned int-100] FAILED [ 94%]
cppyy_bbhash/tests/test_bbhash_basic.py::test_mphf_query[unsigned int-1000] FAILED [100%]

============================================================================== ERRORS ===============================================================================
_________________________________________________________ ERROR at setup of test_mphf_lookup[ULong64_t-10] __________________________________________________________

request = <SubRequest 'mphf_type' for <Function test_mphf_lookup[ULong64_t-10]>>

@pytest.fixture(params=['ULong64_t', 'int', 'unsigned int'])
def mphf_type(request):
  return request.param, boomphf.mphf[request.param, boomphf.SingleHashFunctor[request.param]]

cppyy_bbhash/tests/test_bbhash_basic.py:9:


self = <cppyy.Template 'boomphf::SingleHashFunctor' object at 0x7f9e5fc92f40>, args = ('ULong64_t',), newargs = ['boomphf::SingleHashFunctor', 'ULong64_t']
arg = 'ULong64_t'

def __getitem__(self, *args):
  # multi-argument to [] becomes a single tuple argument
    if args and type(args[0]) is tuple:
        args = args[0]

  # construct the type name from the types or their string representation
    newargs = [self.__name__]
    for arg in args:
        if type(arg) == str:
            arg = ','.join(map(lambda x: x.strip(), arg.split(',')))
        newargs.append(arg)
  pyclass = _backend.MakeCppTemplateClass(*newargs)

E TypeError: 'boomphf::SingleHashFunctor<ULong64_t>' is not a known C++ class

../../miniconda3/envs/cppyy-example/lib/python3.9/site-packages/cppyy/_cpython_cppyy.py:79: TypeError

Packages not found

Hello,

I am getting the following error when I try creating the conda environment.

PackagesNotFoundError: The following packages are not available from current channels:

  • cxx-compiler
  • libstdcxx-ng
  • c-compiler
  • clangdev
  • libgcc-ng

I updated my conda and all my conda packages and the problem is still there.

Do you know why and how I can resolve this problem?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.