Structuring a fabric project with namespaces
Question: 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](http://docs.fabfile.org/en/1.4.1/usage/tasks.html#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.

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?


Answer: 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)
    

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.

