S.D.
S.D.

Reputation: 2951

Fabric 2 using global settings

In Fabric1 there was the ability to put a bunch of settings in the fabfile.py and import the actually tasks from another package. This is wanted as I'm using these tasks for a multiple projects.

Like so:

from fabric.api import env

env.django_dir = '/home/someuser/django_app'
env.git_repo = 'some url'

Then any fabric code could access the variables like so:

from fabric.api import env

def clone():
    with cd('$HOME'):
        run('git clone {repo} {django_dir}'.format(
            repo=env.git_repo, django_dir=env.django_dir))

It seems however that from fabric2 there is no longer such a thing as this env.
How can I get my tasks from another package to use the configuration settings in fabfile.py?

Upvotes: 0

Views: 612

Answers (1)

S.D.
S.D.

Reputation: 2951

After some more digging in the documentation, I came across: a configuration page referencing to Invoke.

It turns out that all one needs to do is create a new file, next to fabfile.py called fabric.py.

Declare your variables in fabric.py.

django_dir = 'django_app'
git_repo = 'some url'

In the tasks you can access this information by talking to c.config

def clone(c):
    # with isn't implemented yet, chain with &&
    c.run('cd $HOME && git clone {} {}'.format(
        c.config.git_repo, c.config.django_dir))

Upvotes: 0

Related Questions