mkinit.static_mkinit module¶
Static version of mkinit.dynamic_autogen
- mkinit.static_mkinit.autogen_init(modpath_or_name, submodules=None, respect_all=True, options=None, dry=False, diff=False, recursive=False)[source]¶
Autogenerates imports for a package __init__.py file.
- Parameters:
modpath_or_name (PathLike | str) – path to or name of a package module. The path should reference the dirname not the __init__.py file. If specified by name, must be findable from the PYTHONPATH.
submodules (List[str] | None, default=None) – if specified, then only these specific submodules are used in package generation. Otherwise, all non underscore prefixed modules are used.
respect_all (bool, default=True) – if False the __all__ attribute is ignored while parsing.
options (dict | None) – formatting options; customizes how output is formatted. See formatting._ensure_options for defaults.
dry (bool, default=False) – if True, the autogenerated string is not written
recursive (bool, default=False) – if True, we will autogenerate init files for all subpackages.
Note
This will partially override the __init__ file. By default everything up to the last comment / __future__ import is preserved, and everything after is overriden. For more fine grained control, you can specify XML-like
# <AUTOGEN_INIT>
and# </AUTOGEN_INIT>
comments around the volitle area. If specified only the area between these tags will be overwritten.To autogenerate a module on demand, its useful to keep a doctr comment in the __init__ file like this
python -m mkinit <your_module>
Example
>>> init_fpath, new_text = autogen_init('mkinit', submodules=None, >>> respect_all=True, >>> dry=True) >>> assert 'autogen_init' in new_text