Skip to content

Commit

Permalink
input: allow to remove builtin white list entries
Browse files Browse the repository at this point in the history
The new "whitelistRemove" key in default.yaml remove entries from the
whitelist. It has a higher precedence than adding whitelist entries. It
is not an error to remove non-existent whitelist entries.
  • Loading branch information
jkloetzke committed Oct 22, 2023
1 parent ae4ea8f commit b3c6cdf
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 }),
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b3c6cdf

Please sign in to comment.