Allow settings prefixed with 'CUSTOM_' (fixes #204)
This commit is contained in:
parent
6acaa490e9
commit
1b5b7abfdd
@ -96,6 +96,9 @@ backends:
|
||||
- Make the entire code base use unicode strings by default, and only fall back
|
||||
to bytestrings where it is required. Another step closer to Python 3.
|
||||
|
||||
- The settings validator will now allow any setting prefixed with ``CUSTOM_``
|
||||
to exist in the settings file.
|
||||
|
||||
**Bug fixes**
|
||||
|
||||
- :issue:`218`: The MPD commands ``listplaylist`` and ``listplaylistinfo`` now
|
||||
|
||||
@ -200,6 +200,21 @@ can use with the ``gst-launch-0.10`` command can be plugged into
|
||||
:attr:`mopidy.settings.OUTPUT`.
|
||||
|
||||
|
||||
Custom settings
|
||||
===============
|
||||
|
||||
Mopidy's settings validator will stop you from defining any settings in your
|
||||
settings file that Mopidy doesn't know about. This may sound obnoxious, but it
|
||||
helps you detect typos in your settings, and deprecated settings that should be
|
||||
removed or updated.
|
||||
|
||||
If you're extending Mopidy in some way, and want to use Mopidy's settings
|
||||
system, you can prefix your settings with ``CUSTOM_`` to get around the
|
||||
settings validator. We recommend that you choose names like
|
||||
``CUSTOM_MYAPP_MYSETTING`` so that multiple custom extensions to Mopidy can be
|
||||
used at the same time without any danger of naming collisions.
|
||||
|
||||
|
||||
Available settings
|
||||
==================
|
||||
|
||||
|
||||
@ -121,7 +121,6 @@ def validate_settings(defaults, settings):
|
||||
errors = {}
|
||||
|
||||
changed = {
|
||||
'CUSTOM_OUTPUT': 'OUTPUT',
|
||||
'DUMP_LOG_FILENAME': 'DEBUG_LOG_FILENAME',
|
||||
'DUMP_LOG_FORMAT': 'DEBUG_LOG_FORMAT',
|
||||
'FRONTEND': 'FRONTENDS',
|
||||
@ -176,7 +175,7 @@ def validate_settings(defaults, settings):
|
||||
if not value:
|
||||
errors[setting] = 'Must contain at least one value.'
|
||||
|
||||
elif setting not in defaults:
|
||||
elif setting not in defaults and not setting.startswith('CUSTOM_'):
|
||||
errors[setting] = 'Unknown setting.'
|
||||
suggestion = did_you_mean(setting, defaults)
|
||||
|
||||
|
||||
@ -29,6 +29,11 @@ class ValidateSettingsTest(unittest.TestCase):
|
||||
result['MPD_SERVER_HOSTNMAE'],
|
||||
'Unknown setting. Did you mean MPD_SERVER_HOSTNAME?')
|
||||
|
||||
def test_custom_settings_does_not_return_errors(self):
|
||||
result = setting_utils.validate_settings(
|
||||
self.defaults, {'CUSTOM_MYAPP_SETTING': 'foobar'})
|
||||
self.assertNotIn('CUSTOM_MYAPP_SETTING', result)
|
||||
|
||||
def test_not_renamed_setting_returns_error(self):
|
||||
result = setting_utils.validate_settings(
|
||||
self.defaults, {'SERVER_HOSTNAME': '127.0.0.1'})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user