Skip to content

Commit e9a9b59

Browse files
committed
update example plugins; update some plugin docs
1 parent 272087b commit e9a9b59

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎example_plugins/one_pot_tps.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import click
2+
from paths_cli import OPSCommandPlugin
23
from paths_cli.parameters import (INPUT_FILE, OUTPUT_FILE, ENGINE, STATES,
34
N_STEPS_MC, INIT_SNAP)
45
from paths_cli.commands.visit_all import visit_all_main
@@ -44,6 +45,15 @@ def one_pot_tps_main(output_storage, states, engine, engine_hot,
4445
equil_multiplier, equil_extra)
4546
return pathsampling_main(output_storage, scheme, equil_set, nsteps)
4647

48+
# these lines enable this plugin to support OPS CLI < 0.3
4749
CLI = one_pot_tps
4850
SECTION = "Workflow"
4951
REQUIRES_OPS = (1, 2)
52+
53+
# these lines enable this plugin to support OPS CLI >= 0.3
54+
PLUGIN = OPSCommandPlugin(
55+
command=one_pot_tps,
56+
section="Workflow",
57+
requires_ops=(1, 2),
58+
requires_cli=(0, 3)
59+
)

‎example_plugins/tps.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import click
2+
from paths_cli import OPSCommandPlugin
23
from paths_cli.parameters import (
34
INPUT_FILE, OUTPUT_FILE, ENGINE, STATES, INIT_CONDS, N_STEPS_MC
45
)
@@ -40,8 +41,17 @@ def tps_main(engine, states, init_traj, output_storage, n_steps):
4041
return simulation.sample_set, simulation
4142

4243

44+
# these lines enable this plugin to support OPS CLI < 0.3
4345
CLI = tps
4446
SECTION = "Simulation"
4547

48+
# these lines enable this plugin to support OPS CLI >= 0.3
49+
PLUGIN = OPSCommandPlugin(
50+
command=tps,
51+
section="Simulation"
52+
)
53+
54+
55+
# this allows you to use this as a script, independently of the OPS CLI
4656
if __name__ == "__main__":
4757
tps()

‎paths_cli/plugin_management.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,20 @@ def __repr__(self):
6060
class CLIPluginLoader(object):
6161
"""Abstract object for CLI plugins
6262
63-
The overall approach involves 5 steps, each of which can be overridden:
63+
The overall approach involves 3 steps:
6464
65-
1. Find candidate plugins (which must be Python modules)
65+
1. Find modules in the relevant locations
6666
2. Load the namespaces associated into a dict (nsdict)
67-
3. Based on those namespaces, validate that the module *is* a plugin
68-
4. Get the associated command name
69-
5. Return an OPSPlugin object for each plugin
67+
3. Find all objects in those namespaces that are plugins
7068
71-
Details on steps 1, 2, and 4 differ based on whether this is a
72-
filesystem-based plugin or a namespace-based plugin.
69+
Additionally, we attach metadata about where the plugin was found and
70+
what mechamism it was loaded with.
71+
72+
Details on steps 1 and 2 differ based on whether this is a
73+
filesystem-based plugin or a namespace-based plugin, and details on step
74+
3 can depend on the specific instance created. By default, it looks for
75+
instances of :class:`.Plugin` (given as ``plugin_class``) but the
76+
``isinstance`` check can be overridden in subclasses.
7377
"""
7478
def __init__(self, plugin_type, search_path, plugin_class=Plugin):
7579
self.plugin_type = plugin_type

0 commit comments

Comments
 (0)