What is the closest Python equivalent for Perl :: Tidy?

Based on Perl, I used Cc to hit to format my code according to the predefined rules of Perl::Tidy . Now, with Python, I am surprised to learn that there is nothing remotely resembling the power of Perl::Tidy . PythonTidy 1.20 looks almost appropriate, but at the first level it is erroneously aligned ("unexpected indentation").

In particular, I am looking for the following:

  • Put PEP-8 to use as much as possible (the following elements are essentially conclusions of this)
  • Convert indent tabs to spaces
  • Remove trailing spaces
  • Break the code according to the predefined line length as much as possible (chaining method of line splitting and splitting Eclipse styles)
  • Normalize spaces around
  • (bonus function, optional) Re-formatting code, including indentation.

Right now, I am pep8 through someone else's code and fixing all pep8 and pyflakes tell me that basically โ€œremoves the trailing spaceโ€ and โ€œinserts an extra blank lineโ€. Although I know that re-indentation is not trivial in Python (although it should be possible just by going through the code and remembering the indentation), the other functions seem quite easy, and I cannot believe that no one has implemented this before.

Any recommendations?

Refresh . I'm going to take a deeper look at PythonTidy as it seems to be going in the right direction. Maybe I can find out why it hurts me.

+4
source share
4 answers

There is a reindent.py script distributed using python in the scripts directory.

+1
source

untabify.py ( Tools/scripts/untabify.py from the root directory of the Python source distribution distribution) should fix the tabs, which may be what stops Python Tidy from doing the rest of the work.

0
source

Have you tried to create a wrapper around pythontidy? There is one for the sublime editor here .

Also, pythontidy breaks long lines right for you? When I have a long line ending with a tuple, it creates a new line for each record in the tuple, instead of using Python's continued continuation in parentheses, brackets and curly braces, as suggested by PEP-8.

0
source

I used autopep8 for this purpose and found it convenient.

0
source

All Articles