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 8fd0248
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 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":

Check warning on line 3139 in pym/bob/input.py

View check run for this annotation

Codecov / codecov/patch

pym/bob/input.py#L3139

Added line #L3139 was not covered by tests
# 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)

Check warning on line 3142 in pym/bob/input.py

View check run for this annotation

Codecov / codecov/patch

pym/bob/input.py#L3142

Added line #L3142 was not covered by tests
else:
self.__whiteList.difference_update(x)

Check warning on line 3144 in pym/bob/input.py

View check run for this annotation

Codecov / codecov/patch

pym/bob/input.py#L3144

Added line #L3144 was not covered by tests

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 @@ -3627,7 +3643,8 @@ 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.get(i[0], PluginSetting).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 8fd0248

Please sign in to comment.