Configuring Bazaar ================== .. contents:: :depth: 2 The short story --------------- As a Bazaar developer there are three things you need to know about configuration. 1. Get a value. You construct or get a reference to a ConfigStack subclass that's relevant to the context where you want to look up a value. For instance, given a branch:: print branch.get_config_stack().get('log_format') This will look up the stack through all relevant configuration sources. The value returned is of the type declared for that Option and if nothing is specifically declared you will get the default for that option. 2. Add a new option. You add a new ``Option`` to the ``option_registry``, either inside ``bzrlib/config.py`` or during initialization of your plugin. New plugins should have systematic hierarchical names so that related values are grouped together:: option_registry.register( Option('dirstate.fdatasync', default=True, from_unicode=bool_from_store, help="Flush dirstate changes onto physical disk? ....")) 3. Old and new configuration code. There is (as of late 2011) some older and some newer configuration code. The old code has specific methods for various checks or uses classes like ``GlobalConfig``. Don't add to to it; try to remove it. Option ------ The Option object is used to define its properties: * name: a name: a valid python identifier (even if it's not used as an identifier in python itself). This is also used to register the option. * from_unicode: a callable accepting a unicode string and returning a suitable value for the option. If the string cannot be coerced it should return None. * default: the default value that Stack.get() should return if no value can be found for the option. * default_from_env: a list of environment variables. The first variable set will provide a default value overriding 'default' which remains the default value if *no* environment variable is set. * help: a doc string describing the option, the first line should be a summary and can be followed by a blank line and a more detailed explanation. This will be displayed to the user with:: bzr help