On Thu, May 14, 2009 at 5:08 AM, Robert Bradshaw
<[email protected]> wrote:
> On Apr 22, 2009, at 7:18 PM, Mark Lodato wrote:
>> 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
> ('.', '__')]


Awesome - thanks!

I updated my cython_freeze.py script and uploaded it to GitHub:
http://github.com/MarkLodato/cython_freeze

It now uses the __pyx_module_is_main_* flag to set the main module, so
it requires Cython 0.11.2.

I also included detailed documentation and a simple example.

If you all have any suggestions, I would be happy to implement them.
It would be nice to include this in some form as part of the Cython
distribution.

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

Reply via email to