[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
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

Merged
merged 3 commits into from Mar 5, 2018

Conversation

Copy link
Member

terryjreedy commented Mar 5, 2018

@@ -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__")
Copy link
Contributor

csabella Mar 5, 2018

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"

Copy link
Member Author

terryjreedy Mar 5, 2018

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.
Copy link
Contributor

csabella Mar 5, 2018

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.

Copy link
Member Author

terryjreedy Mar 5, 2018

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 ;-).

Copy link
Contributor

miss-islington commented Mar 5, 2018

Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒🤖

terryjreedy deleted the file-32984 branch Mar 5, 2018
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2018
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>
Copy link

bedevere-bot commented Mar 5, 2018

GH-5986 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2018
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>
Copy link

bedevere-bot commented Mar 5, 2018

GH-5987 is a backport of this pull request to the 3.6 branch.

miss-islington added a commit that referenced this pull request Mar 5, 2018
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>
Copy link
Contributor

miss-islington commented Mar 5, 2018

Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2018
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>
Copy link

bedevere-bot commented Mar 5, 2018

GH-5993 is a backport of this pull request to the 3.6 branch.

miss-islington added a commit that referenced this pull request Mar 5, 2018
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>
jo2y pushed a commit to jo2y/cpython that referenced this pull request Mar 23, 2018
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.
yahya-abou-imran pushed a commit to yahya-abou-imran/cpython that referenced this pull request Nov 2, 2018
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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants