Skip to content

Commit 8637860

Browse files
committed
Merge branch 'main' of github.com:openpathsampling/openpathsampling-cli into wizard-extra-help
2 parents f3344d5 + 2b6714b commit 8637860

17 files changed

Lines changed: 45 additions & 37 deletions

‎paths_cli/commands/wizard.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
)
1010
def wizard(): # no-cov
1111
register_installed_plugins()
12-
# breakpoint()
1312
TWO_STATE_TPS_WIZARD.run_wizard()
1413

14+
1515
PLUGIN = OPSCommandPlugin(
1616
command=wizard,
1717
section="Simulation setup",

‎paths_cli/tests/compiling/test_volumes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import yaml
66
import numpy as np
77
import openpathsampling as paths
8-
from openpathsampling.experimental.storage.collective_variables import \
8+
from openpathsampling.experimental.storage.collective_variables import \
99
CoordinateFunctionCV
1010
from openpathsampling.tests.test_helpers import make_1d_traj
1111

‎paths_cli/tests/wizard/test_cvs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from paths_cli.wizard.cvs import (
1010
TOPOLOGY_CV_PREREQ, _get_atom_indices, MDTRAJ_DISTANCE, MDTRAJ_ANGLE,
11-
MDTRAJ_DIHEDRAL, COORDINATE_CV, CV_PLUGIN
11+
MDTRAJ_DIHEDRAL, COORDINATE_CV
1212
)
1313

1414
import openpathsampling as paths

‎paths_cli/tests/wizard/test_helper.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from paths_cli.wizard.helper import *
44
from paths_cli.wizard.helper import _LONG_EVAL_HELP
5-
from paths_cli.tests.wizard.mock_wizard import mock_wizard
65

76
def test_raise_quit():
87
with pytest.raises(QuitWizard):
@@ -44,7 +43,7 @@ def setup(self):
4443
self.helper = Helper(help_func=lambda s, ctx: s)
4544

4645
def test_help_string(self):
47-
# if the helper "function" is a string, retuwn that string whether
46+
# if the helper "function" is a string, return that string whether
4847
# or not additional arguments to help are given
4948
helper = Helper(help_func="a string")
5049
assert helper("?") == "a string"

‎paths_cli/tests/wizard/test_parameters.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_call(self, objs):
179179
'more': ['1', '2']}[objs]
180180

181181
wrappers = {"name" + i: self.Wrapper(i*2) for i in ['1', '2', '3']}
182-
items = [(key, val) for key, val in list(wrappers.items())[:n_objs]]
182+
items = list(wrappers.items())[:n_objs]
183183

184184
wiz = mock_wizard(inputs)
185185
wiz.store = dict(items)

‎paths_cli/tests/wizard/test_plugin_classes.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from unittest import mock
33
from paths_cli.wizard.plugin_classes import *
4-
from paths_cli.tests.wizard.test_helper import mock_wizard
4+
from paths_cli.tests.wizard.mock_wizard import mock_wizard
55
from paths_cli.wizard.standard_categories import Category
66
from paths_cli.wizard.parameters import WizardParameter, ProxyParameter
77

@@ -248,7 +248,6 @@ def test_bad_arg(self, input_type):
248248

249249
class TestWrapCategory:
250250
def setup(self):
251-
# TODO: finishing this now
252251
self.wrapper = WrapCategory("foo", "ask foo", intro="intro_foo")
253252
self.plugin_no_format = WizardObjectPlugin(
254253
name="bar",
@@ -291,9 +290,12 @@ def test_register_plugin(self):
291290
self.wrapper.register_plugin(self.plugin_no_format)
292291
assert len(self.wrapper.choices) == 1
293292
assert self.wrapper.choices['bar'] == self.plugin_no_format
294-
# TODO: what is the desired behavior if more that one plugin tries
295-
# to register with the same name? override or error? currently
296-
# overrides, but that should not be considered API
293+
294+
def test_register_plugin_duplicate(self):
295+
self.wrapper.choices['bar'] = self.plugin_no_format
296+
with pytest.raises(WizardObjectPluginRegistrationError,
297+
match="already been registered"):
298+
self.wrapper.register_plugin(self.plugin_format)
297299

298300
@pytest.mark.parametrize('input_type', ['method', 'format', 'string'])
299301
def test_get_ask(self, input_type):

‎paths_cli/tests/wizard/test_plugin_registration.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from unittest import mock
33
from paths_cli.wizard.plugin_registration import *
44
from paths_cli.wizard.plugin_registration import _register_category_plugin
5-
from paths_cli.tests.wizard.test_helper import mock_wizard
5+
from paths_cli.tests.wizard.mock_wizard import mock_wizard
66
from paths_cli.plugin_management import OPSPlugin
77
from paths_cli.wizard.plugin_classes import WrapCategory, WizardObjectPlugin
88

@@ -13,7 +13,7 @@ def _simple_func(wizard, context=None):
1313
return 10
1414

1515
class MockPlugin(OPSPlugin):
16-
def __init__(self, name='foo', requires_ops=(1,0), requires_cli=(0,3)):
16+
def __init__(self, name='foo', requires_ops=(1, 0), requires_cli=(0, 3)):
1717
super().__init__(requires_ops, requires_cli)
1818

1919
def __call__(self, wizard, context):

‎paths_cli/tests/wizard/test_volumes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from paths_cli.wizard.volumes import (
77
INTERSECTION_VOLUME_PLUGIN, UNION_VOLUME_PLUGIN, NEGATED_VOLUME_PLUGIN,
8-
CV_DEFINED_VOLUME_PLUGIN, VOLUMES_PLUGIN, volume_intro, _VOL_DESC,
8+
CV_DEFINED_VOLUME_PLUGIN, volume_intro, _VOL_DESC,
99
volume_ask
1010
)
1111

‎paths_cli/wizard/openmm.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,5 @@
7878
if __name__ == "__main__":
7979
from paths_cli.wizard.wizard import Wizard
8080
wizard = Wizard([])
81-
# engine = openmm_builder(wizard)
8281
engine = OPENMM_PLUGIN(wizard)
8382
print(engine)

‎paths_cli/wizard/plugin_classes.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
from paths_cli.wizard.parameters import WizardParameter
66
from paths_cli.wizard.helper import Helper
77

8+
9+
class WizardObjectPluginRegistrationError(Exception):
10+
pass
11+
12+
813
_PLUGIN_DOCSTRING = """
914
requires_ops : Tuple[int, int]
1015
version of OpenPathSampling required for this plugin
@@ -39,7 +44,7 @@ class LoadFromOPS(OPSPlugin):
3944
can be found
4045
""" + _PLUGIN_DOCSTRING
4146
def __init__(self, category, *, obj_name=None, store_name=None,
42-
requires_ops=(1,0), requires_cli=(0,3)):
47+
requires_ops=(1, 0), requires_cli=(0, 3)):
4348
super().__init__(requires_ops, requires_cli)
4449
self.category = category
4550
self.name = "Load existing from OPS file"
@@ -114,7 +119,7 @@ class WizardObjectPlugin(OPSPlugin):
114119
""" + _WIZARD_KWONLY
115120
def __init__(self, name, category, builder, *, prerequisite=None,
116121
intro=None, description=None, summary=None,
117-
requires_ops=(1,0), requires_cli=(0,3)):
122+
requires_ops=(1, 0), requires_cli=(0, 3)):
118123
super().__init__(requires_ops, requires_cli)
119124
self.name = name
120125
self.category = category
@@ -207,7 +212,7 @@ def __init__(self, name, category, parameters, builder, *,
207212
@classmethod
208213
def from_proxies(cls, name, category, parameters, compiler_plugin, *,
209214
prerequisite=None, intro=None, description=None,
210-
summary=None, requires_ops=(1,0), requires_cli=(0,3)):
215+
summary=None, requires_ops=(1, 0), requires_cli=(0, 3)):
211216
"""
212217
Create plugin from proxy parameters and existing compiler plugin.
213218
@@ -245,7 +250,6 @@ def _build(self, wizard, prereqs):
245250
context = {'obj_dict': dct}
246251
for param in self.parameters:
247252
dct[param.name] = param(wizard, context)
248-
# dct.update({p.name: p(wizard) for p in self.parameters})
249253
result = self.build_func(**dct)
250254
return result
251255

@@ -327,7 +331,7 @@ class WrapCategory(OPSPlugin):
327331
328332
"""
329333
def __init__(self, name, ask, helper=None, *, intro=None,
330-
set_context=None, requires_ops=(1,0), requires_cli=(0,3)):
334+
set_context=None, requires_ops=(1, 0), requires_cli=(0, 3)):
331335
super().__init__(requires_ops, requires_cli)
332336
self.name = name
333337
if isinstance(intro, str):
@@ -361,6 +365,11 @@ def register_plugin(self, plugin):
361365
plugin : :class:`.WizardObjectPlugin`
362366
the plugin to register
363367
"""
368+
if plugin.name in self.choices:
369+
raise WizardObjectPluginRegistrationError(
370+
f"A plugin named '{plugin.name}' has already been "
371+
f"registered with the category '{self.name}'"
372+
)
364373
self.choices[plugin.name] = plugin
365374

366375
def _get_intro(self, wizard, context):

0 commit comments

Comments
 (0)