Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Running pep8 under Stash
-
I was trying to get the python code formatter pep8 to run under stash but I get the error:
stash: <type 'exceptions.ValueError'>: signal only works in main thread
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 toexcept (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
andautopep8.py
to Gist.Download
pep8.py
tosite-packages
https://gist.github.com/ywangd/9a5068bb3f66380ad36eDownload
autopep8.py
tobin
https://gist.github.com/ywangd/d75961a7e67b8cf07e3bYou should now be able to run
autopep8 YOUR_PYTHON_FILE.py
. -
@ywangd Works perfectly! Thank you.