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

Re: [Xen-devel] [PATCH] xen/tools: support Python 2 and Python 3



On 22/02/18 16:47, Doug Goldstein wrote:
> On 2/22/18 6:54 AM, Andrew Cooper wrote:
>> On 22/02/18 05:52, Doug Goldstein wrote:
>>> These changes should make it possible to support modern Pythons as well
>>> as the oldest Python 2 still supported.
>>>
>>> Signed-off-by: Doug Goldstein <cardoe@xxxxxxxxxx>
>> To the overall effect, this is definitely a good thing.  Some queries
>> however...
>>
>>> diff --git a/xen/tools/compat-build-header.py 
>>> b/xen/tools/compat-build-header.py
>>> index 32421b645b..546371225d 100755
>>> --- a/xen/tools/compat-build-header.py
>>> +++ b/xen/tools/compat-build-header.py
>>> @@ -23,4 +23,4 @@ pats = [
>>>  for line in sys.stdin.readlines():
>>>      for pat in pats:
>>>          line = re.subn(pat[0], pat[1], line)[0]
>>> -    print line.rstrip()
>>> +    sys.stdout.write(line.rstrip() + '\n')
>> Is there anything wrong with print(line.rstrip()) which is the more
>> common way of doing this?
> The other scripts in the repo avoided using print as a function which
> was only added to Python 2.6 and newer if you use from __future__ import
> print_function. The README in the repo still says Python 2.3 and newer
> so I had assumed if I broke things prior to Python 2.6 it would be a
> show stopper. While Python 2.3 was released July 29th 2003 and Python
> 2.6 was released Oct 1st 2008 I figured changing this requirement was
> going to be met with the same difficultly I encountered last time
> suggesting that we only support versions of build tools released in the
> past decade.

The print function, or lack thereof, doesn't matter.

The above works with all of python 2, because it parses as "print_stmt,
expression of type str"

The only bit where it goes wonky is if you try to use any of the
optional print function parameters, at which point Py2 will complain.

>>> diff --git a/xen/tools/compat-build-source.py 
>>> b/xen/tools/compat-build-source.py
>>> index 595bc3ff58..8101290ebe 100755
>>> --- a/xen/tools/compat-build-source.py
>>> +++ b/xen/tools/compat-build-source.py
>>> @@ -26,4 +26,4 @@ for pat in pats:
>>>  for line in sys.stdin.readlines():
>>>      for pat in pats:
>>>          line = re.sub(pat[0], pat[1], line)
>>> -    print line.rstrip()
>>> +    sys.stdout.write(line.rstrip() + '\n')
>>> diff --git a/xen/tools/gen-cpuid.py b/xen/tools/gen-cpuid.py
>>> index 613b909c3d..d64f257816 100755
>>> --- a/xen/tools/gen-cpuid.py
>>> +++ b/xen/tools/gen-cpuid.py
>>> @@ -3,6 +3,13 @@
>>>  
>>>  import sys, os, re
>>>  
>>> +if (sys.version_info > (3, 0)):
>>> +    def long(x):
>>> +        return x
>> Strictly speaking, return int(x), however...
>>
>>> +
>>> +    def xrange(x):
>>> +        return range(x)
>>> +
>>>  class Fail(Exception):
>>>      pass
>>>  
>>> @@ -98,13 +105,13 @@ def parse_definitions(state):
>>>  def featureset_to_uint32s(fs, nr):
>>>      """ Represent a featureset as a list of C-compatible uint32_t's """
>>>  
>>> -    bitmap = 0L
>>> +    bitmap = long(0)
>>>      for f in fs:
>>> -        bitmap |= 1L << f
>>> +        bitmap |= long(1) << f
>> Having tested this out, I think the L suffixes can just be dropped:
>>
>> Python 2.4.3 (#1, Sep 21 2011, 20:06:00)
>> [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> bitmap = 0
>>>>> type(bitmap)
>> <type 'int'>
>>>>> for x in xrange(80): bitmap |= 1 << x
>> ...
>>>>> type(bitmap)
>> <type 'long'>
>> I don't recall why I wrote it like this, but I don't think its
>> necessary.  As a result, you shouldn't need to define long above.
>>
>> ~Andrew
> Python 2.4 and newer will properly extend for you but Python 2.3 will
> not and I was aiming to still support Python 2.3. Now this is all
> theoretical since I can't find any boxes with Python 2.3 anywhere and
> I'm not interested in building it.

Oh - lovely :(  So we either keep that as it was, or decide that
continuing to support a 15 year old thing is bordering on the excessive.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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