diff options
author | Zachary Turner <zturner@google.com> | 2015-11-05 19:22:28 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2015-11-05 19:22:28 +0000 |
commit | c1b7cd72db41c14a4f8d7df2c06bc908e2f0bae5 (patch) | |
tree | ab8840e262dc2d898cb8df2eb36ebbe7b427b527 /lldb/packages/Python/lldbsuite/test/dosep.py | |
parent | 185a7aaddacff4b7c846b5946c244d6fabdefa32 (diff) | |
download | bcm5719-llvm-c1b7cd72db41c14a4f8d7df2c06bc908e2f0bae5.tar.gz bcm5719-llvm-c1b7cd72db41c14a4f8d7df2c06bc908e2f0bae5.zip |
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/dosep.py')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/dosep.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/dosep.py b/lldb/packages/Python/lldbsuite/test/dosep.py index 710be296455..08da003e9b5 100644 --- a/lldb/packages/Python/lldbsuite/test/dosep.py +++ b/lldb/packages/Python/lldbsuite/test/dosep.py @@ -33,8 +33,7 @@ echo core.%p | sudo tee /proc/sys/kernel/core_pattern """ from __future__ import print_function - - +from __future__ import absolute_import # system packages and modules import asyncore @@ -51,15 +50,17 @@ import threading from six.moves import queue -# Add our local test_runner/lib dir to the python path. -sys.path.append(os.path.join(os.path.dirname(__file__), "test_runner", "lib")) - # Our packages and modules -import dotest_channels -import dotest_args +import lldbsuite.support.seven as seven + +from . import dotest_channels +from . import dotest_args + +# Todo: Convert this folder layout to be relative-import friendly and don't hack up +# sys.path like this +sys.path.append(os.path.join(os.path.dirname(__file__), "test_runner", "lib")) import lldb_utils import process_control -import lldbsuite.support.seven as seven # Status codes for running command with timeout. eTimedOut, ePassed, eFailed = 124, 0, 1 |