MDANSE icon indicating copy to clipboard operation
MDANSE copied to clipboard

[ENHANCEMENT] Use `pkgutils` for walking files

Open oerc0122 opened this issue 11 months ago • 0 comments

Is your feature request related to a problem? Please describe. Currently in a lot of __init__.py files (c.f. https://github.com/ISISNeutronMuon/MDANSE/blob/protos/MDANSE/Src/MDANSE/Framework/Jobs/init.py) there are manual walks though the contents of the package.

This incurs both maintenance costs and captures invalid files such as temporary files created by linters.

Describe the solution you'd like Manually importing all the required registered subclasses within each init. This would be the usual recommended way as this explicitly names the files to be imported and allows static checkers to validate their use.

If this is not desirable, pkgutil provides both the walk_modules and iter_modules functions in stdlib for doing this kind of job.

Describe alternatives you've considered N/A

Additional context The SubclassFactory metaclass requires the imports in order to create the classes which register themselves as children.

oerc0122 avatar Apr 10 '25 13:04 oerc0122