mkinit.dynamic_mkinit module

Dynamically generate the import exec

mkinit.dynamic_mkinit.dynamic_init(modname, submodules=None, dump=False, verbose=False)[source]

Main entry point for dynamic mkinit.

Dynamically import listed util libraries and their attributes. Create reload_subs function.

Using __import__ like this is typically not considered good style However, it is better than import * and this will generate the good file text that can be used when the module is ‘frozen”

Note

Dynamic mkinit is for initial development and prototyping, and even then it is not recommended. For production it is strongly recommended to use static mkinit instead of dynamic mkinit.

Example

>>> # The easiest way to use this in your code is to add these lines
>>> # to the module __init__ file
>>> from mkinit import dynamic_init
>>> execstr = dynamic_init('mkinit')
>>> print(execstr)
>>> exec(execstr)  # xdoc: +SKIP
mkinit.dynamic_mkinit._indent(str_, indent='    ')[source]
mkinit.dynamic_mkinit._excecute_imports(module, modname, imports, verbose=False)[source]

Module Imports

mkinit.dynamic_mkinit._execute_fromimport_star(module, modname, imports, check_not_imported=False, verbose=False)[source]

Effectively import * statements

The dynamic_init must happen before any * imports otherwise it wont catch anything.

mkinit.dynamic_mkinit._make_initstr(modname, imports, from_imports, withheader=True)[source]

Calls the other string makers

mkinit.dynamic_mkinit._make_module_header()[source]
mkinit.dynamic_mkinit._make_imports_str(imports, rootmodname='.')[source]
mkinit.dynamic_mkinit._make_fromimport_str(from_imports, rootmodname='.')[source]
mkinit.dynamic_mkinit._find_local_submodule_names(pkgpath)[source]
mkinit.dynamic_mkinit._autogen_write(modpath, initstr)[source]

Todo

  • [ ] : replace with code in mkinit/formatting.py