Skip to content

Commit 7fce8a5

Browse files
committed
compiling/__init__; and always error on duplicate
1 parent 3daa542 commit 7fce8a5

5 files changed

Lines changed: 22 additions & 13 deletions

File tree

‎paths_cli/compiling/__init__.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
from .core import Parameter, Builder, InstanceCompilerPlugin
2+
from .root_compiler import (clean_input_key, compiler_for, register_plugins,
3+
do_compile)
14

5+
from .plugins import CategoryPlugin
6+
from .errors import InputError
7+
8+
# OPS-specific
9+
from .plugins import (
10+
EngineCompilerPlugin, CVCompilerPlugin, VolumeCompilerPlugin,
11+
NetworkCompilerPlugin, SchemeCompilerPlugin, StrategyCompilerPlugin,
12+
)

‎paths_cli/compiling/core.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ class InstanceCompilerPlugin(OPSPlugin):
146146
"""
147147
SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json"
148148
category = None
149-
error_on_duplicate = False # TODO: temporary
150149
def __init__(self, builder, parameters, name=None, aliases=None,
151150
requires_ops=(1, 0), requires_cli=(0, 3)):
152151
super().__init__(requires_ops, requires_cli)
@@ -241,8 +240,6 @@ def __call__(self, dct):
241240

242241
class CategoryCompiler:
243242
"""Generic compile class; instances for each category"""
244-
# error_on_duplicate = False # TODO: temporary
245-
error_on_duplicate = True
246243
def __init__(self, type_dispatch, label):
247244
if type_dispatch is None:
248245
type_dispatch = {}
@@ -282,11 +279,11 @@ def register_object(self, obj, name):
282279
def register_builder(self, builder, name):
283280
if name in self.type_dispatch:
284281
if self.type_dispatch[name] is builder:
285-
return # nothing to do here!
282+
# if it's the identical object, just skip it
283+
return
286284
msg = (f"'{name}' is already registered "
287285
f"with {self.label}")
288-
if self.error_on_duplicate:
289-
raise RuntimeError(msg)
286+
raise RuntimeError(msg)
290287
else:
291288
self.type_dispatch[name] = builder
292289

‎paths_cli/compiling/plugins.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class CategoryPlugin(OPSPlugin):
55
"""
66
Category plugins only need to be made for top-level
77
"""
8-
error_on_duplicate = False # TODO: temporary
98
def __init__(self, plugin_class, aliases=None, requires_ops=(1, 0),
109
requires_cli=(0,4)):
1110
super().__init__(requires_ops, requires_cli)

‎paths_cli/plugin_management.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Plugin(object):
2020
tuple representing hte minimum allowed version of the command line
2121
interface application
2222
"""
23-
error_on_duplicate = True
2423
def __init__(self, requires_lib, requires_cli):
2524
self.requires_lib = requires_lib
2625
self.requires_cli = requires_cli
@@ -39,10 +38,7 @@ def attach_metadata(self, location, plugin_type):
3938
f"The plugin {repr(self)} has been previously "
4039
"registered with different metadata."
4140
)
42-
if self.error_on_duplicate:
43-
raise PluginRegistrationError(msg)
44-
else:
45-
warnings.warn(msg)
41+
raise PluginRegistrationError(msg)
4642

4743
self.location = location
4844
self.plugin_type = plugin_type

‎paths_cli/tests/compiling/test_core.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,20 @@ def test_register_builder(self):
290290
assert self.compiler(input_dict) == 10
291291

292292
def test_register_builder_duplicate(self):
293-
# if an attempt is made to registered a builder with a name that is
293+
# if an attempt is made to registere a builder with a name that is
294294
# already in use, a RuntimeError is raised
295295
orig = self.compiler.type_dispatch['foo']
296296
with pytest.raises(RuntimeError, match="already registered"):
297297
self.compiler.register_builder(lambda dct: 10, 'foo')
298298

299299
assert self.compiler.type_dispatch['foo'] is orig
300300

301+
def test_register_builder_identical(self):
302+
# if an attempt is made to register a builder that has already been
303+
# registered, nothin happens (since it is already registered)
304+
orig = self.compiler.type_dispatch['foo']
305+
self.compiler.register_builder(orig, 'foo')
306+
301307
@pytest.mark.parametrize('input_type', ['str', 'dict'])
302308
def test_compile(self, input_type):
303309
# the compile method should work whether the input is a dict

0 commit comments

Comments
 (0)