django.utils.module_loading - python examples

Here are the examples of the python api django.utils.module_loading taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

3 View Complete Implementation : registry.py
Copyright MIT License
Author : fgmacedo
def load_modules(modules=None):
    if not _has_django():
        return
    try:  # pragma: no cover
        from django.utils.module_loading import autodiscover_modules
    except ImportError:  # pragma: no cover
        autodiscover_modules = _autodiscover_modules

    for module in modules:
        autodiscover_modules(module)

3 View Complete Implementation : fabfile.py
Copyright MIT License
Author : harvard-lil
@task
def run_script(module_path, function_name='main', *args, **kwargs):
    """ Run an arbitrary function, e.g. fab run_script:module.name,func_name,arg1,arg2 """
    from django.utils.module_loading import import_string
    func = import_string("%s.%s" % (module_path, function_name))
    func(*args, **kwargs)

0 View Complete Implementation : fabfile.py
Copyright MIT License
Author : harvard-lil
@task
def run_edit_script(script=None, dry_run='true', **kwargs):
    """
        Run any of the scripts in scripts/edits. Usage: fab run_edit_script:script_name,dry_run=false. dry_run defaults to true.
    """
    from django.utils.module_loading import import_string

    # print list of scripts if no script name is provided
    if not script:
        options = Path(settings.BASE_DIR, 'scripts/edits').glob('*.py')
        print("Usage: run_edit_script:script, where script is one of:\n- %s" % ("\n- ".join(o.stem for o in options)))
        return

    # call provided script
    dry_run = dry_run != 'false'
    import_path = 'scripts.edits.%s.make_edits' % script
    try:
        method = import_string(import_path)
    except ImportError:
        print("Script not found. Attempted to import %s" % import_path)
    else:
        method(dry_run=dry_run, **kwargs)