[pypy-svn] r39947 - in pypy/dist/pypy: bin translator/goal

ac at codespeak.net ac at codespeak.net
Mon Mar 5 11:10:06 CET 2007


Author: ac
Date: Mon Mar  5 11:10:05 2007
New Revision: 39947

Modified:
   pypy/dist/pypy/bin/py.py
   pypy/dist/pypy/translator/goal/app_main.py
Log:
Add support for PYTHONSTARTUP environment variable.

Modified: pypy/dist/pypy/bin/py.py
==============================================================================
--- pypy/dist/pypy/bin/py.py	(original)
+++ pypy/dist/pypy/bin/py.py	Mon Mar  5 11:10:05 2007
@@ -46,9 +46,19 @@
             import site
         except:
             import sys
-            print >> sys.stderr, "import site' failed"
+            print >> sys.stderr, "import site\' failed"
 ''').interphook('pypy_init')
 
+def getenv_w(space, name):
+    w_os = space.getbuiltinmodule('os')
+    w_environ = space.getattr(w_os, space.wrap('environ'))
+    w_v = space.call_method(w_environ, 'get', space.wrap(name))
+    try:
+        return space.str_w(w_v)
+    except:
+        return None
+
+
 def main_(argv=None):
     starttime = time.time()
     config, parser = option.get_standard_options()
@@ -111,7 +121,14 @@
                 exit_status = 1
 
             # start the interactive console
-            if go_interactive:
+            if go_interactive or getenv_w(space, 'PYTHONINSPECT'):
+                python_startup = getenv_w(space, 'PYTHONSTARTUP')
+                if python_startup:
+                    try:
+                        main.run_file(python_startup, space=space)
+                    except:
+                        pass
+                    
                 con = interactive.PyPyConsole(
                     space, verbose=interactiveconfig.verbose,
                     completer=interactiveconfig.completer)

Modified: pypy/dist/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/dist/pypy/translator/goal/app_main.py	(original)
+++ pypy/dist/pypy/translator/goal/app_main.py	Mon Mar  5 11:10:05 2007
@@ -267,7 +267,14 @@
         else: 
             sys.argv.append('')
             go_interactive = True
+            
         if go_interactive or os.environ.get('PYTHONINSPECT'):
+            python_startup = os.environ.get('PYTHONSTARTUP')
+            if python_startup:
+                try:
+                    execfile(python_startup, mainmodule.__dict__)
+                except:
+                    pass
             print >> sys.stderr, "debug: importing code" 
             import code
             print >> sys.stderr, "debug: calling code.interact()"



More information about the Pypy-commit mailing list