mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 01:16:28 +03:00
Support --opt=value format in CLI config overrides
This commit is contained in:
parent
ae4d8a6ffd
commit
06a97a8766
|
@ -68,10 +68,13 @@ def parse_config_overrides(args: List[str]) -> Dict[str, Any]:
|
||||||
opt = opt.replace("--", "").replace("-", "_")
|
opt = opt.replace("--", "").replace("-", "_")
|
||||||
if "." not in opt:
|
if "." not in opt:
|
||||||
msg.fail(f"{err}: can't override top-level section", exits=1)
|
msg.fail(f"{err}: can't override top-level section", exits=1)
|
||||||
if not args or args[0].startswith("--"): # flag with no value
|
if "=" in opt: # we have --opt=value
|
||||||
value = "true"
|
opt, value = opt.split("=", 1)
|
||||||
else:
|
else:
|
||||||
value = args.pop(0)
|
if not args or args[0].startswith("--"): # flag with no value
|
||||||
|
value = "true"
|
||||||
|
else:
|
||||||
|
value = args.pop(0)
|
||||||
# Just like we do in the config, we're calling json.loads on the
|
# Just like we do in the config, we're calling json.loads on the
|
||||||
# values. But since they come from the CLI, it'd be unintuitive to
|
# values. But since they come from the CLI, it'd be unintuitive to
|
||||||
# explicitly mark strings with escaped quotes. So we're working
|
# explicitly mark strings with escaped quotes. So we're working
|
||||||
|
|
|
@ -298,9 +298,13 @@ def test_project_config_validation2(config, n_errors):
|
||||||
[
|
[
|
||||||
# fmt: off
|
# fmt: off
|
||||||
(["--x.foo", "10"], {"x.foo": 10}),
|
(["--x.foo", "10"], {"x.foo": 10}),
|
||||||
|
(["--x.foo=10"], {"x.foo": 10}),
|
||||||
(["--x.foo", "bar"], {"x.foo": "bar"}),
|
(["--x.foo", "bar"], {"x.foo": "bar"}),
|
||||||
|
(["--x.foo=bar"], {"x.foo": "bar"}),
|
||||||
(["--x.foo", "--x.bar", "baz"], {"x.foo": True, "x.bar": "baz"}),
|
(["--x.foo", "--x.bar", "baz"], {"x.foo": True, "x.bar": "baz"}),
|
||||||
(["--x.foo", "10.1", "--x.bar", "--x.baz", "false"], {"x.foo": 10.1, "x.bar": True, "x.baz": False})
|
(["--x.foo", "--x.bar=baz"], {"x.foo": True, "x.bar": "baz"}),
|
||||||
|
(["--x.foo", "10.1", "--x.bar", "--x.baz", "false"], {"x.foo": 10.1, "x.bar": True, "x.baz": False}),
|
||||||
|
(["--x.foo", "10.1", "--x.bar", "--x.baz=false"], {"x.foo": 10.1, "x.bar": True, "x.baz": False})
|
||||||
# fmt: on
|
# fmt: on
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user