automodinit

Solves the problem of forgetting to keep __init__.py files up to date
Download

automodinit Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Creative Commons Att...
  • Price:
  • FREE
  • Publisher Name:
  • Niall Douglas
  • Publisher web site:
  • http://www.nedprod.com/programs/portable/nedmalloc/

automodinit Tags


automodinit Description

Is this the smallest package on Pypi? That we have no idea, but automodinit fixes a small problem which has been bugging me throughout years of Python development: forgetting to keep a module's __init__.py up to date with new files added. This causes the following, irritating problems:1. Test suites don't find docstring tests.2. Static analysis tools don't see some module content in __all__.3. Things which scan themselves for plugins mismatch what os.listdir() returns as against what the module import table has.4. I waste time over something which should take care of itself.5. os.listdir() based solutions tend to fail when freezed into an executable binary because they don't understand running from inside a ZIP archive.So here's how to make the problem go away forever:1. Include the automodinit package into your setup.py dependencies.2. Replace all __init__.py files like this:__all__ = # Don't modify the line above, or this line!import automodinitautomodinit.automodinit(__name__, __file__, globals())del automodinit# Anything else you want can go after here, it won't get modified.3. That's it! From now on importing a module will set __all__ to a list of .py files in the module and will also import each of those files as though you had typed: for x in __all__: import x Therefore the effect of "from M import *" matches exactly "import M".Customising:automodinit can take the following additional parameters:filter: This is a callable which will be passed a list of tuples (loader, modulename, ispkg) which is the output of pkgutil.iter_modules() for the calling module. Return only those which you want to be imported.importFindings: Defaults to True. Set to False to not auto-import the contents of __all__.Product's homepage


automodinit Related Software