aboutsummaryrefslogtreecommitdiff
path: root/api/dynamic_import.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
commit28f104de9ae9abe4b42abafbf3865ede5687996c (patch)
tree65e651f09d8fbf81380384692e45803cb4f9d61c /api/dynamic_import.py
parent7b4859059b3bbabf4139ccdf3270a82c094f5d8e (diff)
dprint yapf python formatting
Diffstat (limited to 'api/dynamic_import.py')
-rw-r--r--api/dynamic_import.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/api/dynamic_import.py b/api/dynamic_import.py
index 159950c..5ce9b6b 100644
--- a/api/dynamic_import.py
+++ b/api/dynamic_import.py
@@ -8,24 +8,25 @@ import glob
# get all python files in api/ directory and convert them to python import names
files = glob.glob(os.path.dirname(__file__) + "/**/*.py", recursive=True)
files.remove(__file__)
-files = [str(filename)
- .replace(os.path.dirname(__file__) + "/", '')
- .replace("/", ".")
- .replace(".py", '')
- for filename in files]
+files = [
+ str(filename).replace(os.path.dirname(__file__) + "/",
+ '').replace("/", ".").replace(".py", '')
+ for filename in files
+]
+
def route(dynamic_route):
- app.register_blueprint(dynamic_route[1], url_prefix=dynamic_route[0])
- path = (dynamic_route[0] + "/" + dynamic_route[1].name).replace('//', '/')
- log.info(f"dynamically routing {path}")
+ app.register_blueprint(dynamic_route[1], url_prefix=dynamic_route[0])
+ path = (dynamic_route[0] + "/" + dynamic_route[1].name).replace('//', '/')
+ log.info(f"dynamically routing {path}")
-for file in files:
- mod = importlib.import_module(file)
- # check if module has `dynamic_route` defined (single route)
- if hasattr(mod, "dynamic_route"):
- route(mod.dynamic_route)
- # check if module has `dynamic_routes` defined (multiple routes as list)
- elif hasattr(mod, "dynamic_routes"):
- for dynamic_route in mod.dynamic_routes:
- route(dynamic_route)
+for file in files:
+ mod = importlib.import_module(file)
+ # check if module has `dynamic_route` defined (single route)
+ if hasattr(mod, "dynamic_route"):
+ route(mod.dynamic_route)
+ # check if module has `dynamic_routes` defined (multiple routes as list)
+ elif hasattr(mod, "dynamic_routes"):
+ for dynamic_route in mod.dynamic_routes:
+ route(dynamic_route)