[IronPython] Cyclic Imports in Compiled Modules - Blocker

Michael Foord fuzzyman at voidspace.org.uk
Fri Sep 19 13:30:23 CEST 2008


Ok - minimal repro attached.

Inside the zip folder are two folders - "compiled" and "uncompiled". 
Both have a 'test.py' script with an accompanying package.

'test.py' merely does 'import package.module1'.

The package contains 'module1.py' and 'module2.py' which print when they 
are first imported, and they import each other.

When you execute 'test.py' in the "uncompiled" folder with IronPython 
2.0 B5 it outputs:

Imported package module 1
Imported package module 2
Done
Done

If you do the same in the "compiled" folder it cycles the 'Imported ...' 
lines forever...

In order to get compiled packages working I added the following to the 
'__init__.py':

    import clr
    from System.Reflection import Assembly
    from System.IO import Path

    this_dir = Path.GetDirectoryName(__file__)
    ass = Assembly.LoadFile(Path.Combine(this_dir, 'modules.dll'))
    clr.AddReference(ass)

As far as I can tell you need to do something like this in order to be 
able to import compiled modules from a package.

Michael Foord



Michael Foord wrote:
> Hello guys,
>
> I've been attempting to create a binary distribution of Resolver One 
> using clr.CompileModules with IronPython 2.0 Beta 5.
>
> The framework basically works - modulo the fact that subpackages in 
> compiled assemblies don't work. However cyclic imports inside compiled 
> modules don't work.
>
> We have some cyclic imports inside one of our packages. The code works 
> under IronPython 2. I haven't yet attempted a minimal repro, *but* 
> with prints inside the modules I can verify that the cyclic imports 
> re-executes the prints in a cycle... never to escape.
>
> I'll attempt a minimal repro and repost here. This is going to block 
> us on moving to IronPython 2 unfortunately.
>
> All the best,
>
> Michael
>


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.resolverhacks.net/
http://www.theotherdelia.co.uk/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cyclic-imports.zip
Type: application/octet-stream
Size: 3964 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080919/cd80b1a4/attachment.obj>


More information about the Ironpython-users mailing list