Message299236
This is a result of a known quirk in the way sys.path entry execution works: the search for "__main__.py" isn't constrained specifically to sys.path[0].
That's almost entirely a bad thing, but I'd been ignoring it because I hadn't thought of a nice way of fixing it that didn't require some substantial changes to the import system APIs.
However, it just occurred to me that I may have been overcomplicating matters: we don't need to keep runpy from *finding* a __main__.py from outside sys.path[0] in this case, we just need to keep it from *running* it.
That means that after we find the candidate module spec for __main__, we can introduce a new constraint:
if os.path.commonpath([sys.path[0], spec.origin]) != sys.path[0]:
raise RuntimeError(...)
It might still be a little fiddly to decide exactly when to enforce the constraint, but it should still be much easier than attempting to constrain the search for the spec directly. |
|
Date |
User |
Action |
Args |
2017-07-26 14:45:35 | ncoghlan | set | recipients:
+ ncoghlan, brett.cannon, vstinner, eric.snow, serhiy.storchaka |
2017-07-26 14:45:35 | ncoghlan | set | messageid: <1501080335.32.0.66947337459.issue31038@psf.upfronthosting.co.za> |
2017-07-26 14:45:35 | ncoghlan | link | issue31038 messages |
2017-07-26 14:45:35 | ncoghlan | create | |
|