From bbe074c8e8a06af07ae31015b1c9262c2bd34f73 Mon Sep 17 00:00:00 2001 From: giovannibajo Date: Mon, 15 Jun 2009 22:47:53 +0000 Subject: [PATCH] Bug #60: Relative import syntax (dots) does not disable top-level (absolute) imports. git-svn-id: http://svn.pyinstaller.org/trunk@679 8dd32b29-ccff-0310-8a9a-9233e24343b1 --- buildtests/relimp3a/__init__.py | 1 + buildtests/relimp3a/aa/__init__.py | 0 buildtests/relimp3a/aa/a1.py | 6 ++++++ buildtests/relimp3a/aa/relimp3c.py | 2 ++ buildtests/relimp3a/relimp3b.py | 1 + buildtests/relimp3a/relimp3c.py | 1 + buildtests/relimp3b/__init__.py | 1 + buildtests/relimp3b/b1.py | 1 + buildtests/relimp3c/__init__.py | 1 + buildtests/test-relative-import3.py | 4 ++++ buildtests/test-relative-import3.spec | 17 +++++++++++++++++ iu.py | 2 +- mf.py | 2 +- 13 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 buildtests/relimp3a/__init__.py create mode 100644 buildtests/relimp3a/aa/__init__.py create mode 100644 buildtests/relimp3a/aa/a1.py create mode 100644 buildtests/relimp3a/aa/relimp3c.py create mode 100644 buildtests/relimp3a/relimp3b.py create mode 100644 buildtests/relimp3a/relimp3c.py create mode 100644 buildtests/relimp3b/__init__.py create mode 100644 buildtests/relimp3b/b1.py create mode 100644 buildtests/relimp3c/__init__.py create mode 100644 buildtests/test-relative-import3.py create mode 100644 buildtests/test-relative-import3.spec diff --git a/buildtests/relimp3a/__init__.py b/buildtests/relimp3a/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/buildtests/relimp3a/__init__.py @@ -0,0 +1 @@ + diff --git a/buildtests/relimp3a/aa/__init__.py b/buildtests/relimp3a/aa/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/buildtests/relimp3a/aa/a1.py b/buildtests/relimp3a/aa/a1.py new file mode 100644 index 0000000..cac7d99 --- /dev/null +++ b/buildtests/relimp3a/aa/a1.py @@ -0,0 +1,6 @@ +from .relimp3b import b1 +from .relimp3c import c1 + +def getString(): + return b1.string + c1.string + diff --git a/buildtests/relimp3a/aa/relimp3c.py b/buildtests/relimp3a/aa/relimp3c.py new file mode 100644 index 0000000..710c942 --- /dev/null +++ b/buildtests/relimp3a/aa/relimp3c.py @@ -0,0 +1,2 @@ +class c1: + string = "... and this" diff --git a/buildtests/relimp3a/relimp3b.py b/buildtests/relimp3a/relimp3b.py new file mode 100644 index 0000000..68263d9 --- /dev/null +++ b/buildtests/relimp3a/relimp3b.py @@ -0,0 +1 @@ +raise ValueError diff --git a/buildtests/relimp3a/relimp3c.py b/buildtests/relimp3a/relimp3c.py new file mode 100644 index 0000000..68263d9 --- /dev/null +++ b/buildtests/relimp3a/relimp3c.py @@ -0,0 +1 @@ +raise ValueError diff --git a/buildtests/relimp3b/__init__.py b/buildtests/relimp3b/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/buildtests/relimp3b/__init__.py @@ -0,0 +1 @@ + diff --git a/buildtests/relimp3b/b1.py b/buildtests/relimp3b/b1.py new file mode 100644 index 0000000..78ff89b --- /dev/null +++ b/buildtests/relimp3b/b1.py @@ -0,0 +1 @@ +string = "I hope you see this!" diff --git a/buildtests/relimp3c/__init__.py b/buildtests/relimp3c/__init__.py new file mode 100644 index 0000000..a9615e1 --- /dev/null +++ b/buildtests/relimp3c/__init__.py @@ -0,0 +1 @@ +raise RuntimeError diff --git a/buildtests/test-relative-import3.py b/buildtests/test-relative-import3.py new file mode 100644 index 0000000..a81039b --- /dev/null +++ b/buildtests/test-relative-import3.py @@ -0,0 +1,4 @@ +from relimp3a.aa import a1 + +if __name__ == '__main__': + print a1.getString() diff --git a/buildtests/test-relative-import3.spec b/buildtests/test-relative-import3.spec new file mode 100644 index 0000000..087a268 --- /dev/null +++ b/buildtests/test-relative-import3.spec @@ -0,0 +1,17 @@ +# -*- mode: python -*- + +__testname__ = 'test-relative-import3' + +a = Analysis([os.path.join(HOMEPATH,'support/_mountzlib.py'), + __testname__ + '.py'], + ) +pyz = PYZ(a.pure) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + name = os.path.join('dist', __testname__, __testname__ +'.exe'), + debug=False, + strip=False, + upx=False, + console=1 ) diff --git a/iu.py b/iu.py index fa92434..27258f6 100644 --- a/iu.py +++ b/iu.py @@ -406,7 +406,7 @@ class ImportManager: if level > 1: importernm = _string_split(importernm, '.')[:-level+1] importernm = _string_join('.', importernm) - contexts = [] + contexts = [None] if importernm: if ispkg: # If you use the "from __init__ import" syntax, the package diff --git a/mf.py b/mf.py index db16d3f..d7872db 100644 --- a/mf.py +++ b/mf.py @@ -494,7 +494,7 @@ class ImportTracker: level -= 1 if level > 0: importernm = string.join(string.split(importernm, '.')[:-level], ".") - contexts = [importernm] + contexts = [importernm, None] importernm = None _all = None