[IronPython] Compilation difficulties

Dino Viehland dinov at exchange.microsoft.com
Fri Oct 6 22:02:28 CEST 2006


Unfortunately I don't think this is going to work today.  As you seem to have noticed we're going to treat the assembly as if it's a normal CLR assembly.  Ideally what we'd do is do the same thing as CPython does w/ .pyc's which is the cache them for you and load them for you automatically.

We do have a bug for this (http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=358).  I've added a +1 to the bug (currently marked for 1.1) so that when we look at the 1.1 bugs we'll make sure to prioritize this one.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Christian Muirhead
Sent: Friday, October 06, 2006 9:45 AM
To: users at lists.ironpython.com
Subject: Re: [IronPython] Compilation difficulties

Hi -

I'm a colleague of William's and I'm looking into having some of our packages compiled as dlls (primarily to reduce startup time). I have a structure as discussed in the messages below, and compiling to an exe and running it produces the expected output.

(structure)
  project/
  | main.py
  + Cheesemonger/
   | __init__.py
   | Shopkeeper.py
   | Counter.py


(There is one minor difference: when main.py is running from the executable, the value of __name__ is 'main', rather than '__main__' - I'm not sure why this is, but if I account for it the script works
correctly.)

What I would like to do is keep main.py as a normal .py file, which uses the Cheesemonger package from a dll. I can compile the Cheesemonger package to a dll using pyc.py, and use clr.AddReferenceToFile to add a reference to the dll, but I can't then import Cheesemonger.Storekeeper (or anything else that I think should be included in the dll).

I would guess that while this is how one would use a C# class that had been compiled into a dll from IronPython, it doesn't work for classes compiled using pyc.py because of the name-mangling done when IP generates an assembly from the Python code. Is this right?

If so, how would one use a package that had been compiled to a dll with pyc?

Thanks,
Christian

William Reade wrote:
>
>
> -------- Original Message --------
> Subject:     Re: [IronPython] Compilation difficulties
> Date:     Mon, 2 Oct 2006 09:50:12 -0700
> From:     Dave Fugate <dfugate at microsoft.com>
> Reply-To:     Discussion of IronPython <users at lists.ironpython.com>
> To:     Discussion of IronPython <users at lists.ironpython.com>
> References:     <451D110D.1070301 at resolversystems.com>
>
>
>
> I'm glad to see people are finding this sample useful!
>
> My first suggestion is to verify you have an __init__.py in
> Cheesemonger. I'm pretty sure the answer is yes but just to be certain...
>
> Second, using a command such as:
>        E:\Temp>ipy F:\ipsd\IronPython\Samples\Pyc\pyc.py
> Cheesemonger\Counter.py Cheesemonger\Shopkeeper.py
> Cheesemonger\__init__.py /main:main.py /out:CM.dll should do what I
> *think* you're trying to do. This creates an
> (executable) CM.dll based on main.py which pretty much follows your
> series of files except that my main.py invokes a function from
> Cheesemonger.Counter. When I run CM.dll, the output verifies it is
> indeed using modules from Cheesemonger.*
>
> Last but definitely not least, please stay away from using tools like
> ildasm, reflector, etc to examine the contents of IronPython created
> DLLs. What you'll find there is almost certainly not what you'd expect
> as mentioned on the Codeplex Samples page.
>
>
>
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com
> [mailto:users-bounces at lists.ironpython.com] On Behalf Of William Reade
> Sent: Friday, September 29, 2006 5:27 AM
> To: Discussion of IronPython
> Subject: [IronPython] Compilation difficulties
>
> Hi all
>
> I've been playing with the (excellent) Pyc sample, and I've got stuck.
> I have a series of files a bit like the following:
>
> project/
> | main.py
> + Cheesemonger/
>  | Shopkeeper.py
>  | Counter.py
>
> ...in which main.py contains statements like:
>
> from Cheesemonger.Counter import Counter
>
> ...and Counter.py also contains statements like:
>
> from Cheesemonger.Shopkeeper import Shopkeeper
>
> ---
>
> This is all very well, but I can't work out how to compile a
> Cheesemonger.dll in which the above imports still function -- when I
> inspect it with ildasm, the dll contains "Counter" and "Shopkeeper"
> rather than "Cheesemonger.Counter" and "Cheesemonger.Shopkeeper".
>
> I can "fix" the issue by undisambiguating the imports:
>
> clr.AddReference("Cheesemonger")
> from Counter import Counter
>
> ...and:
>
> from Shopkeeper import Shopkeeper
>
> ...but we've been burned by ambiguous imports before and would prefer
> not to reintroduce them (life can get confusing when every directory
> contains its own "UnitTests" directory ;)).
>
> Is there any way of compiling a directory (and subdirectories) into a
> single dll, such that no import statements need to be changed? A quick
> look at the IP source left me none the wiser, I'm afraid.
>
> Cheers
> William
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>


_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list