def update(self, module_path): try: oldpath = sys.path module_path = os.path.abspath(module_path) if module_path.endswith('.py'): module_path = module_path[:-3] module_dir, module_name = os.path.split(module_path) sys.path = [module_dir, ] + sys.path mod = importlib.import_module(module_name) except ImportError as e: raise ImportError("Could not import configuration '%s' (Is it on sys.path?): %s" % (module_path, e)) finally: sys.path = oldpath for setting in dir(mod): if setting == setting.upper(): setting_value = getattr(mod, setting) setattr(self, setting, setting_value)
def import_callable(module_path_name): """ Import the callable given by ``module_path_name``. """ try: module_path, name = module_path_name.rsplit('.', 1) except ValueError: raise exceptions.ImproperlyConfigured('%s is not a valid module path' % module_path_name) try: mod = importlib.import_module(module_path) except ImportError as e: raise exceptions.ImproperlyConfigured('Error importing module %s: "%s"' % (module_path, e)) try: item_callable = getattr(mod, name) except AttributeError: raise exceptions.ImproperlyConfigured('Module "%s" does not define a "%s" callable' % (module_path, name)) return item_callable
def import_callable(module_path_name): """ Import the callable given by ``module_path_name``. """ try: module_path, name = module_path_name.rsplit('.', 1) except ValueError: raise exceptions.ImproperlyConfigured('%s is not a valid module path' % module_path_name) try: mod = importlib.import_module(module_path) except ImportError as e: raise exceptions.ImproperlyConfigured( 'Error importing module %s: "%s"' % (module_path, e)) try: item_callable = getattr(mod, name) except AttributeError: raise exceptions.ImproperlyConfigured( 'Module "%s" does not define a "%s" callable' % (module_path, name)) return item_callable
def update(self, module_path): try: oldpath = sys.path module_path = os.path.abspath(module_path) if module_path.endswith('.py'): module_path = module_path[:-3] module_dir, module_name = os.path.split(module_path) sys.path = [ module_dir, ] + sys.path mod = importlib.import_module(module_name) except ImportError as e: raise ImportError( "Could not import configuration '%s' (Is it on sys.path?): %s" % (module_path, e)) finally: sys.path = oldpath for setting in dir(mod): if setting == setting.upper(): setting_value = getattr(mod, setting) setattr(self, setting, setting_value)