Message220364
The logic in runpy.run_path() assumes that removing the __main__ entry from sys.modules is enough to be able to use the module search logic for e.g. importing packages and ZIP files (with embedded __main__.py files).
In Python 3.4 (and probably also 3.3 where the importlib was added), this no longer works if a frozen __main__ module is present.
The reason is that the sys.meta_path lists the FrozenImporter before the PathFinder. The runpy trick only works if the PathFinder gets a chance to do its magic, but never gets to play, since the FrozenImporter always returns the existing frozen __main__ module (causing all kinds of strange effects).
Now, looking at the implementation, the frozen __main__ is imported by import.c, not the importlib, so a working solution is to not have the FrozenImporter work on __main__ modules at all.
This then allows the PathFinder to deal with finding the __main__ module in directories or ZIP files and thus allows the hack in runpy to work again.
BTW: In the long run, it would probably better to clean up runpy altogether. It's really messy code due to the many details that it has to address, but I guess this a larger project on its own. |
|
Date |
User |
Action |
Args |
2014-06-12 16:24:20 | lemburg | set | recipients:
+ lemburg |
2014-06-12 16:24:20 | lemburg | set | messageid: <1402590260.07.0.642136179062.issue21737@psf.upfronthosting.co.za> |
2014-06-12 16:24:20 | lemburg | link | issue21737 messages |
2014-06-12 16:24:19 | lemburg | create | |
|