Re: [IronPython] Modifying The PYC Stub EXE
What DLLs you want to be loaded? The reason I ask is that .NET assembly loading doesn't really work on the basis of the current working directory - instead it looks at the app base which by default is where your EXE is located. We do modify sys.path so that IronPython can load things outside of the app base but I wouldn't suggest pushing this too far. Instead I'd propose doing what a normal build process does and copy the DLLs into the build directory. From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Sunday, April 05, 2009 3:55 AM To: Discussion of IronPython Subject: [IronPython] Modifying The PYC Stub EXE Hi Folks, I am looking to modify the EXE stub generated by PYC so that it will set the current working directory to the location of the EXE before loading its assemblies. The problem I am having is I build my EXE to a sub-folder called BUILD. If I call it in the form .\build\die.exe then it can't find the DLLs. This can be worked around with shortcuts setting the working dir etc but having this option in code in PYC would be useful. Forgive me if I am very very muddled up about something :-) Thanks, Davy Mitchell ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Modifying The PYC Stub EXE
Hi Dino, All the DLLs are in the Build directory. Everything runs great if the CWD is the folder containing the EXE. If you try and run it from another folder things go wrong (File Not Found Exception). I've posted a basic repro on my Skydrive http://cid-1c5b93086198f54e.skydrive.live.com/self.aspx/Public/hello.zip cd hello\build\ and die.exe will run cd hello and run .\build\die.exe and it will fail Thanks, Davy Mitchell On Mon, Apr 6, 2009 at 4:18 PM, Dino Viehland di...@microsoft.com wrote: What DLLs you want to be loaded? The reason I ask is that .NET assembly loading doesn’t really work on the basis of the current working directory – instead it looks at the app base which by default is where your EXE is located. We do modify sys.path so that IronPython can load things outside of the app base but I wouldn’t suggest pushing this too far. Instead I’d propose doing what a normal build process does and copy the DLLs into the build directory. From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Sunday, April 05, 2009 3:55 AM To: Discussion of IronPython Subject: [IronPython] Modifying The PYC Stub EXE Hi Folks, I am looking to modify the EXE stub generated by PYC so that it will set the current working directory to the location of the EXE before loading its assemblies. The problem I am having is I build my EXE to a sub-folder called BUILD. If I call it in the form .\build\die.exe then it can't find the DLLs. This can be worked around with shortcuts setting the working dir etc but having this option in code in PYC would be useful. Forgive me if I am very very muddled up about something :-) Thanks, Davy Mitchell ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Modifying The PYC Stub EXE
Davy- I had a similar problem in that the EXE stub built by pyc does not work as expected. My problem was the sys.argv being set to None. As someone who comes to ironpython from Cpython, I want the ironpython equivalent of py2exe where everything just works :) The best advice I've found here is to build your own C# stub exe (thanks Michael!) For my own purposes, I'm going with a two step process. PYC to create the DLL of my script and imported modules. And C# stub that hosts ironpython, loads all the assemblies, and calls my Main(). Now looking at your sample code, I wonder if part of the problem is that you do not have references to the assemblies that the Ironpython console loads by default. Of course I could be wrong on everything. Bruce On Sun, Apr 5, 2009 at 5:54 AM, Davy Mitchell daftspan...@gmail.com wrote: Hi Folks, I am looking to modify the EXE stub generated by PYC so that it will set the current working directory to the location of the EXE before loading its assemblies. The problem I am having is I build my EXE to a sub-folder called BUILD. If I call it in the form .\build\die.exe then it can't find the DLLs. This can be worked around with shortcuts setting the working dir etc but having this option in code in PYC would be useful. Forgive me if I am very very muddled up about something :-) Thanks, Davy Mitchell ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Modifying The PYC Stub EXE
Ahh, I see, you want to add something like: gen.EmitCall(OpCodes.Call, clr.GetClrType(Assembly).GetMethod(GetEntryAssembly), ()); gen.EmitCall(OpCodes.Call, clr.GetClrType(Assembly).GetMethod(get_CodeBase), ()); gen.Emit(OpCodes.Newobj, clr.GetClrType(System.Uri).GetConstructor( (str, ) )); gen.EmitCall(OpCodes.Call, clr.GetClrType(System.Uri).GetMethod(get_LocalPath), ()); gen.Emit(OpCodes.Newobj, clr.GetClrType(System.IO.FileInfo).GetConstructor( (str, ) )) gen.EmitCall(OpCodes.Call, clr.GetClrType(System.IO.FileInfo).GetMethod(get_Directory), ()) gen.EmitCall(OpCodes.Call, clr.GetClrType(System.IO.DirectoryInfo).GetMethod(get_FullName), ()) gen.EmitCall(OpCodes.Call, clr.GetClrType(System.Environment).GetMethod(set_CurrentDirectory), ()) right before we get the ScriptCode assembly in GenerateExe. It's really unfortunate that this is necessary. In theory we can burn a reference from your DLL into your EXE and have the CLR load the assembly and it should be able to pick it up w/o changing the CWD. The problem seems to be that we end up with DIE.EXE and DIE.DLL and it would appear the CLR always loads DIE.EXE and then it doesn't find the types in DIE.DLL. Presumably if we named them different this would work. Maybe we should enable naming them differently or maybe we should enable generating just one EXE instead of the wrapper EXE. Feel free to open a feature request - at the very least we can make an option to insert the above code :) -Original Message- From: users-boun...@lists.ironpython.com [mailto:users- boun...@lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Monday, April 06, 2009 10:57 AM To: Discussion of IronPython Subject: Re: [IronPython] Modifying The PYC Stub EXE Hi Dino, All the DLLs are in the Build directory. Everything runs great if the CWD is the folder containing the EXE. If you try and run it from another folder things go wrong (File Not Found Exception). I've posted a basic repro on my Skydrive http://cid- 1c5b93086198f54e.skydrive.live.com/self.aspx/Public/hello.zip cd hello\build\ and die.exe will run cd hello and run .\build\die.exe and it will fail Thanks, Davy Mitchell On Mon, Apr 6, 2009 at 4:18 PM, Dino Viehland di...@microsoft.com wrote: What DLLs you want to be loaded? The reason I ask is that .NET assembly loading doesn't really work on the basis of the current working directory - instead it looks at the app base which by default is where your EXE is located. We do modify sys.path so that IronPython can load things outside of the app base but I wouldn't suggest pushing this too far. Instead I'd propose doing what a normal build process does and copy the DLLs into the build directory. From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Sunday, April 05, 2009 3:55 AM To: Discussion of IronPython Subject: [IronPython] Modifying The PYC Stub EXE Hi Folks, I am looking to modify the EXE stub generated by PYC so that it will set the current working directory to the location of the EXE before loading its assemblies. The problem I am having is I build my EXE to a sub-folder called BUILD. If I call it in the form .\build\die.exe then it can't find the DLLs. This can be worked around with shortcuts setting the working dir etc but having this option in code in PYC would be useful. Forgive me if I am very very muddled up about something :-) Thanks, Davy Mitchell ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com