Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 4cdd4a3

Browse files
committed
cli: Remove old operations command code
Signed-off-by: John Andersen <[email protected]>
1 parent 55da27b commit 4cdd4a3

File tree

5 files changed

+32
-156
lines changed

5 files changed

+32
-156
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
and all their ancestors to check redundancy (a hold over from pre uid days).
1717
It now correctly only uses the inputs in the parameter set. This fixes a major
1818
performance issue.
19+
### Removed
20+
- CLI command `operations` removed in favor of `dataflow run`
1921

2022
## [0.3.0] - 2019-10-26
2123
### Added

dffml/cli/dataflow.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import contextlib
55

66
from ..base import BaseConfig
7+
from ..df.base import BaseOrchestrator
78
from ..df.types import DataFlow, Stage, Operation, Input
89
from ..df.memory import (
10+
MemoryOrchestrator,
911
MemoryInputSet,
1012
MemoryInputSetConfig,
1113
StringInputSetContext,
@@ -17,7 +19,8 @@
1719
from ..util.entrypoint import load
1820
from ..util.cli.arg import Arg
1921
from ..util.cli.cmd import CMD
20-
from ..util.cli.cmds import SourcesCMD, KeysCMD, OrchestratorCMD
22+
from ..util.cli.cmds import SourcesCMD, KeysCMD
23+
from ..util.cli.parser import ParseInputsAction
2124

2225

2326
class Merge(CMD):
@@ -90,7 +93,7 @@ async def run(self):
9093
print((await loader.dumpb(exported)).decode())
9194

9295

93-
class RunCMD(OrchestratorCMD, SourcesCMD):
96+
class RunCMD(SourcesCMD):
9497

9598
arg_sources = SourcesCMD.arg_sources.modify(required=False)
9699
arg_caching = Arg(
@@ -124,6 +127,29 @@ class RunCMD(OrchestratorCMD, SourcesCMD):
124127
type=BaseConfigLoader.load,
125128
default=None,
126129
)
130+
arg_orchestrator = Arg(
131+
"-orchestrator", type=BaseOrchestrator.load, default=MemoryOrchestrator
132+
)
133+
arg_inputs = Arg(
134+
"-inputs",
135+
nargs="+",
136+
action=ParseInputsAction,
137+
default=[],
138+
help="Other inputs to add under each ctx (repo's src_url will "
139+
+ "be used as the context)",
140+
)
141+
arg_repo_def = Arg(
142+
"-repo-def",
143+
default=False,
144+
type=str,
145+
help="Definition to be used for repo.src_url."
146+
+ "If set, repo.src_url will be added to the set of inputs "
147+
+ "under each context (which is also the repo's src_url)",
148+
)
149+
150+
def __init__(self, *args, **kwargs):
151+
super().__init__(*args, **kwargs)
152+
self.orchestrator = self.orchestrator.withconfig(self.extra_config)
127153

128154

129155
class RunAllRepos(RunCMD):

dffml/util/cli/cmds.py

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,16 @@
11
import os
2-
import sys
3-
import ast
4-
import copy
5-
import json
6-
import asyncio
72
import inspect
8-
import logging
9-
import argparse
10-
from typing import Optional
113

12-
from ...repo import Repo
134
from ...port import Port
14-
from ...feature import Feature, Features
155
from ...source.source import BaseSource, Sources
166
from ...source.json import JSONSource
177
from ...source.file import FileSourceConfig
188
from ...model import Model
199

20-
from ...df.types import Operation
21-
from ...df.base import (
22-
Input,
23-
BaseInputNetwork,
24-
BaseOperationNetwork,
25-
BaseLockNetwork,
26-
BaseRedundancyChecker,
27-
BaseOperationImplementationNetwork,
28-
BaseOrchestrator,
29-
StringInputSetContext,
30-
)
31-
32-
from ...df.memory import (
33-
MemoryInputNetwork,
34-
MemoryOperationNetwork,
35-
MemoryLockNetwork,
36-
MemoryRedundancyChecker,
37-
MemoryOperationImplementationNetwork,
38-
MemoryOrchestrator,
39-
MemoryInputSet,
40-
MemoryInputSetConfig,
41-
)
4210

4311
from .arg import Arg
4412
from .cmd import CMD
45-
from .parser import (
46-
list_action,
47-
ParseOutputSpecsAction,
48-
ParseInputsAction,
49-
ParseRemapAction,
50-
)
13+
from .parser import list_action
5114

5215

5316
class ListEntrypoint(CMD):
@@ -129,58 +92,3 @@ class KeysCMD(CMD):
12992
nargs="+",
13093
required=True,
13194
)
132-
133-
134-
class BaseOrchestratorCMD(CMD):
135-
"""
136-
Data Flow commands
137-
"""
138-
139-
arg_orchestrator = Arg(
140-
"-orchestrator", type=BaseOrchestrator.load, default=MemoryOrchestrator
141-
)
142-
arg_output_specs = Arg(
143-
"-output-specs", nargs="+", action=ParseOutputSpecsAction, default=[]
144-
)
145-
arg_inputs = Arg(
146-
"-inputs",
147-
nargs="+",
148-
action=ParseInputsAction,
149-
default=[],
150-
help="Other inputs to add under each ctx (repo's src_url will "
151-
+ "be used as the context)",
152-
)
153-
arg_repo_def = Arg(
154-
"-repo-def",
155-
default=False,
156-
type=str,
157-
help="Definition to be used for repo.src_url."
158-
+ "If set, repo.src_url will be added to the set of inputs "
159-
+ "under each context (which is also the repo's src_url)",
160-
)
161-
162-
def __init__(self, *args, **kwargs):
163-
super().__init__(*args, **kwargs)
164-
self.orchestrator = self.orchestrator.withconfig(self.extra_config)
165-
166-
# Load all entrypoints which may possibly be selected. Then have them add
167-
# their arguments to the DataFlowFacilitator-tots command.
168-
@classmethod
169-
def add_bases(cls):
170-
# TODO Add args() for each loaded class as argparse arguments
171-
return cls
172-
cls = copy.deepcopy(cls)
173-
for base in [
174-
BaseInputNetwork,
175-
BaseOperationNetwork,
176-
BaseLockNetwork,
177-
BaseRedundancyChecker,
178-
BaseOperationImplementationNetwork,
179-
BaseOrchestrator,
180-
]:
181-
for loaded in base.load():
182-
loaded.args(cls.EXTRA_CONFIG_ARGS)
183-
return cls
184-
185-
186-
OrchestratorCMD = BaseOrchestratorCMD.add_bases()

dffml/util/cli/parser.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
# SPDX-License-Identifier: MIT
22
# Copyright (c) 2019 Intel Corporation
3-
import os
4-
import sys
53
import ast
6-
import copy
7-
import json
8-
import asyncio
9-
import inspect
10-
import logging
114
import argparse
12-
from typing import Optional
13-
14-
from ...repo import Repo
15-
from ...port import Port
16-
from ...feature import Feature, Features
17-
from ...source.source import BaseSource, Sources
18-
19-
from ...df.base import Operation, OperationImplementation
205

216
from .cmd import ParseLoggingAction
227

@@ -36,7 +21,7 @@ def __call__(self, parser, namespace, values, option_string=None):
3621
return ParseExpandAction
3722

3823

39-
class ParseOutputSpecsAction(argparse.Action):
24+
class ParseInputsAction(argparse.Action):
4025
def __call__(self, parser, namespace, values, option_string=None):
4126
if not isinstance(values, list):
4227
values = [values]
@@ -48,18 +33,3 @@ def __call__(self, parser, namespace, values, option_string=None):
4833
for value in values
4934
]
5035
setattr(namespace, self.dest, ouput_specs)
51-
52-
53-
ParseInputsAction = ParseOutputSpecsAction
54-
55-
56-
class ParseRemapAction(argparse.Action):
57-
def __call__(self, parser, namespace, values, option_string=None):
58-
if not isinstance(values, list):
59-
values = [values]
60-
inputs = []
61-
for value in values:
62-
output_operation, sub = value.split(".", maxsplit=1)
63-
sub, feature = sub.split("=", maxsplit=1)
64-
inputs.append((output_operation, sub, feature))
65-
setattr(namespace, self.dest, inputs)

tests/util/test_cli.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
from dffml.util.cli.parser import (
2222
list_action,
2323
ParseLoggingAction,
24-
ParseOutputSpecsAction,
2524
ParseInputsAction,
26-
ParseRemapAction,
2725
)
2826

2927
from dffml.util.cli.cmds import ListEntrypoint, ModelCMD
@@ -65,20 +63,6 @@ def test_logging(self):
6563
action(None, namespace, "WARNING")
6664
mock_method.assert_called_once_with(level=logging.WARNING)
6765

68-
def test_output_specs(self):
69-
namespace = Namespace(output_specs=False)
70-
action = ParseOutputSpecsAction(dest="output_specs", option_strings="")
71-
action(None, namespace, ["['result']=get_single_spec"])
72-
self.assertEqual(len(namespace.output_specs), 1)
73-
self.assertEqual(
74-
namespace.output_specs[0], (["result"], "get_single_spec")
75-
)
76-
action(None, namespace, "['result']=get_single_spec")
77-
self.assertEqual(len(namespace.output_specs), 1)
78-
self.assertEqual(
79-
namespace.output_specs[0], (["result"], "get_single_spec")
80-
)
81-
8266
def test_inputs(self):
8367
namespace = Namespace(inputs=False)
8468
action = ParseInputsAction(dest="inputs", option_strings="")
@@ -89,20 +73,6 @@ def test_inputs(self):
8973
self.assertEqual(len(namespace.inputs), 1)
9074
self.assertEqual(namespace.inputs[0], (["result"], "get_single_spec"))
9175

92-
def test_remap(self):
93-
namespace = Namespace(inputs=False)
94-
action = ParseRemapAction(dest="inputs", option_strings="")
95-
action(None, namespace, ["get_single.result=string_calculator"])
96-
self.assertEqual(len(namespace.inputs), 1)
97-
self.assertEqual(
98-
namespace.inputs[0], ("get_single", "result", "string_calculator")
99-
)
100-
action(None, namespace, "get_single.result=string_calculator")
101-
self.assertEqual(len(namespace.inputs), 1)
102-
self.assertEqual(
103-
namespace.inputs[0], ("get_single", "result", "string_calculator")
104-
)
105-
10676

10777
class TestJSONEncoder(unittest.TestCase):
10878
def test_default(self):

0 commit comments

Comments
 (0)