生成用于管理Web资源的实用程序。

pybuildtool的Python项目详细描述


pybuildtool

摘要

pybuildtool有助于转换资源并在编写代码时运行自动化测试,我 通常让它在使用vim进行编辑时查看项目文件。

pybuildtool是用python编写的,它是一个高级接口,可以连接到一个元构建系统Waf <http://waf.io>

要与之交互的配置文件:build.yml,是声明性的, 用山药写的。而您也可以编写的构建工具是为了 简单一点,遵循一种模式。

配置文件不需要命名为“build.yml”,只需更改 文件wscript(这是waf需要的)。你需要创造 wscript按照下面的示例自行归档: http://raw.githubusercontent.com/dozymoe/PyBuildTool/master/pybuildtool/wscript.example

有一些内置工具,您可以将它们作为示例来构建自己的构建 工具,请看这里:http://github.com/dozymoe/PyBuildTool/tree/master/pybuildtool/tools。 查看它们是如何由wscript文件导入的。

因为您控制了wscript文件,所以您控制了 构建过程。

如果你想比编辑更深入,你可以阅读 introduction to waf and wscript <http://waf.io/apidocs/tutorial.html>,或 更专业的waf project structure <http://waf.io/book/#_basic_project_structure>

有三个预定义的阶段:“dev”、“stage”和“prod”(请参见 wscript文件),但是功能还没有,它们有单独的 它们自己的临时生成目录,但它们仍然共享同一个生成 规则。

当前的阶段是这样实现的:对于clean-css工具,如果 当前阶段是“dev”或“devel”或“development”的一个阶段,它将复制 操作而不是css文件缩小。

这是build.yml的一个例子,假设它是一个django项目:

。代码::yaml

# Macro, reusable definition, defined once - used plenty.
# The word started with ampersand (&) is called yaml node anchor.
# The anchor is what matters, it's a yaml feature.
#
# Group name in all uppercase will be ignored.
#
# {_1} is a replacement pattern for parent group's name at level 1.
# It is being used to easily reproduce the directory structure.
JSHINT_EXCLUDES: &JSHINT_EXCLUDES
    - "{_1}/{_2}/js/jquery.js"
    - "{_1}/{_2}/js/require.js"
    - "{_1}/{_2}/js/underscore.js"


# Build group at level 1.
djangoprj:
    # This is special, not a group.
    options:
        # Lower level tool configurations can be defined at higher level.
        #
        # `config_file` of the tool `jshint`
        jshint_config_file: "etc/jshint.rc"
        # `config_file` of the tool `pylint`
        pylint_config_file: "etc/pylint.rc"

    # Build group at level 2
    blogapp:
        # The lowest level group is the tool being used, if no such tool
        # was found a fatal error will be raised.
        jshint:
            # Wildcards is a okay, see ant-glob.
            file_in: "{_1}/{_2}/js/**/*.js"
        concat:
            # `raw_file_in` will be monitored for changes by `waf watch`
            raw_file_in: "{_1}/{_2}/js/**/*.js"
            # `{_1}:{_2}` will be replaced with the groups' names, in this
            # case it will be read as `djangoprj/blogapp/jshint`
            rule_in: "{_1}/{_2}/jshint"
            # Relative files are relative to the directory where you
            # run `waf configure`
            file_out: "js/blogapp.js"

    # Build group at level 2
    djangoprj:
        # Test javascript files syntax for errors
        jshint:
            options:
                # Example of macro usage, see yaml node anchor.
                # `_source_excluded_` is a special directive, excludes some
                # files listed in `file_in` (could be from wildcards) from
                # being processed.
                _source_excluded_: *JSHINT_EXCLUDES
            file_in: "{_1}/{_2}/js/**/*.js"
        # Test javascript files syntax for errors
        jscs:
            options:
                _source_excluded_: *JSHINT_EXCLUDES
                # This one is defined here, not in higher level group
                config_file: "etc/jscs.rc"
            file_in: "{_1}/{_2}/js/**/*.js"
        # Test python files syntax for errors
        pylint:
            raw_file_in: "{_1}/{_2}/**/*.py"
        # Concacenate javascript files into one file for production site
        concat:
            rule_in:
                # Can has multiple items
                -   "djangoprj/djangoprj/jshint"
                -   "{_1}/{_2}/jscs"
            # The `@` symbol means to use the files produced by other tools
            file_in: "@{_1}/blogapp/concat"
            raw_file_in: "{_1}/{_2}/js/**/*.js"
            file_out: "js/djangoprj.js"
        # Copy final javascript file to production directory
        cp:
            file_in: "@{_1}/{_2}/concat"
            # Files usually produced in sandbox directories, `raw_file_out`
            # directive made it produced in the real project directory
            raw_file_out: "dist/"
        # Copy compressed final javascript file to production
        # directory
        uglifyjs:
            file_in: "@{_1}/{_2}/concat"
            # Directory as target is a okay, directory must ends with `/`.
            raw_file_out: "dist/"

要记住以下几点:

  • “djangoprj”、“blogapp”、“jshint”、“concat”是组名。

  • jshint_excludes不是组名(它匹配所有大写字母和 下划线),pybuildtool将无法识别此条目,但是yaml.load 威尔。 它可以用作yaml node anchor

  • {_1}是基于组名级别的字符串替换项。

  • 因为组名可以用作文件的字符串替换 名称,它们可以用来表示目录结构。

  • “@djangoprj/djangoprj/jshint”是对文件的引用 由规则“djangoprj”-“djangoprj”-“jshint”生成,即, 它的file_outraw_file_outextra_out的组合。

  • 你可以像这样使用ant glob**/*.js

  • 您可以使用目录作为输出,它们必须以路径分隔符结尾,因为 示例:“minified_js/”

  • 大多数组的子组都是特殊的,它们必须匹配工具名,如“jshint”, “concat”、“pylint”、“uglifyjs”等

  • 规则按其编写顺序读取,您可以引用其他规则 生成的输出文件作为输入文件,但这些规则必须 之前指定的。 我们还不支持延迟加载规则。

  • 指令raw_file_inraw_depend_in用于waf watch 要获取需要监视的文件列表。

  • 指令depend_in可用于强制工具处理 file_in如果depend_in中的文件更改。

  • 指令^ {< CD18>}可用于列出由 该工具可以与@group:group指令组合使用 其他工具的输入。

  • 选项字段:_source_excluded_是将 从输入中排除。

  • 指令raw_file_out表示此规则的输出将是 写在实际的文件系统中,默认情况下它是在 '.build/stage/'目录。

  • 选项字段:config_file是每个 工具,在本例中是由“pylint”、“jshint”和“jscs”提供的,并且 他们碰巧用了同一个名字。 当选项字段放在较高的组级别时,它是prefixeD和 工具名,例如:“jscs配置文件”

警告

^ {CD32 >}如果源和目标存在于同一目录中,则不喜欢。 见:Files are always built

如果使用rule_in,可能需要多次运行waf build,直到出现 当系统第一次用waf configure初始化时,没有要构建的内容。 或者通过waf clean

安装

  1. pip install pybuildtool

#是的。安装waf作为可执行二进制文件,从Waf project <http://waf.io>下载。

 You could also ``pip install waftools`` and then run ``wafinstall``,
 caution: this method will modify your ``~/.bashrc`` adding ``WAFDIR=???``.

#是的。复制并修改项目根目录中的wscript,指定 建立你将要使用的工具。

#是的。使用我们的示例这样的内容创建build.yml,这将是 你的构建规则。

#是的。waf configure

#是的。waf build_devwaf watch_dev

。_蚂蚁球:http://ant.apache.org/manual/dirtasks.html ……_ yaml节点锚:http://yaml.org/spec/1.2/spec.html#id2785586 ……_文件总是生成的:https://code.google.com/p/waf/wiki/FAQ#The_same_files_are_always_built

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java例外。Lang.Stringindexoutofboundsexception索引超出范围(0)   java Spring引导Freemarker从2.2.0升级失败   重构Java反模式名称?包含对象的对象包含。。。等   用java处理JDBC可能出现的死锁的最佳方法   java无法访问主线程上的数据库,因为它可能会在很长一段时间内锁定UI   java如何将固定大小的画布包装在边框窗格中的滚动窗格居中?   java解析xsd文件后得到空结果   在html页面中表示XML文件的java   socketjava对象流   sql Java越界异常数据库   JavaJBoss7.1.1不会在Mavericks上启动   Twincat ADS事件驱动读取在一段时间后停止工作(Java)   java MyBatis使用生成的ID插入所有   Mojave上缺少MacOS Java控制面板   JavaGuice:如果多次注入相同的依赖项,是否注入了该依赖项的相同实例?