您如何控制自定义 Fabric 命令的公开方式?
我将我的命令组织在各种包中,例如:
mydomain
__init__.py
db.py
@task
def create()...
@task()
def dump()...
@task
def shell()...
当我运行 fab --list
时,我看到 Fabric 公开了以 mydomain
为前缀的命令:
mydomain.db.create
mydomain.db.dump
mydomain.db.shell
如何让 Fabric 删除 mydomain
前缀,同时仍将任务组织在我的自定义命名空间中?我试过在 @task(name=...)
中指定名称,但这对命名空间没有影响。
最佳答案
我有以下结构,它没有以包名称为前缀。
fab --version
Fabric 1.8.0
Paramiko 1.12.0
rootdir/
fabfile.py
mydomain/
__init__.py
db.py
other.py
fab文件.py
from fabric.api import task
from mydomain import db, other
@task
def boom():
print "boom"
数据库.py
from fabric.api import task
@task
def create():
print "create"
@task()
def dump():
print "dump"
其他.py
from fabric.api import task
@task
def do_stuff():
print "doing stuff"
fab --list 输出
fab --list
Available commands:
boom
db.create
db.dump
other.do_stuff
我注意到如果我导入
import mydomain.db
import mydomain.other
那么输出是:
fab --list
Available commands:
boom
mydomain.db.create
mydomain.db.dump
mydomain.other.do_stuff
所以看看你是如何导入你的包的,这似乎是导致它的原因
关于python - 如何重命名命名空间结构命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16740893/