【问题标题】:How do I configure pybuilder?如何配置 pybuilder?
【发布时间】:2014-03-23 14:27:22
【问题描述】:

如何更改pybuilder中的配置,pybuilder中的配置如何工作?

如何找出可能的配置值及其默认值,如何在每个项目/每个模块/命令行/设置文件中覆盖或更改它们?哪些是设置文件?

【问题讨论】:

    标签: python pybuilder


    【解决方案1】:

    1) 定位初始化方法

    更改现有项目的配置非常容易。访问项目根目录下的build.py 文件,确保其中包含以下代码:

    from pybuilder.core import init
    

    还有这个(不带点):

    @init
    def initialize(project):
      ... 
    

    2) 属性示例

    插件使用他们所谓的properties 进行配置。此处提供了可用插件属性及其默认值的列表:http://pybuilder.github.io/documentation/plugins.html 如果您未配置某些内容,则将使用默认值。

    还有一个python核心插件,可以更改默认目录

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

    这个例子展示了如何改变插件的属性:

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

    这会将unittest 插件的属性unittest_module_glob 设置为值“*_unittest”。

    3) 属性示例

    attributes描述整个项目。例如,要更改项目的版本属性,请在 initialize 方法中使用类似这样的一行:

    project.version = "0.1.14"
    

    4) 完整示例

    您的 .\build.py 现在可能看起来像这样:

    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) 从命令行设置属性

    也可以使用命令行开关设置或覆盖属性:

    $ pyb -P unittest_module_glob="*_unittest"
    

    6) 延伸阅读

    所有这些都在设置页面上进行了解释:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多