Search code examples
pythonpybuilder

How do I configure pybuilder?


How can I change the configuration in pybuilder, and how does the configuration in pybuilder work?.

How Do I find out the possible configuration values and their defaults, how do I override or change them per project / per module / on the commmmandline / in settings files? Which are the settings files?


Solution

  • 1) Locate the initialization method

    It is very easy to change the configuration of an exisiting project. Visit the build.py file in the root directory of your project and make sure it has this code in it:

    from pybuilder.core import init
    

    and also this (without the dots):

    @init
    def initialize(project):
      ... 
    

    2) Properties example

    Plugins are configured using their so called properties. There is a list of available plugin properties and their default values available here: http://pybuilder.github.io/documentation/plugins.html If you do not configure something the default value will be used.

    There is also a python core plugin, where you can change default directories:

    http://pybuilder.github.io/documentation/plugins.html#Pythondeployment

    This example shows how to change a property of a plugin:

    project.set_property('unittest_module_glob', '*_unittest')
    

    This will set the property unittest_module_glob of the unittest plugin to the value '*_unittest'.

    3) Attribute example

    There are attributes to describe the whole project. For instance to change the version attribute of the project use a line like this one in the initialize method:

    project.version = "0.1.14"
    

    4) Complete example

    Your .\build.py could look like this now:

    from pybuilder.core import use_plugin
    from pybuilder.core import init
    
    use_plugin("python.core")
    use_plugin("python.unittest")
    
    name = "myfirstproject"
    default_task = "publish"
    
    @init
    def initialize(project):
      project.version = "0.1.14"
      project.set_property('unittest_module_glob', '*_unittest')
    

    5) Setting Properties from the command line

    Properties can also be set or overridden using command line switches:

    $ pyb -P unittest_module_glob="*_unittest"
    

    6) Further reading

    Much of all this is explained on the settings page:

    http://pybuilder.github.io/documentation/manual.html#Project-specificconfiguration