Forum Archive

Running pep8 under Stash

ihf

I was trying to get the python code formatter pep8 to run under stash but I get the error:

stash: : 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?

ywangd

You need a few modifications for it to work with StaSh.

    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.

ihf

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).

ihf

For "extra credit", I would also like to be able to run autopep8 from Stash. It fails with an 'exceptions.KeyError'

ywangd

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.

ihf

@ywangd Works perfectly! Thank you.