amoffat/pbs — Issue #13: Does not work when imported from compiled-only modules
Author: encukou
Created: 2012-01-30 19:54:43+00:00
State: open

Because pbs assumes that the module that first imports comes from a readable `.py` file, it won't work when imported from modules where there's only a `.pyc`. For example:

test_a.py:

import test_b
test_b.main()

test_b.py:

from pbs import echo
def main():
echo('Hello world!')

Run `python test_a.py` once, then delete `python test_b.py` (leaving only `python test_b.pyc`). Now, running `test_a.py` will crash:

Traceback (most recent call last):
File "test_a.py", line 2, in
import test_b
File "/home/me/pbs/test_b.py", line 2, in
File "/home/me/pbs/pbs.py", line 419, in
with open(script, "r") as h: source = h.readlines()
IOError: [Errno 2] No such file or directory: '/home/me/pbs/test_b.py'

This could come up when a program is packaged somehow (e.g. frozen in a zip file).

----

All in all, the magic here is pretty fragile and will undoubtedly fail in other mysterious ways.
Maybe disallowing `import *` and allowing the above instead (and also import from the REPL) would be the lesser evil?