how to debug python fabric using pycharm
Question:
There are some posts on SO and tell me to use fab-script.py as startup script for pycharm. It’s exactly what I used before. Now when I upgrade fabric to latest version, fab-script disappeared, and only fab.exe left there. I tried a lot of other ways, but still failed to launch debugger in pycharm.
Answers:
I haven’t used this setup on Windows, but on Linux/Mac, it’s fairly straightforward:
- Create a new Run Configuration in PyCharm for a Python script (when you click the “+” button, select the one labelled “Python”)
- The “Configuration” tab should be open.
- For the “Script” field, enter the full path to
fab.exe
, like C:Python27.....fab.exe
or whatever it is.
- For Script parameters, just try
-l
, to list the available commands. You’ll tweak this later, and fill it in with whatever tasks you’d run from the command line, like “fab etc…“
- For the “Working directory” field, you’ll want to set that to the directory that contains your fabfile.
And it’s about as easy as that, at least on *nix. Sorry that I don’t have a Windows setup, but do let us know if you do have any issues with the setup described above.
The final solution is to add line below at fabfile.py:
import fabric.main
if __name__ == '__main__':
fabric.main.main()
then you can debug the fabfile.py as a normal python script in pycharm.
For Fabric 2 users this should work (tested on Fabric 2.6.0
):
import fabric.main
if __name__ == '__main__':
fabric.main.program.run()
How to run/debug Fabric (Fab) command in Pycharm
- run
which fab
from your virtualenv and take the output path
- create new
run/debug configuration
with type = python
script
-
configure it
- script path =
output
from p.1
- parameters = *
- working directory =
Example
- script path: /home/xxx/.virtualenvs/some/bin/fab
- parameters: local-restore-db –dump argument
There are some posts on SO and tell me to use fab-script.py as startup script for pycharm. It’s exactly what I used before. Now when I upgrade fabric to latest version, fab-script disappeared, and only fab.exe left there. I tried a lot of other ways, but still failed to launch debugger in pycharm.
I haven’t used this setup on Windows, but on Linux/Mac, it’s fairly straightforward:
- Create a new Run Configuration in PyCharm for a Python script (when you click the “+” button, select the one labelled “Python”)
- The “Configuration” tab should be open.
- For the “Script” field, enter the full path to
fab.exe
, likeC:Python27.....fab.exe
or whatever it is. - For Script parameters, just try
-l
, to list the available commands. You’ll tweak this later, and fill it in with whatever tasks you’d run from the command line, like “fab etc…“ - For the “Working directory” field, you’ll want to set that to the directory that contains your fabfile.
And it’s about as easy as that, at least on *nix. Sorry that I don’t have a Windows setup, but do let us know if you do have any issues with the setup described above.
The final solution is to add line below at fabfile.py:
import fabric.main
if __name__ == '__main__':
fabric.main.main()
then you can debug the fabfile.py as a normal python script in pycharm.
For Fabric 2 users this should work (tested on Fabric 2.6.0
):
import fabric.main
if __name__ == '__main__':
fabric.main.program.run()
How to run/debug Fabric (Fab) command in Pycharm
- run
which fab
from your virtualenv and take the output path - create new
run/debug configuration
with type =python
script -
configure it
- script path =
output
from p.1 - parameters = *
- working directory =
- script path =
Example
- script path: /home/xxx/.virtualenvs/some/bin/fab
- parameters: local-restore-db –dump argument