automodinit v0.16 5th March 2017:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Niall Douglas http://www.nedproductions.biz/
See http://pypi.python.org/pypi/automodinit for latest version
Go to http://github.com/ned14/automodinit to report bugs
This package 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:
- Test suites don't find docstring tests.
- Static analysis tools don't see some module content in all.
- Things which scan themselves for plugins mismatch what os.listdir()
returns as against what the module import table has.
- I waste time over something which should take care of itself.
- 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:
- Include the automodinit package into your setup.py dependencies.
- Replace all init.py files like this:
all = ["I will get rewritten"]
Don't modify the line above, or this line!
import automodinit
automodinit.automodinit(name, file, globals())
del automodinit
Anything else you want can go after here, it won't get modified.
-
That's it! From now on importing a module will set all to
a list of .py[co] 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.
Version history:
-=-=-=-=-=-=-=-=