def register_blueprints(self, package): """Auto-discover blueprints and register them It will look recursively in every module of the package to find a variable that has the same name as its module. It means that if a file called `foo.py` has an exportable variable called `foo`, it will try to register that variable as a blueprint. """ prefix = package.__name__ + '.' for importer, name, is_pkg in iter_modules(package.__path__, prefix): module = importer.find_module(name).load_module(name) blueprint_name = name.rsplit('.')[-1] blueprint = getattr(module, blueprint_name, None) if blueprint and isinstance(blueprint, Blueprint): log.info(' * Registering blueprint {}'.format(name)) self.register_blueprint(blueprint) elif is_pkg: self.register_blueprints(module)
def __init__(self, *args, **kwargs): super(Stupeflask, self).__init__(*args, **kwargs) config_path = os.path.join(os.getcwd(), "config.py") log.info(" * Loading default config ({})".format(config_path)) self.config.from_pyfile(config_path, silent=True) log.info(" * Loading $CONFIG ({})".format(os.environ.get("CONFIG"))) self.config.from_envvar("CONFIG", silent=True) from_env = self.config.from_env() log.info(" * Overriden by environment: " + ", ".join(from_env)) self.register_converters(converters)
def test_log(caplog): log.info("test logging") for record in caplog.records: assert "test logging" in record.message assert "flask_stupe" == record.name