使用名称空间构造Fabric项目 [英] Structuring a fabric project with namespaces

查看:73
本文介绍了使用名称空间构造Fabric项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在越来越频繁地使用面料,我喜欢它.到目前为止,我的结构脚本往往相对较短且是临时的.它完成了工作,一切都很好.与现有的更精致的工具相比,这就是我喜欢的东西.

I use fabric more and more frequently now, and I love it. So far, my fabric scripts tend to be relatively short and ad-hoc. It gets the job done and it's fine. That's what I like about it compared to more elaborate tools out there.

我现在正尝试将脚本集合在一起,并希望使它们更易于访问和使用. 命名空间似乎很可行,而且看起来很简单优雅.

I am now trying to bunch together a collection of scripts and want to make them more accessible and easy to use. Namespaces seems like the way to go and it looks simple and elegant.

当前,对我来说,难题中缺少的部分是在何处放置各种结构任务需要(有些可能会共享)的各种模板和配置文件,以及如何共享功能或子模块之间的任务.

Currently, the missing piece of the puzzle for me is where to place various templates and configuration files that different fabric tasks need (and some might share), and also how to share functions or tasks between submodules.

我是否需要设置一些PYTHONPATH或修改系统路径以使所有子模块都可以访问这些路径?是否有推荐的结构(或最佳实践指南)来构建此类Fabric项目?

Do I need to set up some PYTHONPATH or modify the system's path to make those accessible from all submodules? Is there a recommended structure (or a best-practice guide) for building such fabric project?

推荐答案

我通常使用常规的python导入来完成此操作.

I mostly use regular python imports to accomplish this.

例如,如果您的目录结构是这样:

For example, if your directory structure is this:

mytoplevel/
├── __init__.py
├── mydeploymenttasks.py
└── templates
    ├── __init__.py
    └── mytemplate.mak

您的模板可以通过以下方式获取:

Your template can be obtained using something like this:

import pkg_resources
pkg_resources.resource_filename('mytoplevel.templates',mytemplate.mak)

但是由于任务存在于常规的python模块中,因此您可以简单地使用包的结构将其导入:

But since tasks live in regular python modules, you can simply import them using your package's structure:

from mytoplevel.mydeploymenttasks import installApplicationTask

关于如何构造程序包,这取决于其域.如果您发现代码中增加了某个主题,请将其分解为自己的模块.

As to how you would structure your package, this depends on its domain. If you find a certain topic grows in your code, break it off into it's own module.

这篇关于使用名称空间构造Fabric项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆