Bug 107566 - AttributeError: 'tuple' object has no attribute 'major'
Summary: AttributeError: 'tuple' object has no attribute 'major'
Status: RESOLVED WONTFIX
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords: bisected, regression
Depends on:
Blocks:
 
Reported: 2018-08-14 07:11 UTC by Vinson Lee
Modified: 2018-08-14 15:53 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Vinson Lee 2018-08-14 07:11:40 UTC
Build error with Python 2.6.

  Generating build/linux-x86_64-debug/util/xmlpool/options.h ...
Traceback (most recent call last):
  File "src/util/xmlpool/gen_xmlpool.py", line 216, in <module>
    expandMatches ([matchDESC], translations)
  File "src/util/xmlpool/gen_xmlpool.py", line 143, in expandMatches
    if sys.version_info.major == 2:
AttributeError: 'tuple' object has no attribute 'major'

commit bd27203f4d808763ac24ac94eb677cacf3e7cb99
Author: Mathieu Bridon <bochecha@daitauha.fr>
Date:   Fri Aug 10 23:17:08 2018 +0200

    python: Rework bytes/unicode string handling
    
    In both Python 2 and 3, opening a file without specifying the mode will
    open it for reading in text mode ('r').
    
    On Python 2, the read() method of a file object opened in mode 'r' will
    return byte strings, while on Python 3 it will return unicode strings.
    
    Explicitly specifying the binary mode ('rb') then decoding the byte
    string means we always handle unicode strings on both Python 2 and 3.
    
    Which in turns means all re.match(line) will return unicode strings as
    well.
    
    If we also make expandCString return unicode strings, we don't need the
    call to the unicode() constructor any more.
    
    We were using the ugettext() method because it always returns unicode
    strings in Python 2, contrarily to the gettext() one which returns
    byte strings. The ugettext() method doesn't exist on Python 3, so we
    must use the right method on each version of Python.
    
    The last hurdles are that Python 3 doesn't let us concatenate unicode
    and byte strings directly, and that Python 2's stdout wants encoded byte
    strings while Python 3's want unicode strings.
    
    With these changes, the script gives the same output on both Python 2
    and 3.
    
    Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr>
    Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Comment 1 Tomeu Vizoso 2018-08-14 07:27:19 UTC
Workaround:

diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py
index 327709c7f8dd..0d97fbcfcf3f 100644
--- a/src/util/xmlpool/gen_xmlpool.py
+++ b/src/util/xmlpool/gen_xmlpool.py
@@ -140,8 +142,8 @@ def expandMatches (matches, translations, end=None):
 
         # In Python 2, stdout expects encoded byte strings, or else it will
         # encode them with the ascii 'codec'
-        if sys.version_info.major == 2:
-            text = text.encode('utf-8')
+        #if sys.version_info.major == 2:
+        text = text.encode('utf-8')
 
         print(text)
Comment 2 Tomeu Vizoso 2018-08-14 07:33:58 UTC
(In reply to Tomeu Vizoso from comment #1)
> Workaround:
> 
> diff --git a/src/util/xmlpool/gen_xmlpool.py
> b/src/util/xmlpool/gen_xmlpool.py
> index 327709c7f8dd..0d97fbcfcf3f 100644
> --- a/src/util/xmlpool/gen_xmlpool.py
> +++ b/src/util/xmlpool/gen_xmlpool.py
> @@ -140,8 +142,8 @@ def expandMatches (matches, translations, end=None):
>  
>          # In Python 2, stdout expects encoded byte strings, or else it will
>          # encode them with the ascii 'codec'
> -        if sys.version_info.major == 2:
> -            text = text.encode('utf-8')
> +        #if sys.version_info.major == 2:
> +        text = text.encode('utf-8')
>  
>          print(text)

Not really, it's better to just revert "2ee1c86d71be meson: Build with Python 3"
Comment 3 Dylan Baker 2018-08-14 15:53:51 UTC
Python 2.6 went EOL in 2013, and we have required python 2.7 since 2015, the fact that python 2.6 continued to work is just happenstance. We need to support python 3.x for the future, python 2 will reach EOL in 2 years, and distros are starting to look to a python 3 by default future. We will continue to support python 2.7 as long as the autotools build remains and as long as the scons build remains (unless someone ports it to 2.7), but python 2.6 is not supported.

Please install or update to python 2.7 for scons and autotools builds.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.