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

Commit 81eebed

Browse files
sakshamarora1pdxjohnny
authored andcommitted
util: cli: arg: Add configloading ability to parse_unknown
Signed-off-by: sakshamarora1 <[email protected]>
1 parent 092423c commit 81eebed

File tree

12 files changed

+93
-47
lines changed

12 files changed

+93
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9+
- Configloading ablity from CLI using "@" before filename
910
- Docstrings and doctestable example for DataFlowSource
1011
- XGBoost Regression Model
1112
- Pre-Trained PyTorch torchvision Models
1213
- Spacy model for NER
13-
- Added ability to rename outputs using GetSingle
14+
- Ability to rename outputs using GetSingle
1415
- Tutorial for using NLP operations with models
1516
- Operations plugin for NLP wrapping spacy and scikit functions
1617
- Support for default value in a Definition

dffml/util/cli/arg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ..data import traverse_config_set
77

88

9-
def parse_unknown(*unknown):
9+
async def parse_unknown(*unknown, configloaders=None):
1010
parsed = {}
1111
name = []
1212
add_to_parsed = []
@@ -24,6 +24,8 @@ def parse_unknown(*unknown):
2424
name = arg.lstrip("-").split("-")
2525
add_to_parsed = []
2626
else:
27+
if arg.startswith("@") and configloaders is not None:
28+
_, arg = await configloaders.load_file(arg[1:])
2729
add_to_parsed.append(arg)
2830
if unknown and name:
2931
if not add_to_parsed:

dffml/util/cli/cmd.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ..data import export_dict
1818
from .arg import Arg, parse_unknown
1919
from ...base import config, mkarg, field
20+
from ...configloader.configloader import ConfigLoaders
2021

2122
DisplayHelp = "Display help message"
2223

@@ -204,7 +205,10 @@ async def do_run(self):
204205
@classmethod
205206
async def cli(cls, *args):
206207
parser, (args, unknown) = await cls.parse_args(*args)
207-
args.extra_config = parse_unknown(*unknown)
208+
async with ConfigLoaders() as configloaders:
209+
args.extra_config = await parse_unknown(
210+
*unknown, configloaders=configloaders
211+
)
208212
if (
209213
getattr(cls, "run", None) is not None
210214
and getattr(args, "cmd", None) is None

model/tensorflow/tests/test_dnnc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def tearDownClass(cls):
6060

6161
async def test_config(self):
6262
config = self.model.__class__.config(
63-
parse_unknown(
63+
await parse_unknown(
6464
"--model-predict",
6565
"feature_name:int:1",
6666
"--model-classifications",

model/tensorflow/tests/test_dnnr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def tearDownClass(cls):
6464
async def test_config(self):
6565
# Setting up configuration for model
6666
config = self.model.__class__.config(
67-
parse_unknown(
67+
await parse_unknown(
6868
"--model-predict",
6969
"TARGET:float:1",
7070
"--model-features",

service/http/tests/test_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async def test_models(self):
155155

156156
class TestRoutesConfigure(TestRoutesRunning, AsyncTestCase):
157157
async def test_source(self):
158-
config = parse_unknown(
158+
config = await parse_unknown(
159159
"--source-filename", "dataset.csv", "-source-allowempty"
160160
)
161161
async with self.post("/configure/source/csv/salary", json=config) as r:
@@ -177,7 +177,7 @@ async def test_source(self):
177177
self.assertIn("salaryctx", self.cli.app["source_contexts"])
178178

179179
async def test_source_error(self):
180-
config = parse_unknown("--source-file", "dataset.csv")
180+
config = await parse_unknown("--source-file", "dataset.csv")
181181
with self.assertRaisesRegex(ServerException, "missing.*filename"):
182182
async with self.post("/configure/source/csv/salary", json=config):
183183
pass # pramga: no cov
@@ -193,7 +193,7 @@ async def test_model(self):
193193
with tempfile.TemporaryDirectory() as tempdir, patch.object(
194194
Model, "load", new=model_load
195195
):
196-
config = parse_unknown(
196+
config = await parse_unknown(
197197
"--model-directory",
198198
tempdir,
199199
"--model-features",
@@ -230,7 +230,7 @@ async def test_model(self):
230230

231231
async def test_model_config_error(self):
232232
# Should be directory, not folder
233-
config = parse_unknown("--model-directory", "mymodel_dir")
233+
config = await parse_unknown("--model-directory", "mymodel_dir")
234234
with patch.object(Model, "load", new=model_load):
235235
with self.assertRaisesRegex(ServerException, "missing.*features"):
236236
async with self.post(

tests/df/test_memory.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ def test_args(self):
6161
},
6262
)
6363

64-
@patch.object(BaseKeyValueStore, "load", load_kvstore_with_args)
65-
def test_config_default_label(self):
66-
was = MemoryRedundancyChecker.config(
67-
parse_unknown(
68-
"--rchecker-memory-kvstore",
69-
"withargs",
70-
"--rchecker-memory-kvstore-withargs-filename",
71-
"somefile",
64+
async def test_config_default_label(self):
65+
with patch.object(BaseKeyValueStore, "load", load_kvstore_with_args):
66+
was = MemoryRedundancyChecker.config(
67+
await parse_unknown(
68+
"--rchecker-memory-kvstore",
69+
"withargs",
70+
"--rchecker-memory-kvstore-withargs-filename",
71+
"somefile",
72+
)
7273
)
73-
)
74-
self.assertEqual(type(was), MemoryRedundancyCheckerConfig)
75-
self.assertEqual(type(was.kvstore), KeyValueStoreWithArguments)
76-
self.assertEqual(
77-
type(was.kvstore.config), KeyValueStoreWithArgumentsConfig
78-
)
79-
self.assertEqual(was.kvstore.config.filename, "somefile")
74+
self.assertEqual(type(was), MemoryRedundancyCheckerConfig)
75+
self.assertEqual(type(was.kvstore), KeyValueStoreWithArguments)
76+
self.assertEqual(
77+
type(was.kvstore.config), KeyValueStoreWithArgumentsConfig
78+
)
79+
self.assertEqual(was.kvstore.config.filename, "somefile")

tests/source/test_csv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ async def test_tag(self):
5454
self.assertEqual("1", rows["untagged"]["0"]["feed"])
5555
self.assertEqual("2", rows["sometag"]["0"]["face"])
5656

57-
def test_config_default(self):
57+
async def test_config_default(self):
5858
config = CSVSource.config(
59-
parse_unknown("--source-csv-filename", "feedface")
59+
await parse_unknown("--source-csv-filename", "feedface")
6060
)
6161
self.assertEqual(config.filename, "feedface")
6262
self.assertEqual(config.tag, "untagged")
@@ -66,9 +66,9 @@ def test_config_default(self):
6666
self.assertFalse(config.allowempty)
6767
self.assertIsNone(config.loadfiles)
6868

69-
def test_config_set(self):
69+
async def test_config_set(self):
7070
config = CSVSource.config(
71-
parse_unknown(
71+
await parse_unknown(
7272
"--source-csv-filename",
7373
"feedface",
7474
"--source-csv-tag",

tests/source/test_file.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ def test_args(self):
7979
},
8080
)
8181

82-
def test_config_readonly_default(self):
82+
async def test_config_readonly_default(self):
8383
config = FileSource.config(
84-
parse_unknown("--source-file-filename", "feedface")
84+
await parse_unknown("--source-file-filename", "feedface")
8585
)
8686
self.assertEqual(config.filename, "feedface")
8787
self.assertEqual(config.tag, "untagged")
8888
self.assertFalse(config.readwrite)
8989
self.assertFalse(config.allowempty)
9090

91-
def test_config_readonly_set(self):
91+
async def test_config_readonly_set(self):
9292
config = FileSource.config(
93-
parse_unknown(
93+
await parse_unknown(
9494
"--source-file-filename",
9595
"feedface",
9696
"--source-file-tag",

tests/test_base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from dffml.util.entrypoint import entrypoint, base_entry_point
1717
from dffml.util.cli.arg import Arg
1818
from dffml.util.cli.cmd import parse_unknown
19+
from dffml.util.asynctestcase import IntegrationCLITestCase
1920

2021

2122
@config
@@ -41,7 +42,7 @@ class FakeTesting(BaseTesting):
4142
CONFIG = FakeTestingConfig
4243

4344

44-
class TestAutoArgsConfig(unittest.TestCase):
45+
class TestAutoArgsConfig(IntegrationCLITestCase):
4546
def test_00_args(self):
4647
self.maxDiff = 99999
4748
self.assertEqual(
@@ -105,9 +106,9 @@ def test_00_args(self):
105106
},
106107
)
107108

108-
def test_config_defaults(self):
109+
async def test_config_defaults(self):
109110
config = FakeTesting.config(
110-
parse_unknown(
111+
await parse_unknown(
111112
"--test-fake-name",
112113
"feedface",
113114
"--test-num",
@@ -140,9 +141,9 @@ def test_config_defaults(self):
140141
)
141142
self.assertEqual(config.nums, (100,))
142143

143-
def test_config_set(self):
144+
async def test_config_set(self):
144145
config = FakeTesting.config(
145-
parse_unknown(
146+
await parse_unknown(
146147
"--test-fake-name",
147148
"feedface",
148149
"--test-num",

0 commit comments

Comments
 (0)