On Apr 22, 2009, at 7:18 PM, Mark Lodato wrote:

> The embedded mode is a really good idea, but I think it would make
> more sense as a separate script for several reasons:
> 1. If it is separate, Cython itself doesn't have to change.
> 2. The same Cython C output file be made into a module and also  
> embedded.
> 3. Multiple Cython modules can be embedded into a single executable.
>
> I have included a first draft of such a script.

Any thoughts on shipping this with Cython? (I think it'd be a good  
idea.)

> An additional idea (not implemented) - it would be awesome to have the
> first module listed (that is, the one directly imported) to have
> __name__ == "__main__", so the normal Python idiom works.  I
> researched this for the past few hours, but I could not find a way to
> do this without modifying the module's code.  My best solution is the
> following:
> 1. For each module, mymod.pyx:
> 1a. Add a new externally-visible global variable:
>     int __pyx_mymod_is___main__ = 0;
> 1b. When converting the code for __name__, if __pyx_mymod_is___main__,
> return "__main__", else the module name.
> 2. In the script below, set
>     __pyx_mainmod_is___main__ = 1;
> right before the call to PyImport_ImportModule(), where "mainmod" is
> the main module.

Done. The flag is __pyx_module_is_main_[fullyqualifiedname.replace 
('.', '__')]

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to