[issue8515] idle "Run Module" (F5) does not set __file__ variable

2013-06-30 Thread Roundup Robot

Roundup Robot added the comment:

New changeset a958b7f16a7d by Terry Jan Reedy in branch '2.7':
Issue #8515: Set __file__ when run file in IDLE. Backport 2c276d0553ff by
http://hg.python.org/cpython/rev/a958b7f16a7d

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8515] idle "Run Module" (F5) does not set __file__ variable

2012-04-05 Thread Andrew Svetlov

Andrew Svetlov  added the comment:

Thanks to all.
Bruce Frederiksen, you are mentioned in Misc/ACK

Tal Einat, if you want to make a patch which will use `execfile` instead of 
current approach — you are welcome. Please file new issue.

--
assignee:  -> asvetlov
resolution:  -> fixed
stage:  -> committed/rejected
status: open -> closed
versions:  -Python 2.7, Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8515] idle "Run Module" (F5) does not set __file__ variable

2012-04-05 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset 2c276d0553ff by Andrew Svetlov in branch 'default':
Issue #8515: Set __file__ when run file in IDLE.
http://hg.python.org/cpython/rev/2c276d0553ff

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8515] idle "Run Module" (F5) does not set __file__ variable

2012-03-31 Thread Andrew Svetlov

Changes by Andrew Svetlov :


--
nosy: +asvetlov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8515] idle "Run Module" (F5) does not set __file__ variable

2011-12-08 Thread Roger Serwy

Roger Serwy  added the comment:

I've encountered this bug several times myself. I applied this patch and it 
corrects the issue.

--
nosy: +serwy
versions: +Python 2.7, Python 3.2, Python 3.3 -Python 2.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8515] idle "Run Module" (F5) does not set __file__ variable

2010-06-11 Thread Tal Einat

Tal Einat  added the comment:

Why doesn't execfile() set __file__? I would be surprised if this is due to an 
oversight by the Python devs. In both execfile and IDLE's "Run Module" I can't 
think of a reason not to set __file__, but perhaps this was intentional? 
Googling a bit hasn't brought up much.

I am currently of the opinion that both IDLE and execfile() should set __file__ 
(with execfile() perhaps requiring more thinking about edge-cases, since it can 
be passes locals and globals dictionaries).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8515] idle "Run Module" (F5) does not set __file__ variable

2010-06-11 Thread Éric Araujo

Changes by Éric Araujo :


Removed file: http://bugs.python.org/file17632/unnamed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8515] idle "Run Module" (F5) does not set __file__ variable

2010-06-11 Thread Bruce Frederiksen

Bruce Frederiksen  added the comment:

No, IDLE compiles the module (with the 'compile' built-in using the 'exec'
option) and then does an 'exec' on the code (in PyShell.py).  It has several
lines of code that it runs before this exec to prepare the environment that
the code is run in.  It appears to be an oversight that the __file__
variable is not being set as a part of this preparation code to match the
behavior of the python CLI.  The patch that I included only changes one line
of this preparation code to also set the __file__ variable and that fixes
the problem.  If you examine the IDLE code in the immediate vicinity of my
patch you will see this.

I have several use cases where I'm relying on the __file__ variable in my
module so that it can find other non .py files that it needs in the same
directory that it's in.  This works under all combinations of uses from the
CLI, but fails in IDLE using Run Module.

The language reference
manualstates
under "Module":

Predefined (writable) attributes: __name__ is the module’s name; __doc__ is
> the module’s documentation string, or None if unavailable; __file__ is the
> pathname of the file from which the module was loaded, if it was loaded from
> a file. The __file__ attribute is not present for C modules that are
> statically linked into the interpreter; for extension modules loaded
> dynamically from a shared library, it is the pathname of the shared library
> file.
>

The python CLI honors this definition in all cases, but IDLE/Run Module does
not.

On Fri, Jun 11, 2010 at 11:11 AM, Tal Einat  wrote:

>
> Tal Einat  added the comment:
>
> I believe IDLE runs modules via execfile(), so I would expect the behavior
> to be similar, and execfile() does not set __file__. Doing "Run Module" is
> also IMO equivalent to doing execfile(), so this behavior retains
> consistency.
>
> However, I would expect __file__ to be set when running IDLE -r 

[issue8515] idle "Run Module" (F5) does not set __file__ variable

2010-06-11 Thread Tal Einat

Tal Einat  added the comment:

I believe IDLE runs modules via execfile(), so I would expect the behavior to 
be similar, and execfile() does not set __file__. Doing "Run Module" is also 
IMO equivalent to doing execfile(), so this behavior retains consistency.

However, I would expect __file__ to be set when running IDLE -r 

[issue8515] idle "Run Module" (F5) does not set __file__ variable

2010-04-23 Thread Bruce Frederiksen

New submission from Bruce Frederiksen :

The python CLI always sets the __file__ variable, whether run as:

$ python foobar.py

or

$ python -m foobar

or

$ python
>>> import foobar   # __file__ set in foobar module

The idle program sets the __file__ variable properly when you do the import 
from the idle shell, but __file__ is not set with the "Run Module" (F5) command 
from the editor.

I've included a patch file to set __file__, but it doesn't del it after the 
module has run.  But maybe this is OK, because the os.chdir is not undone 
either???

--
components: IDLE
files: idle.patch
keywords: patch
messages: 104066
nosy: dangyogi
severity: normal
status: open
title: idle "Run Module" (F5) does not set __file__ variable
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file17062/idle.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com