Skip to content

Commit dd57db8

Browse files
authored
Allow double-adding exact same config option (#2397)
The config system is a little brittle when Manticore tries to import all platform modules since we set the config options upon import and declaring the same config option in two different platforms will cause issues. This is a bit of a band-aid over the real problem, which might look something like moving shared config options to a separate file that each platform can import. Looks to be some related refactoring work here #1636
1 parent d575cf7 commit dd57db8

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

manticore/utils/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def add(self, name: str, default=None, description: str = None):
103103
104104
"""
105105
if name in self._vars:
106+
# Be kind when double-adding the same exact config
107+
existing = self._vars[name]
108+
if default == existing.default and description == existing.description:
109+
return
106110
raise ConfigError(f"{self.name}.{name} already defined.")
107111

108112
if name == "name":

manticore/wasm/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ..utils import config
55

66
consts = config.get_group("cli")
7+
consts.add("profile", default=False, description="Enable worker profiling mode")
78
consts.add("target_func", default="main", description="WASM Function to execute")
89

910

tests/other/utils/test_config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ def test_default_vars(self):
4141
self.assertFalse(g._vars["val1"].was_set)
4242
self.assertTrue(g._vars["val2"].was_set)
4343

44-
def test_double_add(self):
44+
def test_double_add_different(self):
4545
g = config.get_group("test1")
4646
g.add("val1", default="foo")
4747
with self.assertRaises(config.ConfigError):
4848
g.add("val1")
4949

50+
def test_double_add_exact_duplicate(self):
51+
g = config.get_group("test2")
52+
g.add("val1", default="foo", description="Some description")
53+
g.add("val1", default="foo", description="Some description")
54+
5055
def test_update(self):
5156
g = config.get_group("update")
5257
g.add("val", default="default", description="description")

tests/wasm/test_examples.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def test_implicit_call(self):
121121
self.assertEqual(sorted(results), [70])
122122

123123
def test_wasm_main(self):
124-
config.get_group("cli").add("profile", False)
125124
m = wasm_main(
126125
namedtuple("Args", ["argv", "workspace", "policy"])([collatz_file], "mcore_tmp", "ALL"),
127126
None,

0 commit comments

Comments
 (0)