diff --git a/pym/bob/input.py b/pym/bob/input.py index 4af9d8b66..988af9c4f 100644 --- a/pym/bob/input.py +++ b/pym/bob/input.py @@ -277,6 +277,8 @@ def onFinish(self, env, properties): class PluginSetting: + priority = 50 + """Base class for plugin settings. Plugins can be configured in the user configuration of a project. The @@ -361,10 +363,11 @@ def newFun(args, **kwargs): class BuiltinSetting(PluginSetting): """Tiny wrapper to define Bob built-in settings""" - def __init__(self, schema, updater, mangle = False): + def __init__(self, schema, updater, mangle = False, priority=50): self.__schema = schema self.__updater = updater self.__mangle = mangle + self.priority = priority def merge(self, other): self.__updater(self.__schema.validate(other) if self.__mangle else other) @@ -3132,6 +3135,14 @@ def updateWhiteList(x): else: self.__whiteList.update(x) + def removeWhiteList(x): + if self.__platform == "win32": + # Convert to upper case on Windows. The Python interpreter does that + # too and the variables are considered case insensitive by Windows. + self.__whiteList.difference_update(i.upper() for i in x) + else: + self.__whiteList.difference_update(x) + self.__settings = { "alias" : BuiltinSetting( schema.Schema({ schema.Regex(r'^[0-9A-Za-z_-]+$') : str }), @@ -3221,6 +3232,11 @@ def updateWhiteList(x): schema.Schema([ schema.Regex(r'^[^=]*$') ]), updateWhiteList ), + "whitelistRemove" : BuiltinSetting( + schema.Schema([ schema.Regex(r'^[^=]*$') ]), + removeWhiteList, + priority=100 + ), } def __addRecipe(self, recipe): @@ -3623,11 +3639,14 @@ def preValidate(data): e.pushFrame(path) raise + print(self.__whiteList) + def __parseUserConfig(self, fileName, relativeIncludes=None): if relativeIncludes is None: relativeIncludes = self.getPolicy("relativeIncludes") cfg = self.loadYaml(fileName, self.__userConfigSchema) - for (name, value) in cfg.items(): + # merge settings by priority + for (name, value) in sorted(cfg.items(), key=lambda i: self.__settings[i[0]].priority): if name != "include" and name != "require": self.__settings[name].merge(value) for p in cfg.get("require", []): p = (os.path.join(os.path.dirname(fileName), p) if relativeIncludes else p) + ".yaml"