← Back to team overview

launchpad-dev team mailing list archive

Re: New coding standard for formatting imports

 

On 08/19/2010 10:04 AM, Benji York wrote:
On Thu, Aug 19, 2010 at 9:31 AM, Jonathan Lange<jml@xxxxxxxxxxxxx>  wrote:
On Thu, Aug 19, 2010 at 2:26 PM, Jeroen Vermeulen<jtv@xxxxxxxxxxxxx>  wrote:
On 2010-08-19 20:10, Jonathan Lange wrote:

But does that have to be a joke?  Couldn't we generate imports (well,
those
from other Launchpad modules) automatically during branch build?

...

I would much rather use editor tools than a preprocessor. Once we
introduce a mandatory preprocessing stage, we are no longer writing
Python code. Editor tools provide much the same convenience, but leave
us still writing standard Python.

...
The part I haven't thought about at all yet is how to avoid this being an
extra step, or a noticeable delay, for the developer.  But at any rate we
may find a "make" before testing preferable over editing imports ourselves.
  I for one dislike that jump to the top of the file and back.


Easily avoided with a scriptable editor. IIRC, Edwin demonstrated a
vim script for this at the Epic.

Another Vim tip for jumping around: ctrl-o will take you back to where
you were, so adding an import by hand is:

     1G -- go to the top of the file
     [misc screwing around to get the import added]
     ctrl-o -- go back to where you were

Bonus tip: ctrl-i will go forward to where you were before so
ctrl-i/ctrl-o travel forward/back in a sequence of file positions.


Since Henning's script sorts the imports for you, one could write a macro where you type "from foo.bar import Bar", the editor jumps to the top of the file, spits what you typed out anywhere in the header it likes, then runs format-imports. Henning's script will both group and sort the new import line for you. You don't even have to go to the top of the file to look.

Let the machine do the work.


--
Māris Fogels -- https://launchpad.net/~mars
Launchpad.net -- cross-project collaboration and hosting



Follow ups

References