From 1b5b7abfdd2d44fd7c9bd1007a96afa14cd29dd8 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 13 Nov 2012 00:44:07 +0100 Subject: [PATCH] Allow settings prefixed with 'CUSTOM_' (fixes #204) --- docs/changes.rst | 3 +++ docs/settings.rst | 15 +++++++++++++++ mopidy/utils/settings.py | 3 +-- tests/utils/settings_test.py | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 670921d9..81a27d33 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -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 diff --git a/docs/settings.rst b/docs/settings.rst index 0449b458..cb47a71f 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -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 ================== diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 105a94e3..fee5252d 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -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) diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py index 0362dee3..0ecbb90f 100644 --- a/tests/utils/settings_test.py +++ b/tests/utils/settings_test.py @@ -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'})