PythonTidy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chuck Rhode

    #1

    PythonTidy

    I couldn't find a routine to clean up, regularize, and reformat Python
    code, so I wrote one:



    Now, I'm looking for beta-testers. Compensation is a bit on the low
    side. In fact it's limited to the satisfaction of helping out.
    Thanks.

    --
    ... Chuck Rhode, Sheboygan, WI, USA
  • Roberto Bonvallet

    #2
    Re: PythonTidy

    Chuck Rhode wrote:
    I couldn't find a routine to clean up, regularize, and reformat Python
    code, so I wrote one:
    >

    >
    Now, I'm looking for beta-testers. Compensation is a bit on the low
    side. In fact it's limited to the satisfaction of helping out.
    $ cat test.py
    #!/usr/bin/env python2.5
    # vim: set fileencoding=ut f-8 :

    for i in xrange ( 3) :
    print i

    $ python2.5 PythonTidy.pyth on < test.py
    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    for i in xrange(3):
    print i

    About changing the shebang line: I'll take it as a bug.
    About changing the encoding declaration from vim-style to emacs-style:
    I'll take it as an insult :)

    Both are comments, and should be left that way. Besides, there is no
    officially preferred way for each of them. BTW, in a recent thread on
    this newsgroup, most people said they preferred #!/usr/bin/env python over
    #!/usb/bin/python for the shebang line. See http://tinyurl.com/yngmfr .

    Best regards.
    --
    Roberto Bonvallet

    Comment

    • Laurent Pointal

      #3
      Re: PythonTidy

      Roberto Bonvallet a écrit :
      Chuck Rhode wrote:
      >I couldn't find a routine to clean up, regularize, and reformat Python
      >code, so I wrote one:
      >>
      > http://www.lacusveris.com/PythonTidy/PythonTidy.python
      >>
      >Now, I'm looking for beta-testers. Compensation is a bit on the low
      >side. In fact it's limited to the satisfaction of helping out.
      >
      ....
      # vim: set fileencoding=ut f-8 :
      ....
      # -*- coding: utf-8 -*-
      ....
      About changing the shebang line: I'll take it as a bug.
      About changing the encoding declaration from vim-style to emacs-style:
      I'll take it as an insult :)
      This is not "emacs-style", this is Python normalized source encoding
      directive for correct interpretation of u"..." strings by Python
      interpreter.

      See http://www.python.org/dev/peps/pep-0263/


      A+

      Laurent.

      Comment

      • Roberto Bonvallet

        #4
        Re: PythonTidy

        Laurent Pointal wrote:
        ...
        ># vim: set fileencoding=ut f-8 :
        ...
        ># -*- coding: utf-8 -*-
        ...
        >
        This is not "emacs-style", this is Python normalized source encoding
        directive for correct interpretation of u"..." strings by Python
        interpreter.
        >
        See http://www.python.org/dev/peps/pep-0263/
        The -*- syntax is emacs-style. The encoding directive is anything that
        matches r"coding[=:]\s*([-\w.]+)". The docs recommend to use either
        emacs-style or vim-style. See http://docs.python.org/ref/encodings.html

        Cheers,
        --
        Roberto Bonvallet

        Comment

        • Richie Hindle

          #5
          Re: PythonTidy


          [Roberto]
          # vim: set fileencoding=ut f-8 :
          ...
          # -*- coding: utf-8 -*-
          ...
          About changing the encoding declaration from vim-style to emacs-style:
          I'll take it as an insult :)
          [Laurent]
          This is not "emacs-style", this is Python normalized source encoding
          directive for correct interpretation of u"..." strings by Python
          interpreter.
          So is "# vim: set fileencoding=ut f-8". Anything matching
          "coding[:=]\s*([-\w.]+)" on the first or second line counts.
          Yes, you should. 8-)

          --
          Richie Hindle
          richie@entrian. com

          Comment

          • Marc 'BlackJack' Rintsch

            #6
            Re: PythonTidy

            In <ekmmu4$8ii$1@u psn250.cri.u-psud.fr>, Laurent Pointal wrote:
            Roberto Bonvallet a écrit :
            ># vim: set fileencoding=ut f-8 :
            ...
            ># -*- coding: utf-8 -*-
            ...
            >About changing the shebang line: I'll take it as a bug.
            >About changing the encoding declaration from vim-style to emacs-style:
            >I'll take it as an insult :)
            >
            This is not "emacs-style", this is Python normalized source encoding
            directive for correct interpretation of u"..." strings by Python
            interpreter.
            >
            See http://www.python.org/dev/peps/pep-0263/
            Where does it say it has to be emacs-style? It just uses that style as
            example as far as I can see. The real definition is a regexp:

            coding[:=]\s*([-\w.]+)

            So the vim-style is fine. No need to replace it.

            Ciao,
            Marc 'BlackJack' Rintsch

            Comment

            • Laurent Pointal

              #7
              Re: PythonTidy

              Laurent Pointal a écrit :
              Aye, sorry for my missreading...

              [seem I hurt the emacs guy]

              Comment

              • Chuck Rhode

                #8
                Re: PythonTidy

                Roberto Bonvallet wrote this on Thu, Nov 30, 2006 at 01:21:55PM +0000. My reply is below.
                About changing the shebang line: I'll take it as a bug.
                About changing the encoding declaration from vim-style to
                emacs-style: I'll take it as an insult :)
                Ooh! <wounded>
                Both are comments, and should be left that way. Besides, there is no
                officially preferred way for each of them. BTW, in a recent thread on
                this newsgroup, most people said they preferred #!/usr/bin/env python over
                #!/usb/bin/python for the shebang line. See http://tinyurl.com/yngmfr .
                Thanks for the link. I was unaware of the /usr/bin/env technique and
                the controversy surrounding it.

                Thanks, too, for trying *PythonTidy*.

                As you have no doubt perceived, *PythonTidy* is *not* "table driven."
                It is a script after all. I decided before writing it that I didn't
                really need to externalize all the options; nevertheless, most are
                declared near the beginning where they sit just begging for end-user
                involvement. See: CODING_SPEC and SHEBANG. *PythonTidy* is all about
                consistency, consistency, and consistency. You can use it to
                standardize shebangs and coding across a whole library of Python
                scripts.

                --
                ... Chuck Rhode, Sheboygan, WI, USA
                ... Weather: http://LacusVeris.com/WX
                ... 25° — Wind NW 13 mph

                Comment

                • Roberto Bonvallet

                  #9
                  Re: PythonTidy

                  Chuck Rhode wrote:
                  [...]
                  Thanks, too, for trying *PythonTidy*.
                  No, thanks you for writing such a tool!
                  [...] nevertheless, most [options] are declared near the beginning where
                  they sit just begging for end-user involvement. See: CODING_SPEC and
                  SHEBANG.
                  The fact that I immediately noticed them and came up with an example to
                  raise both issues is a indicator of how easy it would be to customize the
                  script :)

                  Cheers!
                  --
                  Roberto Bonvallet

                  Comment

                  Working...