@@ -344,7 +344,8 @@ def info(self, show_contents=False, return_format="string"):
344
344
By default, this will only show the members, and not their contents.
345
345
To see contents that have been set, use `show_contents=True`. This will
346
346
not show empty/unset contents. To see all contents, set
347
- `show_contents=all`.
347
+ `show_contents="all"`. To only show members that have values set, use
348
+ `show_contents="set"`.
348
349
349
350
Note that not all members will have ids (since not all NeuroML2
350
351
ComponentTypes have ids). For members that do not have ids, the object
@@ -361,10 +362,10 @@ def info(self, show_contents=False, return_format="string"):
361
362
If "dict" or "list" is provided, the information is returned as a
362
363
dict/list instead of being printed. Note that if `show_contents` is
363
364
`False`, only a list of members is available and will be returned
364
- even if "dict" is supplied. If `show_contents` is `True` or "all"
365
- but "list" is provided, only the list of members will be returned.
366
- If something other than "string", "list", or "dict" is provided,
367
- the string representation is returned and printed.
365
+ even if "dict" is supplied. If `show_contents` is `True`, "all", or
366
+ "set" but "list" is provided, only the list of members will be
367
+ returned. If something other than "string", "list", or "dict" is
368
+ provided, the string representation is returned and printed.
368
369
:type return_format: str
369
370
:returns: info string, or list of members or dict with members as keys
370
371
and member values as values
@@ -389,7 +390,7 @@ def info(self, show_contents=False, return_format="string"):
389
390
info_str += "Valid members for {} are:\n " .format (class_name )
390
391
all_members = self ._get_members ()
391
392
for member in all_members :
392
- info_str + = "* {} (class: {}, {})\n " .format (
393
+ member_str = "* {} (class: {}, {})\n " .format (
393
394
member .get_name (),
394
395
member .get_data_type (),
395
396
"Optional" if member .get_optional () else "Required" ,
@@ -410,11 +411,13 @@ def info(self, show_contents=False, return_format="string"):
410
411
# will be empty, []
411
412
# if it's a scalar, it will be set to None or to a non
412
413
# container value
414
+ contents_str = ""
413
415
if contents is None or (
414
416
isinstance (contents , list ) and len (contents ) == 0
415
417
):
416
418
if show_contents == "all" :
417
- info_str += "\t * Contents: {}\n \n " .format (contents )
419
+ contents_str = "\t * Contents: {}\n \n " .format (contents )
420
+ # has contents
418
421
else :
419
422
contents_id = None
420
423
# if list, iterate to get ids
@@ -431,12 +434,27 @@ def info(self, show_contents=False, return_format="string"):
431
434
contents_id = f"'{ contents .id } '"
432
435
else :
433
436
contents_id = contents
434
- info_str + = "\t * Contents ('ids'/<objects>): {}\n \n " .format (
437
+ contents_str = "\t * Contents ('ids'/<objects>): {}\n \n " .format (
435
438
contents_id
436
439
)
437
- info_ret [member .get_name ()]["members" ] = getattr (
438
- self , member .get_name (), None
439
- )
440
+
441
+ member_val = getattr (self , member .get_name (), None )
442
+
443
+ # if all, show everything
444
+ if show_contents == "all" :
445
+ info_str += member_str + contents_str
446
+ info_ret [member .get_name ()]["members" ] = member_val
447
+
448
+ # if set, only show members where contents exist
449
+ elif show_contents == "set" :
450
+ if len (contents_str ) > 0 :
451
+ info_str += member_str + contents_str
452
+ if member_val is not None :
453
+ info_ret [member .get_name ()]["members" ] = member_val
454
+ else :
455
+ info_str += member_str + contents_str
456
+ info_ret [member .get_name ()]["members" ] = member_val
457
+
440
458
else :
441
459
info_ret .append (member .get_name ())
442
460
@@ -447,9 +465,11 @@ def info(self, show_contents=False, return_format="string"):
447
465
return info_ret
448
466
elif return_format == "dict" :
449
467
return info_ret
450
-
451
- print (info_str )
452
- return info_str
468
+ elif return_format == "string" :
469
+ return info_str
470
+ else :
471
+ print (info_str )
472
+ return info_str
453
473
454
474
def validate (self , recursive = False ):
455
475
"""Validate the component.
0 commit comments