[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] replace tabs with spaces of Python code


  • To: Ian Pratt <m+Ian.Pratt@xxxxxxxxxxxx>
  • From: aq <aquynh@xxxxxxxxx>
  • Date: Thu, 19 May 2005 11:40:41 +0900
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 19 May 2005 02:40:08 +0000
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=paVynW/e4XHcWsKveITSw7LCbwiCUoK55G4v+gCdgNVZLyARr+drQwIO1cGP9V+0r1O+gv2w+lhiaf8mo5oN6wSEF6DJ4GvPBK8HtVwVWrMW68slrqaKzcFuMzx+IWEZR5uEr+ZX3px678maLSe4VWowz106MlVpjPpsbZyUoqQ=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

On 5/19/05, Ian Pratt <m+Ian.Pratt@xxxxxxxxxxxx> wrote:
> > actually, i did this job manually, with little help from one
> > small script. the reasons are:
> > - as you said, it is very dangeurous to do this kind of thing
> > automatically, so it is best to do it by hand
> 
> No, I think I'd rather it was done automatically, by a script that
> interprets white space the same way that python does.

of course it is fine if we have that kind of tool. but when we have no
such one, we can fix them all by hand, and from then on (in the
future) double check all the new python code before pushing them into
repo, so we can make sure no such a problem ever occur again.

as i said, since the patch is pretty small, we can afford to check it by hand.

> The script from python.org that Anthony posted seems to fit the bill.

no, that script doesnt work very well, because:
1. almost all the code indented by 4 spaces, but his script convert
tab to 8 spaces
2. some code consider tab as 4 and 8 spaces in the same file, so it is
hard to use this script.
3. that script doesnt see how python deal with the code. for example,
lines the python code is aligned with the previous line, but the
script doesnt take that into account. that is a problem.

a small example: file tools/python/xen/xm/main.py has few tabs inside,
and here is how Anthony's script converts the code, and it does it
wrongly. i have 3 files to compare here, so you can make a conclusion:
the main.org.py (copy from original main.py), main-t2s.py (converted
with Anthony's script, with tabsize=4) and main-aq.py (my script,
coverted manually)

now to see the problem, here is a hunk taken from the diffs. see the
commented i put next to the broken line:

$ diff -Nurp main.org.py main-t2s.py
--- main.org.py 2005-05-19 10:59:54.000000000 +0900
+++ main-t2s.py 2005-05-19 10:58:42.000000000 +0900
@@ -142,8 +142,8 @@ class Xm:
         """
         self.name = args[0]
         if len(args) < 2:
-               args.append('help')
-       help = self.helparg(args)
+            args.append('help')
+    help = self.helparg(args)               <==== wrongly indented
         p = self.getprog(args[1], self.unknown)
         if help or len(args) < 2: 
             p.help(args[1:])

in the above code, the first tab is considered 4 spaces, but the
second is considered 8 spaces. then problem arises with the Anthony's
script.


$ diff -Nurp main.org.py main-aq.py 
--- main.org.py 2005-05-19 10:59:54.000000000 +0900
+++ main-aq.py  2005-05-19 11:01:20.000000000 +0900
@@ -142,8 +142,8 @@ class Xm:
         """
         self.name = args[0]
         if len(args) < 2:
-               args.append('help')
-       help = self.helparg(args)
+            args.append('help')
+        help = self.helparg(args)
         p = self.getprog(args[1], self.unknown)
         if help or len(args) < 2: 
             p.help(args[1:])

everything is fine with main-aq.py

and here is a hunk got from diff between main-t2s.py and main-aq.py.
cleary they are not same.

$ diff -Nurp main-aq.py main-t2s.py 
--- main-aq.py  2005-05-19 11:01:20.000000000 +0900
+++ main-t2s.py 2005-05-19 10:58:42.000000000 +0900
@@ -143,7 +143,7 @@ class Xm:
         self.name = args[0]
         if len(args) < 2:
             args.append('help')
-        help = self.helparg(args)
+    help = self.helparg(args)
         p = self.getprog(args[1], self.unknown)
         if help or len(args) < 2: 
             p.help(args[1:])


> I agree that getting rid of the tabs is important, but it can happen
> after some of the outstanding tools merges get completed.

i think it is better to do it now, when there are not much code having
problem. in the future, code get bigger, so it is more difficult to
convert and check everything.

regards,
aq

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.