mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-01 13:58:12 +08:00
Add server plugin system (#1447)
* Add server plugin system Plugins are optional modules loaded at runtime. Specification: * Plugins are loaded from the server.plugins module (directory server/plugins) * The import_plugins method is run as part of the initialization of the server module in __init__.py * Add plugins to the EB build process * Remove bit of dead code * Respond to feedback from @bmccandless
This commit is contained in:
+28
-3
@@ -1,12 +1,16 @@
|
||||
import contextlib
|
||||
import errno
|
||||
import socket
|
||||
from urllib.parse import urlsplit, urljoin
|
||||
import importlib.util
|
||||
import logging
|
||||
import os
|
||||
import pkgutil
|
||||
import socket
|
||||
import warnings
|
||||
|
||||
from flask import json
|
||||
from urllib.parse import urlsplit, urljoin
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import warnings
|
||||
|
||||
|
||||
def find_available_port(host, port=5005):
|
||||
@@ -142,3 +146,24 @@ def series_to_schema(array):
|
||||
else:
|
||||
raise TypeError(f"Annotations of type {dtype} are unsupported.")
|
||||
return schema
|
||||
|
||||
|
||||
def import_plugins(plugin_module):
|
||||
"""
|
||||
Load optional plugin modules from server.common.plugins
|
||||
|
||||
If you would like to customize cellxgene, you can add submodules to server.common.plugins before running the app.
|
||||
This code will import each, loading the code in each. If no plugins are defined, initializing the app continues as
|
||||
normal.
|
||||
"""
|
||||
loaded_modules = []
|
||||
try:
|
||||
pkg = importlib.import_module(plugin_module)
|
||||
for loader, name, is_pkg in pkgutil.walk_packages(pkg.__path__):
|
||||
full_name = f"{plugin_module}.{name}"
|
||||
module = importlib.import_module(full_name)
|
||||
logging.info(f"Imported plugin {full_name}")
|
||||
loaded_modules.append(module)
|
||||
except ModuleNotFoundError:
|
||||
logging.debug(f"No plugins found in module: {plugin_module}")
|
||||
return loaded_modules
|
||||
|
||||
Reference in New Issue
Block a user