python - 是否有 Python 的 Cake 等价物?

标签 python makefile build-automation

我搜索了很多“为 Python 制作”的项目,但我找不到一个简单的 cake file 项目。 .我正在寻找的是一个 Python 等价物,它可以让我:

  1. 将构建命令保存在我的项目根目录中的单个文件中
  2. 将每个任务定义为一个简单的函数,并在不带参数运行“make”文件时自动显示描述
  3. 导入我的 Python 模块

我正在想象这样的事情:

from pymake import task, main

@task('reset_tables', 'Drop and recreate all MySQL tables')
def reset_tables():
    # ...

@task('build_stylus', 'Build the stylus files to public/css/*')
def build_stylus():
    from myproject import stylus_builder
    # ...

@task('build_cscript', 'Build the coffee-script files to public/js/*')
def build_cscript():
    # ...

@task('build', 'Build everything buildable')
def build():
    build_cscript()
    build_stylus()

# etc...

# Function that parses command line args etc...
main()

我找了又找,但没有找到类似的东西。如果它不存在,我会自己制作它并可能用它来回答这个问题。

感谢您的帮助!

最佳答案

自己构建一个简单的解决方案并不难:

import sys

tasks = {}
def task (f):
    tasks[f.__name__] = f
    return f

def showHelp ():
    print('Available tasks:')
    for name, task in tasks.items():
        print('  {0}: {1}'.format(name, task.__doc__))

def main ():
    if len(sys.argv) < 2 or sys.argv[1] not in tasks:
        showHelp()
        return

    print('Executing task {0}.'.format(sys.argv[1]))
    tasks[sys.argv[1]]()

然后是一个小样本:

from pymake import task, main

@task
def print_foo():
    '''Prints foo'''
    print('foo')

@task
def print_hello_world():
    '''Prints hello world'''
    print('Hello World!')

@task
def print_both():
    '''Prints both'''
    print_foo()
    print_hello_world()

if __name__ == '__main__':
    main()

以及使用时的样子:

> .\test.py
Available tasks:
  print_hello_world: Prints hello world
  print_foo: Prints foo
  print_both: Prints both
> .\test.py print_hello_world
Executing task print_hello_world.
Hello World!

关于python - 是否有 Python 的 Cake 等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11538343/

相关文章:

Firebase throw "the server responded with status 400"

python - U-SQL + Python 基础题

makefile - 动态生成 Makefile 规则

linux - 在 Makefile 中动态获取 C 文件

android - Jenkins 和运行 AndroidJUnitRunner 仪器测试

build-process - hudson 通知人?

python - 通过 event_generate 传递附加参数?

python - 过滤 pyspark DataFrame,其中行位于另一个 DataFrame 的范围内

python - 我无法显示文件上传按钮

variables - Makefile 'match' 特殊变量的名称是什么?