biothings.hub.dataplugin

biothings.hub.dataplugin.assistant

exception biothings.hub.dataplugin.assistant.AssistantException[source]

Bases: Exception

class biothings.hub.dataplugin.assistant.BaseAssistant(url: str, plugin_name: str | None = None, src_folder: str | Path | None = None)[source]

Bases: ABC

abstractmethod can_handle() bool[source]

Return true if assistant can handle the code

data_plugin_manager = None
dumper_manager = None
handle()[source]

Access self.url and do whatever is necessary to bring code to life within the hub… (hint: that may involve creating a dumper on-the-fly and register that dumper to a manager…)

keylookup = None
property loader

Return loader object able to interpret plugin’s folder content

loaders = {'advanced': <class 'biothings.hub.dataplugin.loaders.loader.AdvancedPluginLoader'>, 'manifest': <class 'biothings.hub.dataplugin.loaders.loader.ManifestBasedPluginLoader'>}
abstract property plugin_name: str

Return plugin name, parsed from self.url and set self._src_folder as path to folder containing dataplugin source code

plugin_type = None
register_loader()[source]
setup_log()[source]

Setup and return a logger instance

uploader_manager = None
class biothings.hub.dataplugin.assistant.GithubAssistant(url: str, plugin_name: str | None = None, src_folder: str | Path | None = None)[source]

Bases: BaseAssistant

can_handle() bool[source]

Return true if assistant can handle the code

get_classdef()[source]
property plugin_name

Return plugin name, parsed from self.url and set self._src_folder as path to folder containing dataplugin source code

plugin_type = 'github'
class biothings.hub.dataplugin.assistant.LocalAssistant(url: str, plugin_name: str | None = None, src_folder: str | Path | None = None)[source]

Bases: BaseAssistant

can_handle() bool[source]

Return true if assistant can handle the code

get_classdef()[source]
property plugin_name

We attempt to derive the plugin name from the url as we expect the URL (for local plugins) to follow the structure local://<pluginname>

Formats local://pluginname so it’s in hostname. (we leverage urlsplit over urlparse due to lack of need for parameter parsing) https://docs.python.org/3/library/urllib.parse.html#structured-parse-results

If we discover a subdirectory we raise an error for moment due to lack of subdirectory support at the moment for our pathing

This can be verified by checking the path value from the SplitResult

url -> local://plugin-name Supported: > ParseResult(scheme=’local’, netloc=’plugin-name’, path=’’, params=’’, query=’’, fragment=’’)

url -> local://sub-directory/plugin-name Unsupported: > ParseResult(scheme=’local’, netloc=’plugin-name’, path=’sub-directory’, params=’’, query=’’, fragment=’’)

plugin_type = 'local'

biothings.hub.dataplugin.manager

class biothings.hub.dataplugin.manager.AssistantManager(data_plugin_manager, dumper_manager, uploader_manager, keylookup=None, default_export_folder='hub/dataload/sources', *args, **kwargs)[source]

Bases: BaseSourceManager

configure(klasses=[<class 'biothings.hub.dataplugin.assistant.GithubAssistant'>, <class 'biothings.hub.dataplugin.assistant.LocalAssistant'>])[source]
create_instance(klass, url)[source]
export(plugin_name, folder=None, what=['dumper', 'uploader', 'mapping'], purge=False)[source]

Export generated code for a given plugin name, in given folder (or use DEFAULT_EXPORT_FOLDER if None). Exported information can be: - dumper: dumper class generated from the manifest - uploader: uploader class generated from the manifest - mapping: mapping generated from inspection or from the manifest If “purge” is true, any existing folder/code will be deleted first, otherwise, will raise an error if some folder/files already exist.

export_dumper(plugin_name, folder)[source]
export_mapping(plugin_name, folder)[source]
export_uploader(plugin_name, folder)[source]
load(autodiscover: bool = True)[source]

Load plugins registered in internal Hub database and generate/register dumpers & uploaders accordingly. If autodiscover is True, also search DATA_PLUGIN_FOLDER for existing plugin directories not registered yet in the database, and register them automatically.

load_plugin(plugin)[source]
register_classes(klasses)[source]

Register each class in self.register dict. Key will be used to retrieve the source class, create an instance and run method from it. It must be implemented in subclass as each manager may need to access its sources differently,based on different keys.

register_url(url)[source]
setup_log()[source]

Setup and return a logger instance

submit(url)[source]
unregister_url(url=None, name=None)[source]
update_plugin_name(plugin, new_name)[source]
class biothings.hub.dataplugin.manager.DataPluginManager(job_manager: JobManager, poll_schedule=None, datasource_path: str | Path = None)[source]

Bases: DumperManager

load(plugin_name, *args, **kwargs)[source]