gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:52:30 24 4
gpt4 key购买 nike

我搜索了很多“为 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.pyAvailable tasks:  print_hello_world: Prints hello world  print_foo: Prints foo  print_both: Prints both> .\test.py print_hello_worldExecuting task print_hello_world.Hello World!

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com