生成用于管理Web资源的实用程序。
pybuildtool的Python项目详细描述
pybuildtool
- 许可证:麻省理工学院
- 项目URL:http://github.com/dozymoe/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_out
、raw_file_out
和extra_out
的组合。你可以像这样使用
ant glob
**/*.js
您可以使用目录作为输出,它们必须以路径分隔符结尾,因为 示例:“minified_js/”
大多数组的子组都是特殊的,它们必须匹配工具名,如“jshint”, “concat”、“pylint”、“uglifyjs”等
规则按其编写顺序读取,您可以引用其他规则 生成的输出文件作为输入文件,但这些规则必须 之前指定的。 我们还不支持延迟加载规则。
指令
raw_file_in
或raw_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
。
安装
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_dev
或waf 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