Skip to content

Instantly share code, notes, and snippets.

@pradal
Created October 3, 2018 13:21
Show Gist options
  • Save pradal/2bc811ed4fe1885c2a672df3980fda01 to your computer and use it in GitHub Desktop.
Save pradal/2bc811ed4fe1885c2a672df3980fda01 to your computer and use it in GitHub Desktop.
AutoWIG for stat_tool
import autowig
asg = autowig.AbstractSemanticGraph()
import sys, os
from path import Path
prefix = Path(sys.prefix).abspath()
headers = list((prefix/'include'/'stat_tool').walkfiles('*.h'))
flags = ['-x', 'c++', '-std=c++11', '-ferror-limit=0', '-Wno-switch', '-Wno-unknown-attributes']
flags.append('-I' + str((prefix/'include').abspath()))
if autowig.parser.plugin == 'libclang':
kwargs['silent'] = True
autowig.parser.plugin = 'clanglite'
asg = autowig.parser(asg, headers,
flags = flags,
bootstrap = 2,
)
def stat_tool_controller(asg):
for noncopyable in ['class ::std::basic_streambuf< char, struct ::std::char_traits< char > >',
'class ::std::codecvt< char, char, __mbstate_t >',
'class ::std::locale::facet',
'class ::std::locale::id',
'class ::std::ctype< char >',
'class ::std::ios_base',
'class ::std::basic_istream< char, struct ::std::char_traits< char > >',
'class ::std::basic_ostream< char, struct ::std::char_traits< char > >',
'class ::std::basic_ostringstream< char, struct ::std::char_traits< char >, class ::std::allocator< char > >',
'class ::std::basic_ios< char, struct ::std::char_traits< char > >',
'class ::std::basic_stringbuf< char, struct ::std::char_traits< char >, class ::std::allocator< char > >']:
if noncopyable in asg:
asg[noncopyable].is_copyable = False
for cls in asg.classes():
for fld in cls.fields(access='public'):
if fld.qualified_type.unqualified_type.globalname == 'class ::std::locale::id':
fld.boost_python_export = False
for template in ['class ::std::initializer_list',
'class ::std::reverse_iterator',
'class ::std::move_iterator',
'class ::std::allocator']:
for specialization in asg[template].specializations():
specialization.boost_python_export = False
for template in ['class ::std::basic_ios',
'class ::std::basic_string']:
for specialization in asg[template].specializations():
for mtd in specialization.methods():
mtd.boost_python_export = False
asg['::std::ios_base::openmode'].qualified_type.boost_python_export = True
return asg
autowig.controller['stat_tool'] = stat_tool_controller
autowig.controller.plugin = 'stat_tool'
asg = autowig.controller(asg)
autowig.generator.plugin = 'boost_python_internal'
wrappers = autowig.generator(asg,
module = os.path.join("stat_tool", "src", "py", "wrapper", "_stat_tool.cpp"),
decorator = os.path.join("stat_tool", "src", "py", "stat_tool", "_stat_tool.py"),
prefix = 'wrapper_')
wrappers.write()
import pickle
with open(os.path.join("stat_tool", "ASG.pkl"), "wb") as filehandler:
pickle.dump(asg, filehandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment