##// END OF EJS Templates
configitems: add a devel warning for extensions items overiding core one...
configitems: add a devel warning for extensions items overiding core one We do not want such case to pass silently. In the future we'll likely have useful tool for an extension to alter the existing definition in core.

File last commit:

r33128:bf1292c0 default
r33128:bf1292c0 default
Show More
configitems.py
70 lines | 2.0 KiB | text/x-python | PythonLexer
configitems: add a basic class to hold config item information...
r32983 # configitems.py - centralized declaration of configuration option
#
# Copyright 2017 Pierre-Yves David <pierre-yves.david@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
configitems: extract the logic to build a registrar on any configtable...
r33126 import functools
configitems: introduce a central registry for config option...
r32984 from . import (
error,
)
configitems: add an official API for extensions to register config item...
r33127 def loadconfigtable(ui, extname, configtable):
"""update config item known to the ui with the extension ones"""
for section, items in configtable.items():
configitems: add a devel warning for extensions items overiding core one...
r33128 knownitems = ui._knownconfig.setdefault(section, {})
knownkeys = set(knownitems)
newkeys = set(items)
for key in sorted(knownkeys & newkeys):
msg = "extension '%s' overwrite config item '%s.%s'"
msg %= (extname, section, key)
ui.develwarn(msg, config='warn-config')
knownitems.update(items)
configitems: add an official API for extensions to register config item...
r33127
configitems: add a basic class to hold config item information...
r32983 class configitem(object):
"""represent a known config item
:section: the official config section where to find this item,
:name: the official name within the section,
:default: default value for this item,
"""
def __init__(self, section, name, default=None):
self.section = section
self.name = name
self.default = default
configitems: introduce a central registry for config option...
r32984
coreitems = {}
configitems: extract the logic to build a registrar on any configtable...
r33126 def _register(configtable, *args, **kwargs):
configitems: introduce a central registry for config option...
r32984 item = configitem(*args, **kwargs)
configitems: extract the logic to build a registrar on any configtable...
r33126 section = configtable.setdefault(item.section, {})
configitems: introduce a central registry for config option...
r32984 if item.name in section:
msg = "duplicated config item registration for '%s.%s'"
raise error.ProgrammingError(msg % (item.section, item.name))
section[item.name] = item
configitems: register 'ui.quiet' as first example...
r32986
# Registering actual config items
configitems: extract the logic to build a registrar on any configtable...
r33126 def getitemregister(configtable):
return functools.partial(_register, configtable)
coreconfigitem = getitemregister(coreitems)
configitems: register 'patch.fuzz' as first example for 'configint'...
r32988 coreconfigitem('patch', 'fuzz',
default=2,
)
configitems: register 'ui.clonebundleprefers' as example for 'configlist'...
r32989 coreconfigitem('ui', 'clonebundleprefers',
default=[],
)
configitems: register 'ui.interactive'...
r33061 coreconfigitem('ui', 'interactive',
default=None,
)
configitems: register 'ui.quiet' as first example...
r32986 coreconfigitem('ui', 'quiet',
default=False,
)