Rev 6397: Add Option.override_from_env allowing environ variables to override config settings in file:///home/vila/src/bzr/bugs/907279-override-from-env/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Dec 22 18:37:21 UTC 2011
At file:///home/vila/src/bzr/bugs/907279-override-from-env/
------------------------------------------------------------
revno: 6397
revision-id: v.ladeuil+lp at free.fr-20111222183721-teilsa3jwgar3qry
parent: v.ladeuil+lp at free.fr-20111222094254-py0cic7d024momaz
fixes bug: https://launchpad.net/bugs/907279
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 907279-override-from-env
timestamp: Thu 2011-12-22 19:37:21 +0100
message:
Add Option.override_from_env allowing environ variables to override config settings
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-12-22 09:42:54 +0000
+++ b/bzrlib/config.py 2011-12-22 18:37:21 +0000
@@ -1652,17 +1652,6 @@
raise errors.NoWhoami()
-def email_from_store(unicode_str):
- """Unlike other env vars, BZR_EMAIL takes precedence over config settings.
-
- Whatever comes from a config file is then overridden.
- """
- value = os.environ.get('BZR_EMAIL')
- if value:
- return value.decode(osutils.get_user_encoding())
- return unicode_str
-
-
def _auto_user_id():
"""Calculate automatic user identification.
@@ -2715,8 +2704,7 @@
Option('editor',
help='The command called to launch an editor to enter a message.'))
option_registry.register(
- Option('email', default=default_email,
- from_unicode=email_from_store,
+ Option('email', override_from_env=['BZR_EMAIL'], default=default_email,
help='The users identity'))
option_registry.register(
Option('gpg_signing_command',
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-12-22 09:42:54 +0000
+++ b/bzrlib/tests/test_config.py 2011-12-22 18:37:21 +0000
@@ -4618,22 +4618,26 @@
class EmailOptionTests(tests.TestCase):
+ def setUp(self):
+ super(EmailOptionTests, self).setUp()
+
def test_default_email_uses_BZR_EMAIL(self):
+ conf = config.MemoryStack('email=jelmer at debian.org')
# BZR_EMAIL takes precedence over EMAIL
self.overrideEnv('BZR_EMAIL', 'jelmer at samba.org')
self.overrideEnv('EMAIL', 'jelmer at apache.org')
- self.assertEquals('jelmer at samba.org', config.default_email())
+ self.assertEquals('jelmer at samba.org', conf.get('email'))
def test_default_email_uses_EMAIL(self):
+ conf = config.MemoryStack('')
self.overrideEnv('BZR_EMAIL', None)
self.overrideEnv('EMAIL', 'jelmer at apache.org')
- self.assertEquals('jelmer at apache.org', config.default_email())
+ self.assertEquals('jelmer at apache.org', conf.get('email'))
def test_BZR_EMAIL_overrides(self):
+ conf = config.MemoryStack('email=jelmer at debian.org')
self.overrideEnv('BZR_EMAIL', 'jelmer at apache.org')
- self.assertEquals('jelmer at apache.org',
- config.email_from_store('jelmer at debian.org'))
+ self.assertEquals('jelmer at apache.org', conf.get('email'))
self.overrideEnv('BZR_EMAIL', None)
self.overrideEnv('EMAIL', 'jelmer at samba.org')
- self.assertEquals('jelmer at debian.org',
- config.email_from_store('jelmer at debian.org'))
+ self.assertEquals('jelmer at debian.org', conf.get('email'))
=== modified file 'doc/developers/configuration.txt'
--- a/doc/developers/configuration.txt 2011-12-21 20:32:50 +0000
+++ b/doc/developers/configuration.txt 2011-12-22 18:37:21 +0000
@@ -186,6 +186,10 @@
suitable value for the option. If the string cannot be coerced it should
return None.
+* override_from_env: a list of environment variables. The first variable set
+ will be used as the option value overriding any other definition of the
+ option.
+
* default: the default value that Stack.get() should return if no value can
be found for the option. This can also be a callable as long as it returns
a unicode string.
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-12-21 21:31:03 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-12-22 18:37:21 +0000
@@ -28,6 +28,10 @@
parent directories.
(Jared Hance, Jelmer Vernooij, #253529)
+* ``config.Option`` can now declare ``override_from_env``, a list of
+ environment variables which, when set, that takes precedence over values
+ defined in configuration files. (Vincent Ladeuil, #907279)
+
Improvements
************
More information about the bazaar-commits
mailing list