[Piglit] [PATCH 01/20] framework: Use explicit relative imports to be Python 3 compatible.

Jon Severinsson jon at severinsson.net
Wed Apr 17 09:14:40 PDT 2013


From: Kenneth Graunke <kenneth at whitecape.org>

Python 3 dropped support for implicit relative imports, since the
statement 'import core' would be ambiguous if there were a module
named 'core' installed system wide and a similarly named module in the
current package.

Using a leading '.' means to import it from the current module
directory.  This is the approach taken by the 2to3 command.

For more information, see:
http://stackoverflow.com/questions/12172791/changes-in-import-statement-python3

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 framework/core.py             |    7 ++++---
 framework/exectest.py         |    4 ++--
 framework/gleantest.py        |    6 +++---
 framework/glsl_parser_test.py |    6 +++---
 framework/log.py              |    5 +++--
 framework/shader_test.py      |    6 +++---
 framework/summary.py          |    2 +-
 framework/threads.py          |    5 +++--
 8 filer ändrade, 22 tillägg(+), 19 borttagningar(-)

diff --git a/framework/core.py b/framework/core.py
index 3807cf9..c8ddfd3 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -22,6 +22,10 @@
 
 # Piglit core
 
+from .log import log
+from .threads import ConcurrentTestPool
+from .threads import synchronized_self
+
 import errno
 import json
 import os
@@ -33,11 +37,8 @@ import string
 import sys
 import time
 import traceback
-from log import log
 from cStringIO import StringIO
 from textwrap import dedent
-from threads import ConcurrentTestPool
-from threads import synchronized_self
 import threading
 
 __all__ = [
diff --git a/framework/exectest.py b/framework/exectest.py
index 652ff4d..7c54681 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -20,14 +20,14 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+from .core import Test, testBinDir, TestResult
+
 import errno
 import os
 import subprocess
 import shlex
 import types
 
-from core import Test, testBinDir, TestResult
-
 #############################################################################
 ##### Platform global variables
 #############################################################################
diff --git a/framework/gleantest.py b/framework/gleantest.py
index 1143ebf..597b005 100644
--- a/framework/gleantest.py
+++ b/framework/gleantest.py
@@ -20,12 +20,12 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+from .core import checkDir, testBinDir, Test, TestResult
+from .exectest import ExecTest
+
 import os
 import subprocess
 
-from core import checkDir, testBinDir, Test, TestResult
-from exectest import ExecTest
-
 #############################################################################
 ##### GleanTest: Execute a sub-test of Glean
 #############################################################################
diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 66e6dd3..9385dab 100755
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -31,17 +31,17 @@ standalone tests on the command line. To add a test to a Piglit group, us
 
 usage_message = "usage: glsl_parser_test.py TEST_FILE"
 
+from .core import Test, testBinDir, TestResult
+from .exectest import PlainExecTest
+
 import ConfigParser
 import os
 import os.path as path
 import re
 import subprocess
 import sys
-
 from ConfigParser import SafeConfigParser
-from core import Test, testBinDir, TestResult
 from cStringIO import StringIO
-from exectest import PlainExecTest
 
 def add_glsl_parser_test(group, filepath, test_name):
 	"""Add an instance of GLSLParserTest to the given group."""
diff --git a/framework/log.py b/framework/log.py
index e90137a..bf8ce9d 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -21,8 +21,9 @@
 # IN THE SOFTWARE.
 #
 
-from threads import synchronized_self
-from patterns import Singleton
+from .threads import synchronized_self
+from .patterns import Singleton
+
 import logging
 
 class Logger(Singleton):
diff --git a/framework/shader_test.py b/framework/shader_test.py
index 48a9085..67930a4 100755
--- a/framework/shader_test.py
+++ b/framework/shader_test.py
@@ -23,6 +23,9 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+from .core import testBinDir, Group, Test, TestResult
+from .exectest import PlainExecTest
+
 import json
 import os
 import os.path
@@ -31,9 +34,6 @@ import re
 import sys
 import textwrap
 
-from core import testBinDir, Group, Test, TestResult
-from exectest import PlainExecTest
-
 """This module enables running shader tests.
 
 This module can be used to add shader tests to a Piglit test group or to run
diff --git a/framework/summary.py b/framework/summary.py
index a72bb4b..c2a7f00 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -20,7 +20,7 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
-import core
+import .core
 
 
 #############################################################################
diff --git a/framework/threads.py b/framework/threads.py
index 724e84e..443cb5c 100644
--- a/framework/threads.py
+++ b/framework/threads.py
@@ -21,8 +21,9 @@
 # IN THE SOFTWARE.
 #
 
-from threadpool import ThreadPool, WorkRequest
-from patterns import Singleton
+from .threadpool import ThreadPool, WorkRequest
+from .patterns import Singleton
+
 from threading import RLock
 from weakref import WeakKeyDictionary
 import multiprocessing
-- 
1.7.10.4



More information about the Piglit mailing list