[Python-Dev] PEP 338 - Executing Modules as Scripts

Nick Coghlan ncoghlan at gmail.com
Sat Feb 11 18:02:25 CET 2006

Nick Coghlan wrote:
> Paul Moore wrote:
>> On 2/11/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>> I finally finished updating PEP 338 to comply with the flexible importing
>>> system in PEP 302.
>>> The result is a not-yet-thoroughly-tested module that should allow the -m
>>> switch to execute any module written in Python that is accessible via an
>>> absolute import statement.
>> Does this implementation resolve http://www.python.org/sf/1250389 as
>> well? A reading of the PEP would seem to imply that it does, but the
>> SF patches you mention don't include any changes to the core, so I'm
>> not sure...
> It will. I haven't updated the command line switch itself yet, so you'd need 
> to do "-m runpy <whatever>". I do plan on fixing the switch, but at the moment 
> there's a bug in the module's handling of nested packages, so I want to sort 
> that out first.

OK, nested packages now work right (I'd managed to make the common mistake 
that's highlighted quite clearly in the docs for __import__).

Running from inside a zipfile also appears to be working, but I don't have 
zlib in my Python 2.5 build to be 100% certain of that (I could check for 
certain with Python 2.4, but that would involve enough mucking around that I 
don't want to do it right now).

My aim is to have a patch up for the command line switch tomorrow. It 
shouldn't be too tricky, since it is just a matter of retrieving and calling 
the function from the module.

That should supply the last missing piece for the PEP implementation (aside 
from figuring out how to integrate my current manual test setup for 
runpy.run_module into the unit tests - it shouldn't be that hard to create a 
temp directory and add some files to it, similar to what test_pkg already does).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list