Skip to content

bpython cannot run directories with __main__.py. #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gwk opened this issue Apr 29, 2015 · 7 comments
Open

bpython cannot run directories with __main__.py. #530

gwk opened this issue Apr 29, 2015 · 7 comments
Labels

Comments

@gwk
Copy link

gwk commented Apr 29, 2015

python can execute directories with __main__.py; bpython cannot but should. repro:

$ mkdir test
$ touch test/__main__.py
$ python test # ok.
$ python3 test # ok.
$ bpython3 test # fails.
Traceback (most recent call last):
  File "/usr/local/bin/bpython3", line 9, in <module>
    load_entry_point('bpython==0.15.dev106', 'console_scripts', 'bpython')()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bpython/curtsies.py", line 69, in main
    bpargs.exec_code(interp, exec_args)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bpython/args.py", line 113, in exec_code
    with open(args[0], 'r') as sourcefile:
IsADirectoryError: [Errno 21] Is a directory: 'test'
@gwk
Copy link
Author

gwk commented Apr 29, 2015

this fix is not complete; python3 evaluates __name__ == '__main__' in __main__.py to True; bpython does not.

i think you want to be using runpy.run_path if possible. i imagine this will give you correct behavior for things like running bytecode, zipped module dirs, etc.

here is a sample stack trace from python3 execution, indicating that runpy is used:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "boot/__main__.py", line 30, in <module>
    raise Exception()
Exception

@sebastinas
Copy link
Contributor

Thanks for the hint. I'll look into it.

@sebastinas
Copy link
Contributor

Unfortunately it's not an option until we decide to drop support for 2.6.

@sebastinas
Copy link
Contributor

It also requires major changes to the current main implementations of the frontends. Maybe we could execute with runpy and then inject the globals into our own interpreter.

sebastinas added a commit that referenced this issue Apr 30, 2015
@sebastinas sebastinas reopened this Apr 30, 2015
@sebastinas sebastinas added the bug label Apr 30, 2015
@sebastinas
Copy link
Contributor

After some testing I don't think that it's possible to use runpy. It breaks -i.

@thomasballinger
Copy link
Member

I thought about using runpy in #284 but ran into the same thing.

@gwk
Copy link
Author

gwk commented Apr 30, 2015

meaning that this would be a very intrusive change? python has its own -i option, so i wonder if reading that implementation works would be helpful. i imagine it could be a large undertaking, but the obvious benefit is that you will get the 'official' behavior now and in the future. @thomasballinger i'd be down to pair on looking at how this works in cpython sometime if you are interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants