Skip to content

Instantly share code, notes, and snippets.

@pdxjohnny

pdxjohnny/patch.diff

Last active Aug 14, 2020
Embed
What would you like to do?
dffml: configloader file @
diff --git a/dffml/util/cli/arg.py b/dffml/util/cli/arg.py
index 01ffa75b..e4fd9212 100644
--- a/dffml/util/cli/arg.py
+++ b/dffml/util/cli/arg.py
@@ -3,10 +3,10 @@
import copy
from typing import Optional
-from ..data import traverse_config_set
+from ..data import traverse_config_set, merge
-def parse_unknown(*unknown):
+async def parse_unknown(*unknown, configloaders=None):
parsed = {}
name = []
add_to_parsed = []
@@ -23,6 +23,9 @@ def parse_unknown(*unknown):
traverse_config_set(parsed, *name, add_to_parsed)
name = arg.lstrip("-").split("-")
add_to_parsed = []
+ elif arg.startswith("@") and configloaders is not None:
+ _, conf_dict = await configloaders.load_file(arg[1:])
+ merge(parsed, conf_dict)
else:
add_to_parsed.append(arg)
if unknown and name:
diff --git a/tests/util/lr-model-config.yaml b/tests/util/lr-model-config.yaml
new file mode 100644
index 00000000..1d24f434
--- /dev/null
+++ b/tests/util/lr-model-config.yaml
@@ -0,0 +1,6 @@
+model:
+ config:
+ predict:
+ dtype: int
+ length: 1
+ name: Salary
diff --git a/tests/util/test_cli.py b/tests/util/test_cli.py
index 1a97775d..f1dcd2dc 100644
--- a/tests/util/test_cli.py
+++ b/tests/util/test_cli.py
@@ -4,6 +4,7 @@ import sys
import json
import asyncio
import logging
+import pathlib
import unittest
from unittest.mock import patch
@@ -184,7 +185,7 @@ class TestCMD(AsyncTestCase):
mock_method.assert_called_once()
-class TestArg(unittest.TestCase):
+class TestArg(IntegrationCLITestCase):
def test_init(self):
arg = Arg("-test", key="value")
self.assertEqual(arg.name, "-test")
@@ -201,15 +202,33 @@ class TestArg(unittest.TestCase):
self.assertEqual(second["key"], "new_value")
def test_parse_unknown(self):
- parsed = parse_unknown(
- "-rchecker-memory-kvstore",
- "withargs",
- "-rchecker-memory-kvstore-withargs-filename",
- "somefile",
- )
+ self.required_plugins("dffml-config-yaml")
+ async with ConfigLoaders() as configloaders:
+ parsed = await parse_unknown(
+ "-rchecker-memory-kvstore",
+ "withargs",
+ "-rchecker-memory-kvstore-withargs-filename",
+ "somefile",
+ # More command line arguments via file
+ "-model",
+ "slr",
+ "@"
+ + str(pathlib.Path(__file__).parent / "lr-model-config.yaml"),
+ configloaders=configloaders,
+ )
self.assertEqual(
parsed,
{
+ "model": {
+ "plugin": "slr",
+ "config": {
+ "predict": {
+ "dtype": "int",
+ "length": 1,
+ "name": "Salary",
+ }
+ },
+ },
"rchecker": {
"plugin": None,
"config": {
@@ -233,7 +252,7 @@ class TestArg(unittest.TestCase):
},
}
},
- }
+ },
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment