Skip to content

Commit 272087b

Browse files
committed
Clean up to remove unused stuff
1 parent 002555a commit 272087b

2 files changed

Lines changed: 0 additions & 107 deletions

File tree

‎paths_cli/plugin_management.py‎

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,6 @@ def func(self):
5757
def __repr__(self):
5858
return "OPSCommandPlugin(" + self.name + ")"
5959

60-
61-
class OPSParserPlugin(Plugin):
62-
"""Plugin to add a new Parser (top-level stage in YAML parsing"""
63-
def __init__(self, parser, requires_ops=(1, 0), requires_cli=(0, 4)):
64-
self.parser = parser
65-
super().__init__(requires_ops, requires_cli)
66-
67-
68-
class OPSInstanceBuilderPlugin(Plugin):
69-
"""
70-
Plugin to add a new object type (InstanceBuilder) to YAML parsing.
71-
"""
72-
def __init__(self, yaml_name, instance_builder, requires_ops=(1, 0),
73-
requires_cli=(0, 3)):
74-
self.yaml_name = yaml_name
75-
self.instance_builder = instance_builder
76-
super().__init__(requires_ops, requires_cli)
77-
78-
7960
class CLIPluginLoader(object):
8061
"""Abstract object for CLI plugins
8162
@@ -103,25 +84,6 @@ def _find_candidates(self):
10384
def _make_nsdict(candidate):
10485
raise NotImplementedError()
10586

106-
# TODO: this should validate with an isinstance of the plugin class
107-
@staticmethod
108-
def _validate(nsdict):
109-
for attr in ['CLI', 'SECTION']:
110-
if attr not in nsdict:
111-
return False
112-
return True
113-
114-
def _get_command_name(self, candidate):
115-
raise NotImplementedError()
116-
117-
# TODO: this should return the actual plugin objects
118-
def _find_valid(self):
119-
candidates = self._find_candidates()
120-
namespaces = {cand: self._make_nsdict(cand) for cand in candidates}
121-
valid = {cand: ns for cand, ns in namespaces.items()
122-
if self._validate(ns)}
123-
return valid
124-
12587
def _find_candidate_namespaces(self):
12688
candidates = self._find_candidates()
12789
namespaces = {cand: self._make_nsdict(cand) for cand in candidates}
@@ -141,16 +103,6 @@ def __call__(self):
141103
namespaces = self._find_candidate_namespaces()
142104
plugins = list(self._find_plugins(namespaces))
143105
return plugins
144-
# valid = self._find_valid()
145-
# plugins = [
146-
# OPSPlugin(name=self._get_command_name(cand),
147-
# location=cand,
148-
# func=ns['CLI'],
149-
# section=ns['SECTION'],
150-
# plugin_type=self.plugin_type)
151-
# for cand, ns in valid.items()
152-
# ]
153-
# return plugins
154106

155107

156108
class FilePluginLoader(CLIPluginLoader):
@@ -188,12 +140,6 @@ def _make_nsdict(candidate):
188140
eval(code, ns, ns)
189141
return ns
190142

191-
def _get_command_name(self, candidate):
192-
_, command_name = os.path.split(candidate)
193-
command_name = command_name[:-3] # get rid of .py
194-
command_name = command_name.replace('_', '-') # commands use -
195-
return command_name
196-
197143

198144
class NamespacePluginLoader(CLIPluginLoader):
199145
"""Load namespace plugins (plugins for wide distribution)
@@ -227,11 +173,3 @@ def iter_namespace(ns_pkg):
227173
@staticmethod
228174
def _make_nsdict(candidate):
229175
return vars(candidate)
230-
231-
def _get_command_name(self, candidate):
232-
command_name = candidate.__name__
233-
# +1 for the dot
234-
command_name = command_name[len(self.search_path) + 1:]
235-
command_name = command_name.replace('_', '-') # commands use -
236-
return command_name
237-

‎paths_cli/tests/test_plugin_management.py‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,6 @@
1010
# need to check that CLI is assigned to correct type
1111
import click
1212

13-
class TestCLIPluginLoader(object):
14-
def setup(self):
15-
class MockPlugin(object):
16-
def get_dict(self):
17-
return {
18-
'CLI': self.foo,
19-
'SECTION': "FooSection"
20-
}
21-
22-
def foo():
23-
pass
24-
25-
self.plugin = MockPlugin()
26-
self.loader = CLIPluginLoader(plugin_type="test", search_path="foo")
27-
self.loader._make_nsdict = MockPlugin.get_dict
28-
self.loader._find_candidates = MagicMock(return_value=[self.plugin])
29-
30-
@pytest.mark.parametrize('contains', ([], ['cli'], ['sec'],
31-
['cli', 'sec']))
32-
def test_validate(self, contains):
33-
expected = len(contains) == 2 # only case where we expect correct
34-
dct = {'cli': self.plugin.foo, 'sec': "FooSection"}
35-
fullnames = {'cli': "CLI", 'sec': "SECTION"}
36-
nsdict = {fullnames[obj]: dct[obj] for obj in contains}
37-
38-
assert CLIPluginLoader._validate(nsdict) == expected
39-
40-
def test_find_valid(self):
41-
# smoke test for the procedure
42-
expected = {self.plugin: self.plugin.get_dict()}
43-
assert self.loader._find_valid() == expected
44-
45-
4613
class PluginLoaderTest(object):
4714
def setup(self):
4815
self.expected_section = {'pathsampling': "Simulation",
@@ -89,12 +56,6 @@ def setup(self):
8956
def _make_candidate(self, command):
9057
return self.commands_dir / (command + ".py")
9158

92-
def test_get_command_name(self):
93-
# this may someday get parametrized, set it up to make it easy
94-
filename = "/foo/bar/baz_qux.py"
95-
expected = "baz-qux"
96-
assert self.loader._get_command_name(filename) == expected
97-
9859

9960
class TestNamespacePluginLoader(PluginLoaderTest):
10061
def setup(self):
@@ -106,9 +67,3 @@ def setup(self):
10667
def _make_candidate(self, command):
10768
name = self.namespace + "." + command
10869
return importlib.import_module(name)
109-
110-
def test_get_command_name(self):
111-
loader = NamespacePluginLoader('foo.bar', OPSCommandPlugin)
112-
candidate = MagicMock(__name__="foo.bar.baz_qux")
113-
expected = "baz-qux"
114-
assert loader._get_command_name(candidate) == expected

0 commit comments

Comments
 (0)