Index: Lib/idlelib/PyShell.py =================================================================== --- Lib/idlelib/PyShell.py (revision 69550) +++ Lib/idlelib/PyShell.py (working copy) @@ -345,6 +345,9 @@ rpcclt = None rpcpid = None + def set_startup_filename(self, path): # mlm@acm.org, 2009-02-10, + self.startup_filename = path # for restarts + def spawn_subprocess(self): args = self.subprocess_arglist self.rpcpid = os.spawnv(os.P_NOWAIT, sys.executable, args) @@ -434,6 +437,9 @@ console.write(halfbar + ' RESTART ' + halfbar) console.text.mark_set("restart", "end-1c") console.text.mark_gravity("restart", "left") + if self.startup_filename and os.path.isfile(self.startup_filename): + # mlm@acm.org, 2009-02-10: run startup file on each restart + self.execfile(self.startup_filename) console.showprompt() # restart subprocess debugger if debug: @@ -1230,9 +1236,9 @@ usage_msg = """\ -USAGE: idle [-deins] [-t title] [file]* - idle [-dns] [-t title] (-c cmd | -r file) [arg]* - idle [-dns] [-t title] - [arg]* +USAGE: idle [-dein] [-q | -s file] [-t title] [file]* + idle [-dn [-q | -s file] [-t title] (-c cmd | -r file) [arg]* + idle [-dn] [-q | -s file] [-t title] - [arg]* -h print this help message and exit -n run IDLE without a subprocess (see Help/IDLE Help for details) @@ -1248,7 +1254,9 @@ -r file run script from file -d enable the debugger - -s run $IDLESTARTUP or $PYTHONSTARTUP before anything else + -s file run file in place of $IDLESTARTUP or $PYTHONSTARTUP before + anything else and whenever the interpreter restarts + -q do NOT run $IDLESTARTUP or $PYTHONSTARTUP -t title set title of shell window A default edit window will be bypassed when -c, -r, or - are used. @@ -1257,24 +1265,26 @@ Examples: +[All run $IDLESTARTUP or $PYTHONSTARTUP before anything else unless +-q or -s is specified.] + idle Open an edit window or shell depending on IDLE's configuration. idle foo.py foobar.py Edit the files, also open a shell if configured to start with shell. -idle -est "Baz" foo.py - Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell - window with the title "Baz". +idle -et "Baz" foo.py + edit foo.py, and open a shell window with the title "Baz". idle -c "import sys; print(sys.argv)" "foo" Open a shell window and run the command, passing "-c" in sys.argv[0] and "foo" in sys.argv[1]. -idle -d -s -r foo.py "Hello World" - Open a shell window, run a startup script, enable the debugger, and - run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in - sys.argv[1]. +idle -d -s startup.py -r foo.py "Hello World" + Open a shell window, run startup.py instead of $IDLESTARTUP or + $PYTHONSTARTUP, enable the debugger, and run foo.py, passing + "foo.py" in sys.argv[0] and "Hello World" in sys.argv[1]. echo "import sys; print(sys.argv)" | idle - "foobar" Open a shell window, run the script piped in, passing '' in sys.argv[0] @@ -1290,9 +1300,12 @@ debug = False cmd = None script = None - startup = False + startup_filename = os.environ.get("IDLESTARTUP") or \ + os.environ.get("PYTHONSTARTUP") + # -q suppresses; -s specifies alternate; mlm@acm.org, 2009-02-10 try: - opts, args = getopt.getopt(sys.argv[1:], "c:deihnr:st:") + opts, args = getopt.getopt(sys.argv[1:], "c:deihnqr:s:t:") + except getopt.error as msg: sys.stderr.write("Error: %s\n" % str(msg)) sys.stderr.write(usage_msg) @@ -1313,6 +1326,10 @@ enable_shell = True if o == '-n': use_subprocess = False + if o == '-q': # mlm@acm.org, 2009-02-10: + if '-s' in sys.argv: # suppress $IDLESTARTUP/$PYTHONSTARTUP + raise GetOptError('options -q and -s cannot both be specified') + startup_filename = None if o == '-r': script = a if os.path.isfile(script): @@ -1321,8 +1338,12 @@ print("No script file: ", script) sys.exit() enable_shell = True - if o == '-s': - startup = True + if o == '-s': # mlm@acm.org, 2009-02-10: default changed to run + # $IDLESTARTUP or $PYTHONSTARTUP; -s takes an argument + # which is the path to an alternate startup file. + if '-q' in sys.argv: + raise GetOptError('options -s and -q cannot both be specified') + startup_filename = a enable_shell = True if o == '-t': PyShell.shell_title = a @@ -1387,11 +1408,10 @@ # handle remaining options: if debug: shell.open_debugger() - if startup: - filename = os.environ.get("IDLESTARTUP") or \ - os.environ.get("PYTHONSTARTUP") - if filename and os.path.isfile(filename): - shell.interp.execfile(filename) + if startup_filename: + shell.interp.set_startup_filename(startup_filename) # for restarts + if os.path.isfile(startup_filename): # mlm@acm.org, 2009-02-10 + shell.interp.execfile(startup_filename) if shell and cmd or script: shell.interp.runcommand("""if 1: import sys as _sys