Skip to content

Commit 5d1e208

Browse files
committed
Record wrapped functions and class methods with useful names in G3PipelineInfo module listing
1 parent 363f229 commit 5d1e208

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

core/python/modconstruct.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,33 @@ def PipelineAddCallable(self, callable, name=None, subprocess=False, **kwargs):
288288

289289
if not hasattr(self, 'nameprefix'):
290290
self.nameprefix = ''
291-
if (hasattr(callable, '__name__')):
291+
orig_callable = callable
292+
# unwrap
293+
if hasattr(callable, '__wrapped__'):
294+
callable = callable.__wrapped__
295+
if hasattr(callable, '__name__'):
292296
callable_name = callable.__name__
293-
elif (hasattr(callable, '__class__')):
297+
elif hasattr(callable, '__class__'):
294298
callable_name = callable.__class__.__name__
295299
else:
296300
raise RuntimeError("Cannot establish name of pipeline module")
301+
# callable may be a class method
302+
if hasattr(callable, '__self__'):
303+
cls = callable.__self__.__class__
304+
callable_mod = '%s.%s' % (cls.__module__, cls.__name__)
305+
else:
306+
callable_mod = callable.__module__
307+
# make sure wrapped callable is called
308+
callable = orig_callable
297309
if name is None:
298-
name = '%s.%s' % (callable.__module__, callable_name)
310+
name = '%s.%s' % (callable_mod, callable_name)
299311
name = self.nameprefix + name
300312

301313
# Record module configuration for root objects
302314
if self.nameprefix == '':
303315
modconfig = G3ModuleConfig()
304316
modconfig.instancename = name
305-
modconfig.modname = '%s.%s' % (callable.__module__, callable_name)
317+
modconfig.modname = '%s.%s' % (callable_mod, callable_name)
306318
for k,v in kwargs.items():
307319
tostore = v
308320
try:

0 commit comments

Comments
 (0)