From dd78b37290e1f0ebcb7a8b10939675b03d76895b Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Fri, 12 Feb 2021 11:30:16 +0100 Subject: [PATCH] cython setup imc_termite pytho module --- .gitignore | 2 +- cython/imc_termite.pxd | 18 ++++++++++++++++++ cython/py_imc_termite.pyx | 27 +++++++++++++++++++++++++++ cython/setup.py | 24 ++++++++++++++++++++++++ lib/imc_raw.hpp | 1 + makefile | 32 +++++--------------------------- src/main.cpp | 5 +++-- 7 files changed, 79 insertions(+), 30 deletions(-) create mode 100644 cython/imc_termite.pxd create mode 100644 cython/py_imc_termite.pyx create mode 100644 cython/setup.py diff --git a/.gitignore b/.gitignore index f8c663c..179bf14 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ nohup.out raw_eater.cpp raw_meat.cpp -cyt/*.cpp +cython/*.cpp /build *.log diff --git a/cython/imc_termite.pxd b/cython/imc_termite.pxd new file mode 100644 index 0000000..1d6ffc3 --- /dev/null +++ b/cython/imc_termite.pxd @@ -0,0 +1,18 @@ +# cython: language_level = 3 + +# use some C++ STL libraries +from libcpp.string cimport string +from libcpp.vector cimport vector +from libcpp cimport bool + +cdef extern from "imc_raw.hpp" namespace "imc": + cdef cppclass imc_termite "imc::raw": + # constructor(s) + imc_termite() except + + imc_termite(string rawfile) except + + # provide raw file + void submit_file(string rawfile) except+ + # get JSON list of channels + vector[string] get_channels() except+ + # print all channels + void print_channels(string outputdir) except+ diff --git a/cython/py_imc_termite.pyx b/cython/py_imc_termite.pyx new file mode 100644 index 0000000..34cf596 --- /dev/null +++ b/cython/py_imc_termite.pyx @@ -0,0 +1,27 @@ +# distutils: language = c++ + +from imc_termite cimport imc_termite + +import json as jn +# import numpy as np + +cdef class imctermite: + + # C++ instance of class => stack allocated (requires nullary constructor!) + cdef imc_termite cpp_imc + + # constructor + def __cinit__(self, string rawfile): + self.cpp_imc = imc_termite(rawfile) + + # provide raw file + def submit_file(self,string rawfile): + self.cpp_tdm.set_file(rawfile) + + # get JSON list of channels + def get_channels(self, bool data): + return self.cpp_imc.get_channels() + + # print a channels + def print_channel(self, string outputdir): + self.cpp_tdm.print_channels(outputdir) diff --git a/cython/setup.py b/cython/setup.py new file mode 100644 index 0000000..53d9472 --- /dev/null +++ b/cython/setup.py @@ -0,0 +1,24 @@ +from distutils.core import setup +from distutils.extension import Extension +from Cython.Build import cythonize + +extensions = Extension( + name="imc_termite", + sources=["cython/py_imc_termite.pyx"], + # libraries=[""], + # library_dirs=["lib"], + include_dirs=["lib"], + language='c++', + extra_compile_args=['-std=c++17','-Wno-unused-variable'], + extra_link_args=['-std=c++17'], +) + +setup( + version='0.1', + description='IMCtermite cython extension', + author='Record Evolution GmbH', + author_email='mario.fink@record-evolution.de', + url='https://github.com/RecordEvolution/IMCtermite.git', + name="imc_termite", + ext_modules=cythonize(extensions) +) diff --git a/lib/imc_raw.hpp b/lib/imc_raw.hpp index c391972..25b0587 100644 --- a/lib/imc_raw.hpp +++ b/lib/imc_raw.hpp @@ -5,6 +5,7 @@ #include #include +#include #include "hexshow.hpp" #include "imc_key.hpp" diff --git a/makefile b/makefile index 55168a7..25d7fd9 100644 --- a/makefile +++ b/makefile @@ -58,36 +58,14 @@ docker-build : docker-run: docker run -it --rm imctermite:0.1 /bin/bash -# # build CLI executable -# $(EXE) : $(SRC)main.cpp $(LIB)raweat.hpp $(LIB)hexshow.hpp $(LIB)rawmerge.hpp output -# $(CCC) $(OPT) $< -o $@ +#-----------------------------------------------------------------------------# +# python -# # development version -# eatdev : $(SRC)main_dev.cpp $(LIB)raweat.hpp -# $(CCC) $(OPT) $< -o $@ -# -# # build target for conversion set of .raw files -# eatall : $(SRC)eatall.cpp $(LIB)raweat.hpp -# $(CCC) $(OPT) $< -o $@ - -# check existence of name of executable globally -# chexe:=$(shell command -v $(EXE)) -# -# # install executable if name does not exist yet -# install : $(EXE) -# ifeq ($(chexe),) -# cp $(EXE) /usr/local/bin/ -# else -# @echo "executable with name already exists! choose different name!" -# @exit 1 -# endif - -# # uninstall -# uninstall : -# rm /usr/local/bin/$(EXE) +cython-build : $(CYT)setup.py $(CYT)imc_termite.pxd $(CYT)py_imc_termite.pyx $(HPP) + python3 $< build_ext --inplace #-----------------------------------------------------------------------------# -# Python +# Python (to be removed) # build python module py : $(CYT)setup_raw_eater.py $(CYT)raw_eater.pyx $(CYT)raw_eater.pxd $(LIB)raweat.hpp \ diff --git a/src/main.cpp b/src/main.cpp index 5c603f9..4f246df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,11 @@ //---------------------------------------------------------------------------// #include +#include #include -#include "imc_key.hpp" -#include "imc_block.hpp" +// #include "imc_key.hpp" +// #include "imc_block.hpp" #include "imc_raw.hpp" //---------------------------------------------------------------------------//