-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
bpo-32984: IDLE - set __file__ for startup files #5981
Conversation
Lib/idlelib/pyshell.py
Outdated
@@ -635,6 +635,9 @@ def execfile(self, filename, source=None): | |||
if source is None: | |||
with tokenize.open(filename) as fp: | |||
source = fp.read() | |||
if use_subprocess: | |||
source = (f"__file__ = r'{os.path.abspath(filename)}'\n" + | |||
source + "\ndel __file__") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives a SyntaxError if there's an unescaped quote in the path or file name (such as /home/cheryl's/tests/
).
Using triple quotes works:
f"__file__ = r'''{os.path.abspath(filename)}'''\n"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. Changed.
input prompt. For IDLE, -s runs a file named in environmental variable | ||
IDLESTARTUP or PYTHONSTARTUP; -r file runs file. Python sets __file__ to | ||
the startup file name before running the file and unsets it before the first | ||
prompt. IDLE now does the same when run normally, without the -n option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set __file__
while running a startup file. Like Python, IDLE optionally
runs one startup file in the Shell window before presenting the first
interactive input prompt. For IDLE, -s
runs a file named in
environmental variable :envvar:IDLESTARTUP
or :envvar:PYTHONSTARTUP
;
-r
file runs file. Python sets __file__
to the startup file
name before running the file and unsets it before the first prompt. IDLE now
does the same when run normally, without the -n
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. by 'editing', I could see and copy the markup (and maybe learn better). I changed one clause to -r file
runs file
, which I can preview here ;-).
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup file name before running the file and unsets it before the first prompt. IDLE now does the same when run normally, without the -n option. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
GH-5986 is a backport of this pull request to the 3.7 branch. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup file name before running the file and unsets it before the first prompt. IDLE now does the same when run normally, without the -n option. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
GH-5987 is a backport of this pull request to the 3.6 branch. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup file name before running the file and unsets it before the first prompt. IDLE now does the same when run normally, without the -n option. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup file name before running the file and unsets it before the first prompt. IDLE now does the same when run normally, without the -n option. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
GH-5993 is a backport of this pull request to the 3.6 branch. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup file name before running the file and unsets it before the first prompt. IDLE now does the same when run normally, without the -n option. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or PYTHONSTARTUP; -r file runs file. Python sets __file__ to the startup file name before running the file and unsets it before the first prompt. IDLE now does the same when run normally, without the -n option.
https://bugs.python.org/issue32984