@@ -8,23 +8,33 @@ There are two possible ways to distribute plugins (file plugins and
88namespace plugins), but a given plugin script could be distributed either
99way.
1010
11- Writing a plugin script
12- -----------------------
13-
14- An OPS plugin is simply a Python module that follows a few rules.
15-
16- * It must define a variable ``CLI `` that is the main CLI function is
17- assigned to.
18- * It must define a variable ``SECTION `` to determine where to show it in
19- help (what kind of command it is). Valid values are ``"Simulation" ``,
20- ``"Analysis" ``, ``"Miscellaneous" ``, or ``"Workflow" ``. If ``SECTION `` is
21- defined but doesn't have one of these values, it won't show in
22- ``openpathsampling --help ``, but might still be usable. If your command
23- doesn't show in the help, carefully check your spelling of the ``SECTION ``
24- variable.
25- * The main CLI function must be decorated as a ``click.command ``.
26- * (If distributed as a file plugin) It must be possible to ``exec `` it in an
27- empty namespace (mainly, this can mean no relative imports).
11+ Writing a command plugin
12+ ------------------------
13+
14+ To write an OPS command plugin, you simply need to create an instance of
15+ :class: `paths_cli.OPSCommandPlugin ` and to install the module in a location
16+ where the CLI knows to look for it. The input parameters to
17+ ``OPSCommandPlugin `` are:
18+
19+ * ``command ``: This is the main CLI function for the subcommand. It must be
20+ decorated as a ``click.command ``.
21+ * ``section ``: This is a string to determine where to show it in help (what
22+ kind of command it is). Valid values are ``"Simulation" ``,
23+ ``"Analysis" ``, ``"Miscellaneous" ``, or ``"Workflow" ``. If ``section ``
24+ doesn't have one of these values, it won't show in ``openpathsampling
25+ --help ``, but might still be usable. If your command doesn't show in the
26+ help, carefully check your spelling of the ``section `` variable.
27+ * ``requires_ops `` (optional, default ``(1, 0) ``): Minimum allowed version
28+ of OpenPathSampling. Note that this is currently informational only, and
29+ has no effect on functionality.
30+ * ``requires_cli `` (optional, default ``(0, 3) ``): Minimum allowed version
31+ of the OpenPathSampling CLI. Note that this is currently informational
32+ only, and has no effect on functionality.
33+
34+
35+ If you distribute your plugin as a file-based plugin, be aware that it must
36+ be possible to ``exec `` it in an empty namespace (mainly, this can mean no
37+ relative imports).
2838
2939As a suggestion, I (DWHS) tend to structure my plugins as follows:
3040
@@ -41,16 +51,15 @@ As a suggestion, I (DWHS) tend to structure my plugins as follows:
4151 ...
4252 return final_status, simulation
4353
44- CLI = plugin
45- SECTION = " MySection"
54+ PLUGIN = OPSCommandPlugin(command = plugin, section = " MySection" )
4655
4756 The basic idea is that there's a ``plugin_main `` function that is based on
4857pure OPS, using only inputs that OPS can immediately understand (no need to
4958process the command line). This is easy to develop/test with OPS. Then
5059there's a wrapper function whose sole purpose is to convert the command line
5160parameters to something OPS can understand (using the ``get `` method). This
52- wrapper is the ``CLI `` variable. Give it an allowed `` SECTION ``, and the
53- plugin is ready!
61+ wrapper is the ``command `` in you `` OPSCommandPlugin ``. Also provide an
62+ allowed `` section ``, and the plugin is ready!
5463
5564The result is that plugins are astonishingly easy to develop, once you have
5665the scientific code implemented in a library. This structure also makes it
@@ -89,10 +98,9 @@ If the plugin is part of a larger Python package, or if it is important to
8998track version numbers or to be able to change which plugins are installed
9099in particular Python environments, the namespace distribution mechanism is a
91100better choice. We use `native namespace packages `_, which is a standard way
92- of making plugins in Python. Plugins should be in the ``paths_cli.plugins ``
101+ of making plugins in Python. Plugins should be in the ``paths_cli_plugins ``
93102namespace.
94103
95104.. _native namespace packages :
96105 https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages
97106
98-
0 commit comments