Mailing List Archive

Gordons installer or imputil problem?
Gordon,
I tried out your installer (the new beta) and am really impressed.
IMHO the best part is parsing the binary files (dlls, pyds) for dependecies.

I noticed a strange problem however, and I do not know where to look
for the solution.

Consider a simple python package:

directory 'package':
file '__init__.py'
file 'mod.py'

and the following scripts:

-----<script a>-----
print "Importing package"
import package
print "Importing package.mod"
import package.mod
print "Importing mod from package"
from package import mod
-----<EOF script a>-----

-----<script b>-----
print "Importing package"
import package
print "Importing mod from package"
from package import mod
print "Importing package.mod"
import package.mod
-----<EOF script b>-----

Since 'package' as well as 'package.mod' is imported
and modulefinder.py has no problems finding the needed files
and a.exe and b.exe are generated correctly.

Running the scripts shows the problem:

C:\>a
Importing package
Importing package.mod1
Importing mod1 from package

C:\>b
Importing package
Importing mod1 from package
Traceback (innermost last):
File "C:\launch.py", line 5, in ?
from package import mod1
ImportError: cannot import name mod1

C:\>

The only difference between a.py and b.py is that in the first case
'import package.mod' is executed before 'from package import mod',
while in the other case the order is different.
Since I'm working with packages a lot, and normally use 'from package import
module'
I would stronly prefer to find a solution other than rewriting all the
import statements.


Thomas Heller
ION-TOF GmbH
Gordons installer or imputil problem? [ In reply to ]
Thomas Heller wrote:

> I tried out your installer (the new beta) and am really impressed.
> IMHO the best part is parsing the binary files (dlls, pyds) for
> dependecies.
>
> I noticed a strange problem however, and I do not know where to look
> for the solution.

[import package.mod vs from package import mod]

> The only difference between a.py and b.py is that in the first case
> 'import package.mod' is executed before 'from package import mod',
> while in the other case the order is different. Since I'm working
> with packages a lot, and normally use 'from package import module' I
> would stronly prefer to find a solution other than rewriting all the
> import statements.

OK, just tested imputil on a .pyz built with a package= option. No
problem using "from package import mod".

Just poked around with modulefinder - no problem there.

AHA! It's the way the zlib gets built. When you specify a package,
the TOC has an entry for "package.__init__" and "package.mod", as it
should. But when it's built from chasing dependencies, it has an
entry for "package" and "package.mod", so imputil thinks "package" is
a module...

Hack hack hack...

archivebuilder line 139 to end of function:

for (k, v) in mf.modules.items():
ispkg = os.path.basename(v.__file__) == '__init__.py'
d = os.path.dirname(v.__file__)
if not d:
v.__file__ = os.path.join(os.getcwd(), v.__file__)
if ispkg:
rslt.append(k+'.__init__', v.__file__)
else:
rslt.append(k, v.__file__)
return rslt

or-wait-for-the-next-rev-of-the-beta-ly y'rs

- Gordon