classification
Title: Specify interpreter when running in IDLE
Type: enhancement Stage: resolved
Components: IDLE Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: lordmauve, terry.reedy
Priority: normal Keywords:

Created on 2015-07-25 10:40 by lordmauve, last changed 2017-06-20 22:39 by terry.reedy. This issue is now closed.

Messages (3)
msg247337 - (view) Author: Daniel Pope (lordmauve) * Date: 2015-07-25 10:40
I maintain a library called Pygame Zero which allows beginner programmers to start writing games without lines of boilerplate importing libraries, creating event loops and so on.

To support these features, Pygame Zero provides the 'pgzrun' command:

    pgzrun <script>

(or if you prefer, 'python -m pgzero <script>')

Any workarounds for this, to make games written with this framework run directly in IDLE, would detract from its "zero-boilerplate" approach.

I believe this is similar to, but different from #5680, which is about supplying sys.argv to the running process; this is about switching out interpreter entirely.

This issue corresponds to an issue in the Pygame Zero tracker:

https://bitbucket.org/lordmauve/pgzero/issues/23/add-a-way-of-invoking-pgzrun-on-the
msg247776 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-31 21:57
I have in mind the idea of enhancing run module options.  In particular, I think there should be a "Run in console" option ("python -i -m <file>".  However I do not understand exactly what you would want.

I believe you could now write an extension that would add 'pgzrun' to the Run menu and define a function bound to that entry that would call subprocess with "python -m pgzero <script>".  Error tracebacks (and print() output, but games should not do such) would appear in the console menu instead of Idle's Shell.  You could add '-i' to the invocation for post-mortem investigation.

Idle *simulates* running a file with "python -i -m <script>".  What it actually does (on Windows) is "pythonw -m .../idlelib/run.py".  The editor contents are compiled in the Idle process. The code must be complete at this time.  For tracebacks to work properly, it must be the same as displayed in the editor, so adding an import line is a bad idea. 

If both the process invocation and compile work, the code object is sent to the process and exec'ed in a pseudo-main namespace.  Output to stdout/err is sent back to Shell.  The only interpreter option I see here is run a different version of python and run.py (not trivial).

The user process should import site.py and if present, sitecustomize  and maybe a 'usercustomize'.  I am not familiar with these but you could investigate.

I do not see the point of an absolute zero boilerplate requirement. Kids manage with "from turtle import *" and anyone should be able to deal with "from pgz import *".  Avoiding even that given people a wrong impression of what a proper python file looks like and creates trouble that I see as unnecessary.

Since the solution to your problem seems to be a custom extension, patch, or use of the site module, I am inclined to close this.
msg296496 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-06-20 22:39
From your post, it was unclear to me what you are actually asking for.  From reading the bitbucket thread, it appears that you want something I cannot give you -- a built-in privileged position in IDLE.  However, as I said before, you can write a pgz extension.  An extension can add a menu entry and get a reference to the editor's tk Text widget.  It would be easy to write one that added needed boilerplate at the top and bottom of a file so that it is ready to run with F5.  The top part could end with
# Ignore everything above this line.
and the bottom part start with
# Ignore everything below this line.
With more effort, you could do probably do more to hide the boilerplate, but as I explained before, I have no motivation for that.
History
Date User Action Args
2017-06-20 22:39:40terry.reedysetstatus: open -> closed
messages: + msg296496

assignee: terry.reedy
resolution: rejected
stage: resolved
2015-07-31 21:57:57terry.reedysetnosy: + terry.reedy
messages: + msg247776
2015-07-25 10:40:59lordmauvecreate