Structuring a fabric project with namespaces

I use fabric more and more, and I like it. So far, my scripts on fabric have been relatively short and ad-hoc. He is doing his job, and everything is in order. This is what I like about this, compared to more complex tools.

Now I am trying to build a set of scripts and want to make them more accessible and easier to use. Namespaces seems the way it is and looks simple and elegant.

Currently, the missing part of the puzzle for me is the place where you can place various templates and configuration files that require different trianging tasks (and some can share), as well as how to share functions or tasks between submodules.

Do I need to configure some PYTHONPATH or change the system path to make them accessible from all submodules? Is there a recommended structure (or best practice guide) for creating such a fabric project?

+1
source share
1 answer

I mainly use regular python imports to accomplish this.

For example, if your directory structure is as follows:

 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) 

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

 from mytoplevel.mydeploymenttasks import installApplicationTask 

As for the structure of your package, it depends on its domain. If you find that a particular topic is growing in your code, disable it in your own module.

+1
source

Source: https://habr.com/ru/post/1415146/


All Articles