0

My fabfile contains relative imports, thus it has to be loaded as a module.

It seems that fab loads the fabfile as standalone script, so the relative imports are not working.

Here is my folder structure:

scripts
 |-> __init__.py 
 |-> deployment
      |-> __init__.py
      |-> fabfile.py
 |-> other-module

To debug/test the fabfile I can load it using:

python -m scripts.deployment.fabfile

Is there a way to force the fab tool to load the fabfile as module?

hoonzis
  • 1,717
  • 1
  • 17
  • 32

1 Answers1

0

In order to make that happen, you need to add a scripts/deployment/__main__.py.

scripts
 |-> __init__.py 
 |-> deployment
      |-> __init__.py
      |-> __main__.py
      |-> fabfile.py
 |-> other-module

Supposing there's an entrypoint function inside your scripts/deployment/fabfile.py called my_fabric_entry, you can call it from scripts/deployment/__main__.py and it will do the trick.

$ cat scripts/deployment/__main__.py
from __future__ import print_function
from .fabfile import my_fabric_entry

print('About to call fabfile.my_fabric_entry()')
my_fabric_entry()

$ python -m scripts.deployment
About to call fabfile.my_fabric_entry()

Check this answer for more info https://stackoverflow.com/a/36320295/977593

slackmart
  • 4,754
  • 3
  • 25
  • 39