Commit b6eeef41 authored by Terry Jan Reedy's avatar Terry Jan Reedy

Issue #8515: Set __file__ when run file in IDLE. Backport 2c276d0553ff by

Andrew Svetlov, based on initial patch by Bruce Frederiksen.
parent d1caae86
...@@ -152,16 +152,16 @@ class ScriptBinding: ...@@ -152,16 +152,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.
......
...@@ -317,6 +317,7 @@ Doug Fort ...@@ -317,6 +317,7 @@ Doug Fort
John Fouhy John Fouhy
Stefan Franke Stefan Franke
Martin Franklin Martin Franklin
Bruce Frederiksen
Robin Friedrich Robin Friedrich
Bradley Froehle Bradley Froehle
Ivan Frohne Ivan Frohne
......
...@@ -73,6 +73,9 @@ Build ...@@ -73,6 +73,9 @@ Build
IDLE IDLE
---- ----
- Issue #8515: Set __file__ when run file in IDLE.
Initial patch by Bruce Frederiksen.
- Issue #5492: Avoid traceback when exiting IDLE caused by a race condition. - Issue #5492: Avoid traceback when exiting IDLE caused by a race condition.
- Issue #17511: Keep IDLE find dialog open after clicking "Find Next". - Issue #17511: Keep IDLE find dialog open after clicking "Find Next".
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment