Thread: [pygccxml-development] Multiple namespaces with the same name
Brought to you by:
mbaas,
roman_yakovenko
From: Vincent F. <vin...@gm...> - 2008-06-12 08:11:20
|
I'm renaming most of my classes to avoid them to override themselves like explained in an other subject. In order to achieve this I coded following functions which prefix the classes in python with their namespace names. rename_in_namespace(mb, ['nastran', 'samcef', 'generic', 'cla']) #Writing code to file. mb.split_module(settings.generated_files_dir) def rename_in_namespace(mb, nameList): for namespaceName in nameList: nspace = mb.global_ns.namespace(namespaceName) for clz in nspace.classes(): clz.rename(namespaceName.capitalize() + clz.name.capitalize()) There isn't apparently any way to get the name of the namespace the class is in, but it's not right here the problem, I know their names explicitely. When I try to generate the wrapper code, I'm encountering following errors : Traceback (most recent call last): File "generate_code.py", line 73, in ? export() File "generate_code.py", line 59, in export rename_in_namespace(mb, ['nastran', 'samcef', 'generic', 'cla']) File "generate_code.py", line 67, in rename_in_namespace nspace = mb.global_ns.namespace(namespaceName) File "/usr/lib/python2.4/site-packages/pygccxml/declarations/namespace.py", line 74, in namespace , recursive=recursive ) File "/usr/lib/python2.4/site-packages/pygccxml/declarations/scopedef.py", line 343, in _find_single found = matcher_module.matcher.get_single( matcher, decls, False ) File "/usr/lib/python2.4/site-packages/pygccxml/declarations/matcher.py", line 81, in get_single raise matcher.multiple_declarations_found_t( decl_matcher ) pygccxml.declarations.matcher.multiple_declarations_found_t: Multiple declarations has been found. matcher: [(decl type==namespace_t) and (name==nastran)] Even if the same namespace is defined many times, the delarations should complete themselves, not redefine each other right? Why do I have this error? |
From: Roman Y. <rom...@gm...> - 2008-06-12 09:12:48
|
On Thu, Jun 12, 2008 at 11:11 AM, Vincent Ferries <vin...@gm...> wrote: > I'm renaming most of my classes to avoid them to override themselves > like explained in an other subject. > > In order to achieve this I coded following functions which prefix the > classes in python with their namespace names. > > > rename_in_namespace(mb, ['nastran', 'samcef', 'generic', 'cla']) > > #Writing code to file. > mb.split_module(settings.generated_files_dir) > > > def rename_in_namespace(mb, nameList): > for namespaceName in nameList: > nspace = mb.global_ns.namespace(namespaceName) > for clz in nspace.classes(): > clz.rename(namespaceName.capitalize() + clz.name.capitalize()) > > > > There isn't apparently any way to get the name of the namespace the > class is in, Did you read the code I posted? clz.parent will give you reference to the parent scope. In your case this will return reference to the namespace You also can use clz.decl_string, which will return full name ::X::Y::x > but it's not right here the problem, I know their names > explicitely. It is up to you > When I try to generate the wrapper code, I'm encountering following errors : > > > Traceback (most recent call last): > File "generate_code.py", line 73, in ? > export() > File "generate_code.py", line 59, in export > rename_in_namespace(mb, ['nastran', 'samcef', 'generic', 'cla']) > File "generate_code.py", line 67, in rename_in_namespace > nspace = mb.global_ns.namespace(namespaceName) > File "/usr/lib/python2.4/site-packages/pygccxml/declarations/namespace.py", > line 74, in namespace > , recursive=recursive ) > File "/usr/lib/python2.4/site-packages/pygccxml/declarations/scopedef.py", > line 343, in _find_single > found = matcher_module.matcher.get_single( matcher, decls, False ) > File "/usr/lib/python2.4/site-packages/pygccxml/declarations/matcher.py", > line 81, in get_single > raise matcher.multiple_declarations_found_t( decl_matcher ) > pygccxml.declarations.matcher.multiple_declarations_found_t: Multiple > declarations has been found. matcher: [(decl type==namespace_t) and > (name==nastran)] > > > > Even if the same namespace is defined many times, the delarations > should complete themselves, not redefine each other right? Right, but this functionality is missing in Py++, but as you already saw it is pretty easy to implement it in the user script. > Why do I have this error? Because you have multiple namespaces named "nastran". I think next solution will work for you: mb = module_builder_t( ... ) gns = mb.global_ns nastran = gns.namespace( "nastran", recursive=False ) This will search for namespace "nastran" under the global one. It will not look under other namespaces. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-06-12 10:53:38
|
Ok, my classes were all generated in a namespace called postLib. I've found it and replaced code by : def rename_in_namespace(mb, nameList): for namespaceName in nameList: nspace = mb.namespace('postLib').namespace(namespaceName, recursive=False) for clz in nspace.classes(): clz.rename(namespaceName.capitalize() + clz.name.capitalize()) This point is working now and I can see the light! I'll have to fully understand call_policies to finish wrapping the whole library. I'll read the docs again and again :) I open a new subject for the next little problem. Thans a lot! 2008/6/12, Roman Yakovenko <rom...@gm...>: > On Thu, Jun 12, 2008 at 11:11 AM, Vincent Ferries > <vin...@gm...> wrote: >> I'm renaming most of my classes to avoid them to override themselves >> like explained in an other subject. >> >> In order to achieve this I coded following functions which prefix the >> classes in python with their namespace names. >> >> >> rename_in_namespace(mb, ['nastran', 'samcef', 'generic', 'cla']) >> >> #Writing code to file. >> mb.split_module(settings.generated_files_dir) >> >> >> def rename_in_namespace(mb, nameList): >> for namespaceName in nameList: >> nspace = mb.global_ns.namespace(namespaceName) >> for clz in nspace.classes(): >> clz.rename(namespaceName.capitalize() + clz.name.capitalize()) >> >> >> >> There isn't apparently any way to get the name of the namespace the >> class is in, > > Did you read the code I posted? > clz.parent will give you reference to the parent scope. In your case > this will return reference to the namespace > > You also can use clz.decl_string, which will return full name ::X::Y::x > >> but it's not right here the problem, I know their names >> explicitely. > > It is up to you > >> When I try to generate the wrapper code, I'm encountering following errors >> : >> >> >> Traceback (most recent call last): >> File "generate_code.py", line 73, in ? >> export() >> File "generate_code.py", line 59, in export >> rename_in_namespace(mb, ['nastran', 'samcef', 'generic', 'cla']) >> File "generate_code.py", line 67, in rename_in_namespace >> nspace = mb.global_ns.namespace(namespaceName) >> File >> "/usr/lib/python2.4/site-packages/pygccxml/declarations/namespace.py", >> line 74, in namespace >> , recursive=recursive ) >> File >> "/usr/lib/python2.4/site-packages/pygccxml/declarations/scopedef.py", >> line 343, in _find_single >> found = matcher_module.matcher.get_single( matcher, decls, False ) >> File "/usr/lib/python2.4/site-packages/pygccxml/declarations/matcher.py", >> line 81, in get_single >> raise matcher.multiple_declarations_found_t( decl_matcher ) >> pygccxml.declarations.matcher.multiple_declarations_found_t: Multiple >> declarations has been found. matcher: [(decl type==namespace_t) and >> (name==nastran)] >> >> >> >> Even if the same namespace is defined many times, the delarations >> should complete themselves, not redefine each other right? > > Right, but this functionality is missing in Py++, but as you already > saw it is pretty easy to implement it in the user script. > >> Why do I have this error? > > Because you have multiple namespaces named "nastran". I think next > solution will work for you: > > mb = module_builder_t( ... ) > gns = mb.global_ns > > nastran = gns.namespace( "nastran", recursive=False ) > > This will search for namespace "nastran" under the global one. It will > not look under other namespaces. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |