@@ -275,11 +275,11 @@ def install_plugins(filenames: List[str]=()) -> None:
275275 continue
276276
277277 # Add the Options and data format section of the plugin to the default template bidsmap
278- if 'OPTIONS' in dir (module ) or 'BIDSMAP' in dir ( module ):
279- if 'OPTIONS' in dir ( module ):
278+ if hasattr ( module , 'OPTIONS' ) or hasattr (module , 'BIDSMAP' ):
279+ if hasattr ( module , 'OPTIONS' ):
280280 LOGGER .info (f"Adding default { file .name } bidsmap options to the { bidsmap_template .stem } template" )
281281 template ['Options' ]['plugins' ][file .stem ] = module .OPTIONS
282- if 'BIDSMAP' in dir ( module ):
282+ if hasattr ( module , 'BIDSMAP' ):
283283 for key , value in module .BIDSMAP .items ():
284284 LOGGER .info (f"Adding default { key } bidsmappings to the { bidsmap_template .stem } template" )
285285 template [key ] = value
@@ -331,11 +331,11 @@ def uninstall_plugins(filenames: List[str]=(), wipe: bool=True) -> None:
331331 if not module :
332332 LOGGER .warning (f"Cannot remove any { file .stem } bidsmap options from the { bidsmap_template .stem } template" )
333333 continue
334- if 'OPTIONS' in dir (module ) or 'BIDSMAP' in dir ( module ):
335- if 'OPTIONS' in dir ( module ):
334+ if hasattr ( module , 'OPTIONS' ) or hasattr (module , 'BIDSMAP' ):
335+ if hasattr ( module , 'OPTIONS' ):
336336 LOGGER .info (f"Removing default { file .stem } bidsmap options from the { bidsmap_template .stem } template" )
337337 template ['Options' ]['plugins' ].pop (file .stem , None )
338- if wipe and 'BIDSMAP' in dir ( module ):
338+ if wipe and hasattr ( module , 'BIDSMAP' ):
339339 for key , value in module .BIDSMAP .items ():
340340 LOGGER .info (f"Removing default { key } bidsmappings from the { bidsmap_template .stem } template" )
341341 template .pop (key , None )
@@ -376,7 +376,7 @@ def import_plugin(plugin: Union[Path,str], functions: tuple=()) -> Union[types.M
376376
377377 functionsfound = []
378378 for function in functions :
379- if function not in dir (module ):
379+ if not hasattr (module , function ):
380380 LOGGER .verbose (f"Could not find '{ function } ' in the '{ plugin } ' plugin" )
381381 elif not callable (getattr (module , function )):
382382 LOGGER .error (f"'The { function } ' attribute in the '{ plugin } ' plugin is not callable" )
@@ -405,13 +405,13 @@ def test_plugin(plugin: Union[Path,str], options: dict) -> int:
405405
406406 LOGGER .info (f"--------- Testing the '{ plugin } ' plugin ---------" )
407407
408- # First test to see if we can import the plugin
408+ # First test to see if we can import the core plugin methods
409409 module = import_plugin (plugin , ('bidsmapper_plugin' ,'bidscoiner_plugin' ))
410410 if module is None :
411411 return 1
412412
413413 # Then run the plugin's own 'test' routine (if implemented)
414- if 'test' in dir ( module ) and callable (getattr (module , 'test' )):
414+ if hasattr ( module , 'test' ) and callable (getattr (module , 'test' )):
415415 try :
416416 returncode = module .test (options )
417417 if returncode == 0 :
0 commit comments