Issue #8515: Set __file__ when run file in IDLE.

This commit is contained in:
Andrew Svetlov 2012-04-05 21:54:39 +03:00
parent 0130ad14dd
commit dfe980bb82
4 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,9 @@
What's New in IDLE 3.3? What's New in IDLE 3.3?
========================= =========================
- Issue #8515: Set __file__ when run file in IDLE.
Initial patch by Bruce Frederiksen.
- IDLE can be launched as `python -m idlelib` - IDLE can be launched as `python -m idlelib`
- Issue #14409: IDLE now properly executes commands in the Shell window - Issue #14409: IDLE now properly executes commands in the Shell window

View File

@ -150,16 +150,16 @@ class ScriptBinding:
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
# XXX Too often this discards arguments the user just set... # XXX Too often this discards arguments the user just set...
interp.runcommand("""if 1: interp.runcommand("""if 1:
_filename = %r __file__ = {filename!r}
import sys as _sys import sys as _sys
from os.path import basename as _basename from os.path import basename as _basename
if (not _sys.argv or if (not _sys.argv or
_basename(_sys.argv[0]) != _basename(_filename)): _basename(_sys.argv[0]) != _basename(__file__)):
_sys.argv = [_filename] _sys.argv = [__file__]
import os as _os import os as _os
_os.chdir(%r) _os.chdir({dirname!r})
del _filename, _sys, _basename, _os del _sys, _basename, _os
\n""" % (filename, dirname)) \n""".format(filename=filename, dirname=dirname))
interp.prepend_syspath(filename) interp.prepend_syspath(filename)
# XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
# go to __stderr__. With subprocess, they go to the shell. # go to __stderr__. With subprocess, they go to the shell.

View File

@ -333,6 +333,7 @@ Doug Fort
John Fouhy John Fouhy
Andrew Francis Andrew Francis
Martin Franklin Martin Franklin
Bruce Frederiksen
Robin Friedrich Robin Friedrich
Ivan Frohne Ivan Frohne
Matthias Fuchs Matthias Fuchs

View File

@ -19,6 +19,9 @@ Core and Builtins
Library Library
------- -------
- Issue #8515: Set __file__ when run file in IDLE.
Initial patch by Bruce Frederiksen.
- Issue #14496: Fix wrong name in idlelib/tabbedpages.py. - Issue #14496: Fix wrong name in idlelib/tabbedpages.py.
Patch by Popa Claudiu. Patch by Popa Claudiu.