# file Build%STRATEGY_NAME%.py
# DEVELOPER'S NOTE: All files are found relative to the current working directory
# of the terminal or script that calls the `python` command.
import cffi
ffibuilder = cffi.FFI()
with open('AlgoServer.h') as f:
# read plugin.h and pass it to embedding_api(), manually
# removing the '#' directives and the CFFI_DLLEXPORT
data = ''.join([line for line in f if not line.startswith('#')])
data = data.replace('CFFI_DLLEXPORT', '')
ffibuilder.embedding_api(data)
with open('Bars.h') as f:
# read plugin.h and pass it to embedding_api(), manually
# removing the '#' directives and the CFFI_DLLEXPORT
data = ''.join([line for line in f if not line.startswith('#')])
data = data.replace('CFFI_DLLEXPORT', '')
ffibuilder.embedding_api(data)
ffibuilder.set_source("Build%STRATEGY_NAME%", r'''
#include "Bars.h"
#include "AlgoServer.h"
''')
ffibuilder.embedding_init_code("""
from Build%STRATEGY_NAME% import ffi
# Add futbox import directory
import sys
import os
#sys.path.append(os.path.expandvars("$FUTBOX_PY_MODULE_DIR"))
%STRATEGY_IMPORTS%
# Python implementation of exposed C code
%STRATEGY_PYTHON_CODE%
""")
ffibuilder.compile(target="libFtbx%STRATEGY_NAME%.*", verbose=True)
%STUB%
# file BuildTrain.py
# DEVELOPER'S NOTE: All files are found relative to the current working directory
# of the terminal or script that calls the `python` command.
import cffi
ffibuilder = cffi.FFI()
with open('AlgoServer.h') as f:
# read plugin.h and pass it to embedding_api(), manually
# removing the '#' directives and the CFFI_DLLEXPORT
data = ''.join([line for line in f if not line.startswith('#')])
data = data.replace('CFFI_DLLEXPORT', '')
ffibuilder.embedding_api(data)
with open('Bars.h') as f:
# read plugin.h and pass it to embedding_api(), manually
# removing the '#' directives and the CFFI_DLLEXPORT
data = ''.join([line for line in f if not line.startswith('#')])
data = data.replace('CFFI_DLLEXPORT', '')
ffibuilder.embedding_api(data)
ffibuilder.set_source("BuildTrain", r'''
#include "Bars.h"
#include "AlgoServer.h"
''')
ffibuilder.embedding_init_code("""
from BuildTrain import ffi
# Add futbox import directory
import sys
import os
#sys.path.append(os.path.expandvars("$FUTBOX_PY_MODULE_DIR"))
# Python implementation of exposed C code
# from futbox.PyFriendly import make_python_friendly
# from futbox import CustomMetrics
@ffi.def_extern(name="whatever")
def whatever():
print("in train function")
""")
ffibuilder.compile(target="libFtbxTrain.*", verbose=True)
gcc -std=gnu99 -I"$(pwd)" -I/usr/local/Cellar/postgresql -I/usr/local/Cellar/czmq/4.0.2/include -I"$(pwd)"/.. tests/TestAlgoServer.c Bars.c CQueue.c -L"$(pwd)"/tests -L"$(pwd)" -L/usr/local/Cellar/postgresql -L/usr/local/Cellar/czmq/4.0.2/lib -lFtbxBasic -lFtbxMovingAverageCross -lFtbxVwap -lFtbxTrain -lpython2.7 -lczmq -lzmq -lpq -lssl -lcrypto -o Server
sh build.sh -clean
sh build.sh