Пример #1
0
 def __reload__(self):
     if self.__dict__['_autoimp_lib'] is None:
         # If mod has not yet been imported, then only load mod once.
         self.__load_lib()
         return self
     else:
         _reload(self.__dict__['_autoimp_lib'])
         self.__set_lib(self.__dict__['_autoimp_lib'])
         return self
Пример #2
0
 def __reload__(self):
   if self.__dict__['_autoimp_lib'] is None:
     # If mod has not yet been imported, then only load mod once.
     self.__load_lib()
     return self
   else:
     _reload(self.__dict__['_autoimp_lib'])
     self.__set_lib(self.__dict__['_autoimp_lib'])
     return self
Пример #3
0
def _reloadModule(theMod, fromList=[], toNamespace=globals()):
    if type(theMod) == str:
        theMod = _modules[theMod]

    _reload(theMod)

    if type(toNamespace).__name__ == 'module':
        toNamespace = vars(toNamespace)

    fromNamespace = vars(theMod)
    for name in fromList:
        toNamespace[name] = fromNamespace[name]

    return theMod
Пример #4
0
def reload(x):
  """
  Replacement for builtin reload() by autoimp.py.

  Reloads the module argument, and returns the reloaded module.  The
  module need not have been already imported.  If the argument has the
  special method __reload__(), then that method is called and its
  return value is returned by reload().
  """
  if hasattr(x, '__reload__'):
    return x.__reload__()
  else:
    return _reload(x)
Пример #5
0
def reload(x):
    """
  Replacement for builtin reload() by autoimp.py.

  Reloads the module argument, and returns the reloaded module.  The
  module need not have been already imported.  If the argument has the
  special method __reload__(), then that method is called and its
  return value is returned by reload().
  """
    if hasattr(x, '__reload__'):
        return x.__reload__()
    else:
        return _reload(x)
Пример #6
0
def _load_app_module(app: str, is_dash: bool = True):
    """Load underlying module of a Dash app.

    Args:
        app: App's corresponding file name.

    Returns:
        Module loaded.
    """
    mod = _import_module(('dash_apps.' if is_dash else 'apps.') + app)
    if app[:4] == 'dev_':
        mod = _reload(mod)
    return mod
Пример #7
0
def reload(
    module: ModuleType,
    upgraders: Iterable[UpgradeFn] = ...,
) -> ModuleType:
    # Import importlib.reload here so that this module can reload itself.
    # If the import is outside this function, it is cleared during reload and
    # can't be resolved.
    from importlib import reload as _reload

    if upgraders is ...:
        upgraders = UPGRADERS

    saved_dict = module.__dict__.copy()
    name = module.__name__
    loader = module.__loader__
    spec = module.__spec__
    magazine_refs = module.__dict__.get('__magazine__',
                                        defaultdict(weakref.WeakSet))
    module.__dict__.clear()
    module.__dict__.update(
        __name__=name,
        __loader__=loader,
        __spec__=spec,
        __magazine__=magazine_refs,
    )

    try:
        # Try to reload the module.
        module = _reload(module)
    except:
        # Restore the previous dict on failure.
        module.__dict__.update(saved_dict)
        raise

    for name, obj in saved_dict.items():
        if getattr(obj, '__module__', None) == module.__name__:
            magazine_refs[name].add(obj)

    # Delete the saved module dict so members can potentially be
    # garbage-collected and avoid needless upgrading.
    del saved_dict

    # Upgrade existing upgradeable objects.
    for name, refset in magazine_refs.items():
        for old in refset:
            new = module.__dict__.get(name)
            if old is not None and new is not None:
                # print(f'upgrading {module.__name__}.{name}')
                upgrade(old, new, upgraders)

    return module
Пример #8
0
    def _impl(m):
        if isinstance(m, str):
            m = import_module(m)

        return _reload(m)
Пример #9
0
def reload():
    from freecad import lumberjack as this

    _reload(this)
Пример #10
0
from contextlib import suppress as _suppress
from functools import wraps as _wraps
from gc import collect as _collect
from importlib import reload as _reload
from sys import modules as _modules

if __name__ != '__main__':
    #If name != main, then this is being imported
    try:
        _crossword
    except NameError:
        import crossword as _crossword
    else:
        _reload(_crossword)
else:
    if 'crossword' in _modules:
        _crossword = _modules['crossword']
        #If Checker is defined but isn't the standard from crossword, the user
        #has mucked with it.  Reload crossword to ensure everything is good
        with _suppress(NameError):
            if Checker is not _crossword.Checker:
                _reload(_modules['crossword.clses'])
                _reload(_modules['crossword.funcs'])
                _reload(_modules['crossword.globs'])
                _reload(_crossword)
    else:
        import crossword as _crossword
from crossword import *


class Checker(Checker):