omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    6
    3217
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ihf
      ihf last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • ywangd
        ywangd last edited by ywangd

        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.

        1 Reply Last reply Reply Quote 1
        • ihf
          ihf last edited by

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

          1 Reply Last reply Reply Quote 0
          • ihf
            ihf last edited by

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

            1 Reply Last reply Reply Quote 0
            • ywangd
              ywangd last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • ihf
                ihf last edited by

                @ywangd Works perfectly! Thank you.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors