Call plugin setup function
This commit is contained in:
parent
c7eafd9472
commit
19e8b54a32
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -160,4 +160,5 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
.vscode
|
||||||
secrets
|
secrets
|
||||||
|
|
@ -16,9 +16,6 @@ from fastapi import FastAPI
|
||||||
# https://pydantic-docs.helpmanual.io/usage/settings/
|
# https://pydantic-docs.helpmanual.io/usage/settings/
|
||||||
# from app.views import home
|
# from app.views import home
|
||||||
|
|
||||||
# from prometheus_fastapi_instrumentator import Instrumentator
|
|
||||||
# from prometheus_fastapi_instrumentator import metrics as pfi_metrics
|
|
||||||
|
|
||||||
logger.info("Hello Amarillo!")
|
logger.info("Hello Amarillo!")
|
||||||
|
|
||||||
app = FastAPI(title="Amarillo - The Carpooling Intermediary",
|
app = FastAPI(title="Amarillo - The Carpooling Intermediary",
|
||||||
|
|
@ -86,10 +83,37 @@ app = FastAPI(title="Amarillo - The Carpooling Intermediary",
|
||||||
|
|
||||||
# instrumentator.instrument(app)
|
# instrumentator.instrument(app)
|
||||||
|
|
||||||
# def configure():
|
import importlib
|
||||||
# configure_admin_token()
|
import pkgutil
|
||||||
# configure_services()
|
|
||||||
# configure_routing()
|
import amarillo.plugins # FIXME this namespace does not exist if there are 0 plugins installed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def iter_namespace(ns_pkg):
|
||||||
|
# Source: https://packaging.python.org/guides/creating-and-discovering-plugins/
|
||||||
|
return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".")
|
||||||
|
|
||||||
|
def load_plugins():
|
||||||
|
discovered_plugins = {
|
||||||
|
name: importlib.import_module(name)
|
||||||
|
for finder, name, ispkg
|
||||||
|
in iter_namespace(amarillo.plugins)
|
||||||
|
}
|
||||||
|
print(f"Discovered plugins: {list(discovered_plugins.keys())}")
|
||||||
|
|
||||||
|
for name, module in discovered_plugins.items():
|
||||||
|
if hasattr(module, "setup"):
|
||||||
|
print(f"Running setup function for {name}")
|
||||||
|
module.setup(app)
|
||||||
|
|
||||||
|
else: print(f"Did not find setup function for {name}")
|
||||||
|
|
||||||
|
def configure():
|
||||||
|
# configure_admin_token()
|
||||||
|
# configure_services()
|
||||||
|
# configure_routing()
|
||||||
|
load_plugins()
|
||||||
|
|
||||||
|
|
||||||
# def configure_routing():
|
# def configure_routing():
|
||||||
|
|
@ -100,8 +124,8 @@ app = FastAPI(title="Amarillo - The Carpooling Intermediary",
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# configure()
|
configure()
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||||
else:
|
else:
|
||||||
# configure()
|
configure()
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
22
logging.conf
Normal file
22
logging.conf
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
[loggers]
|
||||||
|
keys=root
|
||||||
|
|
||||||
|
[handlers]
|
||||||
|
keys=consoleHandler
|
||||||
|
|
||||||
|
[formatters]
|
||||||
|
keys=simpleFormatter
|
||||||
|
|
||||||
|
[logger_root]
|
||||||
|
level=INFO
|
||||||
|
handlers=consoleHandler
|
||||||
|
propagate=yes
|
||||||
|
|
||||||
|
[handler_consoleHandler]
|
||||||
|
class=StreamHandler
|
||||||
|
level=DEBUG
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=(sys.stdout,)
|
||||||
|
|
||||||
|
[formatter_simpleFormatter]
|
||||||
|
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||||
Loading…
Reference in a new issue