Python sublime_plugin.reload_plugin() Examples

The following are 8 code examples of sublime_plugin.reload_plugin(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sublime_plugin , or try the search function .
Example #1
Source File: reloader.py    From UnitTesting with MIT License 6 votes vote down vote up
def reload_dependency(dependency_name, dummy=True, verbose=True):
    """
    Reload.

    Package Control dependencies aren't regular packages, so we don't want to
    call `sublime_plugin.unload_module` or `sublime_plugin.reload_plugin`.
    Instead, we manually unload all of the modules in the dependency and then
    `reload_package` any packages that use that dependency. (We have to manually
    unload the dependency's modules because calling `reload_package` on a
    dependent module will not unload the dependency.)
    """
    for name in get_package_modules(dependency_name):
        del sys.modules[name]

    manager = PackageManager()
    for package in manager.list_packages():
        if dependency_name in manager.get_dependencies(package):
            reload_package(package, dummy=False, verbose=verbose)

    if dummy:
        load_dummy(verbose) 
Example #2
Source File: reloader.py    From UnitTesting with MIT License 5 votes vote down vote up
def reload_package(pkg_name, dummy=True, verbose=True):
    if is_dependency(pkg_name):
        reload_dependency(pkg_name, dummy, verbose)
        return

    if pkg_name not in sys.modules:
        dprint("error:", pkg_name, "is not loaded.")
        return

    if verbose:
        dprint("begin", fill='=')

    modules = get_package_modules(pkg_name)

    for m in modules:
        if m in sys.modules:
            sublime_plugin.unload_module(modules[m])
            del sys.modules[m]

    try:
        with intercepting_imports(modules, verbose), \
                importing_fromlist_aggresively(modules):

            reload_plugin(pkg_name)
    except Exception:
        dprint("reload failed.", fill='-')
        reload_missing(modules, verbose)
        raise

    if dummy:
        load_dummy(verbose)

    if verbose:
        dprint("end", fill='-') 
Example #3
Source File: reloader.py    From UnitTesting with MIT License 5 votes vote down vote up
def reload_plugin(pkg_name):
    pkg_path = os.path.join(os.path.realpath(sublime.packages_path()), pkg_name)
    plugins = [pkg_name + "." + os.path.splitext(file_path)[0]
               for file_path in os.listdir(pkg_path) if file_path.endswith(".py")]
    for plugin in plugins:
        sublime_plugin.reload_plugin(plugin) 
Example #4
Source File: reload.py    From GitSavvy with MIT License 5 votes vote down vote up
def reload_plugin(verbose=True, then=None):
    threading.Thread(
        target=functools.partial(reload_package, 'GitSavvy', verbose=verbose, then=then)
    ).start() 
Example #5
Source File: reloader.py    From Terminus with MIT License 5 votes vote down vote up
def reload_package(pkg_name, dummy=True, verbose=True):
    if pkg_name not in sys.modules:
        dprint("error:", pkg_name, "is not loaded.")
        return

    main = sys.modules[pkg_name]

    if verbose:
        dprint("begin", fill='=')

    modules = {main.__name__: main}
    modules.update({name: module for name, module in sys.modules.items()
                    if name.startswith(pkg_name + ".")})
    for m in modules:
        if m in sys.modules:
            sublime_plugin.unload_module(modules[m])
            del sys.modules[m]

    try:
        with intercepting_imports(modules, verbose), \
                importing_fromlist_aggresively(modules):

            reload_plugin(pkg_name)
    except Exception:
        dprint("reload failed.", fill='-')
        reload_missing(modules, verbose)
        raise

    if dummy:
        load_dummy(verbose)

    if verbose:
        dprint("end", fill='-') 
Example #6
Source File: reloader.py    From Terminus with MIT License 5 votes vote down vote up
def reload_plugin(pkg_name):
    pkg_path = os.path.join(os.path.realpath(sublime.packages_path()), pkg_name)
    plugins = [pkg_name + "." + os.path.splitext(file_path)[0]
               for file_path in os.listdir(pkg_path) if file_path.endswith(".py")]
    for plugin in plugins:
        sublime_plugin.reload_plugin(plugin) 
Example #7
Source File: Localization.py    From Chinese-Localization with MIT License 5 votes vote down vote up
def plugin_unloaded():
    PACKAGE_NAME = __name__.split('.')[0]
    from package_control import events

    if events.pre_upgrade(PACKAGE_NAME):
        print('Upgrading from %s!' % events.pre_upgrade(PACKAGE_NAME))
    elif events.remove(PACKAGE_NAME):
        # set_language("EN", True)
        cleanup()
        sublime_plugin.reload_plugin('Default')
        print('Removing %s!' % events.remove(PACKAGE_NAME)) 
Example #8
Source File: reloader.py    From AutomaticPackageReloader with MIT License 4 votes vote down vote up
def reload_package(package, dependencies=[], dummy=True, verbose=True):
    if verbose:
        dprint("begin", fill='=')

    packages = [package] + dependencies
    parents = set()
    for package in packages:
        for parent in resolve_parents(package):
            parents.add(parent)
    parents = list(parents)

    modules = sorted(
        list(set(get_package_modules(packages + parents))),
        key=lambda x: x[0].split('.')
    )

    plugins = [m for m, is_plugin in modules if is_plugin]
    # Tell Sublime to unload plugin_modules
    for plugin in plugins:
        if plugin in sys.modules:
            sublime_plugin.unload_module(sys.modules[plugin])

    # these are modules marked to be reloaded, they are not necessarily reloaded
    modules_to_reload = [sys.modules[m] for m, is_plugin in modules if m in sys.modules]

    with ReloadingImporter(modules_to_reload, verbose) as importer:
        if plugins:
            # we only reload top level plugin_modules to mimic Sublime Text natural order
            for plugin in plugins:
                if plugin in sys.modules:
                    module = sys.modules[plugin]
                    importer.reload(module)

            for plugin in plugins:
                if plugin in sys.modules:
                    module = sys.modules[plugin]
                    sublime_plugin.load_module(module)
                else:
                    # in case we missed something
                    sublime_plugin.reload_plugin(plugin)
        else:
            # it is possibly a dependency but no packages use it
            for module in modules_to_reload:
                importer.reload(module)

    if dummy:
        load_dummy(verbose)

    if verbose:
        dprint("end", fill='-')