Allow fabric to be invoked as a Python module (with -m) #975

merged 2 commits into from Sep 3, 2014


None yet

2 participants

jaraco commented Sep 5, 2013

This patch allows fabric to be invoked as a Python module. This is particularly convenient when the Python environment is known but its location (and scripts) are not (such as on Windows when using pylauncher).

jaraco commented Aug 8, 2014

I use this change every day. Now that I use Python 3 for my main environment, but because fabric doesn't yet support Python 3, I need an easy way to invoke fabric from Python 2. What I've been doing is this:

py -2 -m fabric [commands]

On Windows with pylancher, that invokes fabric under Python 2 (where fabric is installed with this patch). I don't have to have any entry points or worry about execution paths or Python 3 'fab' executable taking precedence.

The same advantages would apply on a Unix environment:

python2.7 -m fabric [commands]

That would invoke fabric under python2.7 even if 'fab' resolves to another Python version.

This change leverages well-defined Python standard defined in PEP 338, and as far as I know has no disadvantages.

@bitprophet bitprophet added the Feature label Aug 11, 2014
@bitprophet bitprophet added this to the 1.10 milestone Aug 11, 2014

Looks like this only functions correctly under Python 2.7 and up; 2.5 behaves like it's a no-op and 2.6 complains because fabric is a package instead of a module. A bit confusing since that PEP implies this was added in Python 2.5.

Still, it can hardly hurt anything for the older Pythons, so I think I may just note this in the changelog for CYA (COA?) purposes.

@bitprophet bitprophet merged commit 83313d2 into fabric:master Sep 3, 2014

1 check passed

default The Travis CI build passed
jaraco commented Sep 10, 2014

awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment