mirror of
https://github.com/OpenFreeEnergy/openfe.git
synced 2026-06-07 16:34:24 +08:00
* isort for docs and utils * isort for top-level openfe, analysis, setup * isort setup/ * isort storage/ * isort protocols * isort openn_afe * isort openmm_rfe * isort all protocols * apply isort to openfe/tests * apply isort to openfecli * apply isort to devtools/ * add TODO for setup init
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
# This code is part of OpenFE and is licensed under the MIT license.
|
|
# For details, see https://github.com/OpenFreeEnergy/openfe
|
|
|
|
# MOVE SINGLEMODULEPLUGINLOADER UPSTREAM TO PLUGCLI
|
|
import importlib
|
|
import shutil
|
|
import urllib
|
|
|
|
import click
|
|
from plugcli.cli import CLI, CONTEXT_SETTINGS
|
|
from plugcli.plugin_management import CLIPluginLoader
|
|
|
|
from openfecli import OFECommandPlugin
|
|
from openfecli.fetching import FetchablePlugin
|
|
|
|
|
|
class SingleModulePluginLoader(CLIPluginLoader):
|
|
"""Load plugins from a specific module"""
|
|
|
|
def __init__(self, module_name, plugin_class):
|
|
super().__init__(
|
|
plugin_type="single_module",
|
|
search_path=module_name,
|
|
plugin_class=plugin_class,
|
|
)
|
|
|
|
def _find_candidates(self):
|
|
return [importlib.import_module(self.search_path)]
|
|
|
|
@staticmethod
|
|
def _make_nsdict(candidate):
|
|
return vars(candidate)
|
|
|
|
|
|
class FetchCLI(CLI):
|
|
"""Custom command class for the Fetch subcommand.
|
|
|
|
This provides the command sections used in help and defines where
|
|
plugins should be kept.
|
|
"""
|
|
|
|
COMMAND_SECTIONS = ["Tutorials"]
|
|
|
|
def get_loaders(self):
|
|
return [SingleModulePluginLoader("openfecli.fetchables", FetchablePlugin)]
|
|
|
|
def get_installed_plugins(self):
|
|
loader = self.get_loaders()[0]
|
|
return list(loader())
|
|
|
|
|
|
@click.command(cls=FetchCLI, short_help="Fetch tutorial or other resource.")
|
|
def fetch():
|
|
"""
|
|
Fetch the given resource. Some resources require internet; others are
|
|
built-in.
|
|
"""
|
|
|
|
|
|
PLUGIN = OFECommandPlugin(
|
|
command=fetch,
|
|
section="Miscellaneous",
|
|
requires_ofe=(0, 7),
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
# it's useful to keep a main here for debugging where problems happen in
|
|
# the command tree
|
|
fetch()
|