Hi Alec,

the examples given doesn’t work. Maybe you’re missing something.

env should be imported from fabric.api, if not, Python fails with NameError:
name 'env' is not defined

Also, the Python path should include foo/and can/, so you need to call a
python executable from the project root (Or add ROOT_DIRECTORY to the
python path with sys.path.append(ROOT_DIRECTORY)). For example:

## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes

domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]

execute(funtimes)

And you execute it with: python foo/__init__.py. And this works.


Regards

2016-01-27 6:21 GMT+01:00 Alec Taylor <[email protected]>:

Using Fabric outside a fabfile. `fabric.api.execute` on relative imported
> functions works.
>
> Importing other installed modules fails with "No hosts found. Please
> specify (single) host string for connection:"
>
> To illustrate, this works:
>
> ## foo/__init__.py
>
> from fabric.api import execute
> from bar import funtimes
>
> domain = 'localhost'
> env.user = 'bar'
> env.password = 'foo'
> env.hosts = [domain]
>
> execute(funtimes)
>
> ## foo/bar.py
>
> from fabric.api import run
>
> def funtimes(): run('hello funtimes')
>
> Whilst this fails:
>
> ## foo/__init__.py
>
> from fabric.api import execute
> from can.haz import funtimes
>
> domain = 'localhost'
> env.user = 'bar'
> env.password = 'foo'
> env.hosts = [domain]
>
> execute(funtimes)
>
> ## can/haz.py
>
> from fabric.api import run
>
> def funtimes(): run('hello funtimes')
>
> # also tried
> def funtimes2(env):
>     fabric.api.env = env
>     run('hello funtimes2')
>
>
> _______________________________________________
> Fab-user mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/fab-user
>
> ​
--
_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to