I was trying to get the python code formatter pep8 to run under stash but I get the error:
stash:
If this cannot run under stash for some reason, what is the easiest way to run it and pass a file parameter?
I was trying to get the python code formatter pep8 to run under stash but I get the error:
stash:
If this cannot run under stash for some reason, what is the easiest way to run it and pass a file parameter?
You need a few modifications for it to work with StaSh.
signal is not really needed for pep8. So you can ignore the error by changing line 2124 to except (AttributeError, ValueError):
In function init_checks_registry (line 1345), replace the whole function body (i.e. line 1350 to 1352) with following code:
this_filename = inspect.getfile(register_check)
for name, obj in inspect.currentframe().f_globals.items():
if inspect.isfunction(obj) and inspect.getfile(obj) == this_filename:
register_check(obj)
Now you should be able to run this from within stash.
Thank you. I made the changes and the error msg goes away but when I run pep8 with a file parameter of a script, it just returns (i.e. no output at all).
For "extra credit", I would also like to be able to run autopep8 from Stash. It fails with an 'exceptions.KeyError'
The second change to pep8.py is to fix the no output issue. I am not sure why it did not work for you, unless you ran it through an already fully pep8 compatible file.
Anyway, I uploaded my patched versions of both pep8.py and autopep8.py to Gist.
Download pep8.py to site-packages
https://gist.github.com/ywangd/9a5068bb3f66380ad36e
Download autopep8.py to bin
https://gist.github.com/ywangd/d75961a7e67b8cf07e3b
You should now be able to run autopep8 YOUR_PYTHON_FILE.py.
@ywangd Works perfectly! Thank you.