Skip to content

Commit 4e74899

Browse files
committed
Rename: compiler_name => category
1 parent 43fec22 commit 4e74899

7 files changed

Lines changed: 39 additions & 39 deletions

File tree

‎paths_cli/compiling/core.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class InstanceCompilerPlugin(OPSPlugin):
145145
version of the OPS CLI requires for this functionality
146146
"""
147147
SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json"
148-
compiler_name = None
148+
category = None
149149
error_on_duplicate = False # TODO: temporary
150150
def __init__(self, builder, parameters, name=None, aliases=None,
151151
requires_ops=(1, 0), requires_cli=(0, 3)):
@@ -166,8 +166,8 @@ def __init__(self, builder, parameters, name=None, aliases=None,
166166

167167
@property
168168
def schema_name(self):
169-
if not self.name.endswith(self.compiler_name):
170-
schema_name = f"{self.name}-{self.compiler_name}"
169+
if not self.name.endswith(self.category):
170+
schema_name = f"{self.name}-{self.category}"
171171
else:
172172
schema_name = self.name
173173
return schema_name

‎paths_cli/compiling/plugins.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ def __init__(self, plugin_class, aliases=None, requires_ops=(1, 0),
1616

1717
@property
1818
def name(self):
19-
return self.plugin_class.compiler_name
19+
return self.plugin_class.category
2020

2121
def __repr__(self):
2222
return (f"CompilerPlugin({self.plugin_class.__name__}, "
2323
f"{self.aliases})")
2424

2525

2626
class EngineCompilerPlugin(InstanceCompilerPlugin):
27-
compiler_name = 'engine'
27+
category = 'engine'
2828

2929
class CVCompilerPlugin(InstanceCompilerPlugin):
30-
compiler_name = 'cv'
30+
category = 'cv'
3131

3232
class VolumeCompilerPlugin(InstanceCompilerPlugin):
33-
compiler_name = 'volume'
33+
category = 'volume'
3434

3535
class NetworkCompilerPlugin(InstanceCompilerPlugin):
36-
compiler_name = 'network'
36+
category = 'network'
3737

3838
class SchemeCompilerPlugin(InstanceCompilerPlugin):
39-
compiler_name = 'scheme'
39+
category = 'scheme'
4040

4141
class StrategyCompilerPlugin(InstanceCompilerPlugin):
42-
compiler_name = 'strategy'
42+
category = 'strategy'

‎paths_cli/compiling/root_compiler.py‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ def _canonical_name(alias):
5151
alias_to_canonical.update({pname: pname for pname in _COMPILERS})
5252
return alias_to_canonical.get(alias, None)
5353

54-
def _get_compiler(compiler_name):
54+
def _get_compiler(category):
5555
"""
56-
_get_compiler must only be used after the compilers have been
56+
_get_compiler must only be used after the CategoryCompilers have been
5757
registered. It will automatically create a compiler for any unknown
58-
``compiler_name.``
58+
``category.``
5959
"""
60-
if compiler_name is None:
60+
if category is None:
6161
if None not in _COMPILERS:
6262
_COMPILERS[None] = CategoryCompiler(None, None)
6363
return _COMPILERS[None]
6464

65-
canonical_name = _canonical_name(compiler_name)
65+
canonical_name = _canonical_name(category)
6666
# create a new compiler if none exists
6767
if canonical_name is None:
68-
canonical_name = compiler_name
69-
_COMPILERS[compiler_name] = CategoryCompiler(None, compiler_name)
68+
canonical_name = category
69+
_COMPILERS[category] = CategoryCompiler(None, category)
7070
return _COMPILERS[canonical_name]
7171

7272
def _register_compiler_plugin(plugin):
7373
DUPLICATE_ERROR = CategoryCompilerRegistrationError(
74-
f"The name {plugin.name} has been reserved by another compiler"
74+
f"The category '{plugin.name}' has been reserved by another plugin"
7575
)
7676
if plugin.name in _COMPILERS or plugin.name in _ALIASES:
7777
raise DUPLICATE_ERROR
@@ -93,15 +93,15 @@ def _register_compiler_plugin(plugin):
9393
# the loading of the compiler by using a proxy object.
9494

9595
class _CategoryCompilerProxy:
96-
def __init__(self, compiler_name):
97-
self.compiler_name = compiler_name
96+
def __init__(self, category):
97+
self.category = category
9898

9999
@property
100100
def _proxy(self):
101-
canonical_name = _canonical_name(self.compiler_name)
101+
canonical_name = _canonical_name(self.category)
102102
if canonical_name is None:
103-
raise RuntimeError("No compiler registered for "
104-
f"'{self.compiler_name}'")
103+
raise RuntimeError("No CategoryCompiler registered for "
104+
f"'{self.category}'")
105105
return _get_compiler(canonical_name)
106106

107107
@property
@@ -111,17 +111,17 @@ def named_objs(self):
111111
def __call__(self, *args, **kwargs):
112112
return self._proxy(*args, **kwargs)
113113

114-
def compiler_for(compiler_name):
114+
def compiler_for(category):
115115
"""Delayed compiler calling.
116116
117117
Use this when you need to use a compiler as the loader for a parameter.
118118
119119
Parameters
120120
----------
121-
compiler_name : str
122-
the name of the compiler to use
121+
category : str
122+
the category to use (:class:`.CategoryCompiler` name or alias)
123123
"""
124-
return _CategoryCompilerProxy(compiler_name)
124+
return _CategoryCompilerProxy(category)
125125

126126

127127
### Registering builder plugins and user-facing register_plugins ###########
@@ -143,7 +143,7 @@ def _get_registration_names(plugin):
143143
return ordered_names
144144

145145
def _register_builder_plugin(plugin):
146-
compiler = _get_compiler(plugin.compiler_name)
146+
compiler = _get_compiler(plugin.category)
147147
for name in _get_registration_names(plugin):
148148
compiler.register_builder(plugin, name)
149149

‎paths_cli/tests/compiling/test_core.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ def setup(self):
143143
name='demo',
144144
aliases=['foo', 'bar'],
145145
)
146-
self.instance_builder.compiler_name = 'demo'
146+
self.instance_builder.category = 'demo'
147147
self.input_dict = {'req_param': "qux", 'opt_override': 25}
148148

149149
def test_schema_name(self):
150150
assert self.instance_builder.schema_name == 'demo'
151-
self.instance_builder.compiler_name = 'foo'
151+
self.instance_builder.category = 'foo'
152152
assert self.instance_builder.schema_name == 'demo-foo'
153153
self.instance_builder.name = 'demo-foo'
154154
assert self.instance_builder.schema_name == 'demo-foo'

‎paths_cli/tests/compiling/test_plugins.py‎

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

55
class TestCompilerPlugin:
66
def setup(self):
7-
self.plugin_class = Mock(compiler_name='foo')
7+
self.plugin_class = Mock(category='foo')
88
self.plugin = CategoryPlugin(self.plugin_class)
99
self.aliased_plugin = CategoryPlugin(self.plugin_class,
1010
aliases=['bar'])

‎paths_cli/tests/compiling/test_root_compiler.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def foo_compiler():
2121

2222
@pytest.fixture
2323
def foo_compiler_plugin():
24-
return CategoryPlugin(Mock(compiler_name='foo'), ['bar'])
24+
return CategoryPlugin(Mock(category='foo'), ['bar'])
2525

2626
@pytest.fixture
2727
def foo_baz_builder_plugin():
2828
builder = InstanceCompilerPlugin(lambda: "FOO" , [], name='baz',
2929
aliases=['qux'])
30-
builder.compiler_name = 'foo'
30+
builder.category = 'foo'
3131
return builder
3232

3333
### CONSTANTS ##############################################################
@@ -63,7 +63,7 @@ def test_proxy(self):
6363

6464
def test_proxy_nonexisting(self):
6565
# _proxy should error if the no compiler is registered
66-
with pytest.raises(RuntimeError, match="No compiler registered"):
66+
with pytest.raises(RuntimeError, match="No CategoryCompiler"):
6767
self.proxy._proxy
6868

6969
def test_named_objs(self):
@@ -83,7 +83,7 @@ def test_compiler_for_nonexisting():
8383
assert 'foo' not in compilers
8484
proxy = compiler_for('foo')
8585
assert 'foo' not in compilers
86-
with pytest.raises(RuntimeError, match="No compiler registered"):
86+
with pytest.raises(RuntimeError, match="No CategoryCompiler"):
8787
proxy._proxy
8888

8989
def test_compiler_for_existing(foo_compiler):
@@ -158,10 +158,10 @@ def test_register_compiler_plugin_duplicate(duplicate_of, duplicate_from):
158158
# duplicate_of: existing
159159
# duplicate_from: which part of the plugin has the duplicated name
160160
if duplicate_from == 'canonical':
161-
plugin = CategoryPlugin(Mock(compiler_name=duplicate_of),
161+
plugin = CategoryPlugin(Mock(category=duplicate_of),
162162
aliases=['foo'])
163163
else:
164-
plugin = CategoryPlugin(Mock(compiler_name='foo'),
164+
plugin = CategoryPlugin(Mock(category='foo'),
165165
aliases=[duplicate_of])
166166

167167
compilers = {'canonical': "FOO"}

‎paths_cli/tests/compiling/utils.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from paths_cli.compiling.core import CategoryCompiler
22

3-
def mock_compiler(compiler_name, type_dispatch=None, named_objs=None):
3+
def mock_compiler(category, type_dispatch=None, named_objs=None):
44
if type_dispatch is None:
55
type_dispatch = {}
6-
compiler = CategoryCompiler(type_dispatch, compiler_name)
6+
compiler = CategoryCompiler(type_dispatch, category)
77
if named_objs is not None:
88
compiler.named_objs = named_objs
99
return compiler

0 commit comments

Comments
 (0)