diff --git a/examples/foomodulegen.py b/examples/foomodulegen.py new file mode 100755 index 0000000..088fb37 --- /dev/null +++ b/examples/foomodulegen.py @@ -0,0 +1,36 @@ +#! /usr/bin/env python + +import sys + +from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink) +from pybindgen import (CppMethod, CppConstructor, CppClass) + + +def my_module_gen(out_file): + print >> out_file, "#include " + print >> out_file, "#include \"foo.h\"" + + mod = Module('foo') + + mod.add_function(Function(ReturnValue('int'), 'print_something', + [Parameter('const char*', 'message')])) + + mod.add_function(Function(ReturnValue('int'), 'print_something_else', + [Parameter('const char*', 'message2')])) + + + SomeObject = CppClass('SomeObject') + SomeObject.add_method(CppMethod(ReturnValue('int'), 'add_prefix', + [Parameter('std::string&', 'message', + direction=Parameter.DIRECTION_INOUT)])) + SomeObject.add_constructor( + CppConstructor([Parameter('std::string', 'prefix')])) + + mod.add_class(SomeObject) + + mod.generate(FileCodeSink(out_file)) + + +if __name__ == '__main__': + my_module_gen(sys.stdout) + diff --git a/examples/wscript b/examples/wscript index 7f6879f..a2b3bb2 100644 --- a/examples/wscript +++ b/examples/wscript @@ -4,73 +4,13 @@ import Object import Params import Task -import os, sys -sys.path.insert(0, os.getcwd()) # to work with uninstalled pybindgen - -from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink) -from pybindgen import (CppMethod, CppConstructor, CppClass) - - -def _pybindgen_action(task): - target, = task.m_outputs - out_file = file(target.bldpath(task.m_env), "w") - task.function(out_file) - out_file.close() - -class PyBindGen(Object.genobj): - def __init__(self, env=None): - Object.genobj.__init__(self, 'other') - self.install_var = 0 - self.env = env - if not self.env: - self.env = Params.g_build.m_allenvs['default'].copy() - self.function = None - self.target = None - self.prio = 5 - def apply(self): - function = self.function - task = self.create_task('pybindgen', self.env, self.prio) - task.function = self.function - target = self.path.find_build(self.target) - task.set_outputs([target]) - task.set_inputs([self.path.find_source('wscript')]) - def install(self): - pass - - - -def my_module_gen(out_file): - print >> out_file, "#include " - print >> out_file, "#include \"foo.h\"" - - mod = Module('foo') - - mod.add_function(Function(ReturnValue('int'), 'print_something', - [Parameter('const char*', 'message')])) - - mod.add_function(Function(ReturnValue('int'), 'print_something_else', - [Parameter('const char*', 'message2')])) - - - SomeObject = CppClass('SomeObject') - SomeObject.add_method(CppMethod(ReturnValue('int'), 'add_prefix', - [Parameter('std::string&', 'message')])) - SomeObject.add_constructor( - CppConstructor([Parameter('std::string', 'prefix')])) - - mod.add_class(SomeObject) - - mod.generate(FileCodeSink(out_file)) - def build(bld): - Object.register('pybindgen', PyBindGen) - Action.Action('pybindgen', func=_pybindgen_action, color='BLUE') - - bindgen = bld.create_obj('pybindgen') - bindgen.target = 'foomodule.cc' - bindgen.function = my_module_gen - bindgen.prio = 1 + bindgen = bld.create_obj('command-output') + bindgen.stdout = 'foomodule.cc' + bindgen.stdin = 'foomodulegen.py' + bindgen.command = 'foomodulegen.py' + bindgen.prio = 3 # must run after the 'py' objects in ../pybindgen obj = bld.create_obj('cpp', 'shlib', 'pyext') obj.source = [ diff --git a/pybindgen/wscript b/pybindgen/wscript index 3019923..96609d2 100644 --- a/pybindgen/wscript +++ b/pybindgen/wscript @@ -7,8 +7,10 @@ def build(bld): # commented, triggers a WAF bug (Issue #40) #obj.source.append('version.py') obj.inst_dir = 'pybindgen' + obj.prio = 2 obj = bld.create_obj('py') obj.find_sources_in_dirs('typehandlers') obj.inst_dir = 'pybindgen/typehandlers' + obj.prio = 2 diff --git a/tests/test-generation.py b/tests/test-generation.py index 79f0366..44265f8 100755 --- a/tests/test-generation.py +++ b/tests/test-generation.py @@ -2,11 +2,6 @@ import sys -try: - path = sys.argv[1] -except IndexError: - path = '..' -sys.path.insert(0, path) from pybindgen import typehandlers from pybindgen.typehandlers import codesink diff --git a/tests/wscript b/tests/wscript index f7ebafc..e6f1b46 100644 --- a/tests/wscript +++ b/tests/wscript @@ -13,18 +13,16 @@ def build(bld): gen.stdin = 'test-generation.py' top_srcdir = bld.m_srcnode.abspath() gen.argv = [top_srcdir] - gen.priority = 5 + gen.prio = 5 obj = bld.create_obj('cpp', 'objects', 'pyext') obj.source = 'test.cc' obj.env.append_value('CXXFLAGS', ['-Wall', '-Werror', '-Wno-unused']) cwd = os.getcwd() - env = dict(os.environ) - env['PYTHONPATH'] = top_srcdir os.chdir(top_srcdir) try: - if subprocess.Popen(['python', 'tests/test.py'], env=env).wait(): + if subprocess.Popen(['python', 'tests/test.py']).wait(): raise SystemExit(1) finally: os.chdir(cwd) diff --git a/wscript b/wscript index 028f397..43cabd2 100644 --- a/wscript +++ b/wscript @@ -8,6 +8,10 @@ import os import pproc as subprocess import shutil + +os.environ['PYTHONPATH'] = os.path.join(os.getcwd(), 'build', 'default') + + def get_version_from_bzr(): import bzrlib.tag, bzrlib.branch branch = bzrlib.branch.Branch.open('file://' + os.getcwd())