diff en/examples/run-example @ 172:5f305adeb584

Try to tighten up the run environment to make things more reproducible.
author Bryan O'Sullivan <bos@serpentine.com>
date Tue, 27 Mar 2007 15:04:47 -0700
parents f8b5b782e150
children 754312dc23d5
line wrap: on
line diff
--- a/en/examples/run-example	Mon Mar 26 23:57:58 2007 -0700
+++ b/en/examples/run-example	Tue Mar 27 15:04:47 2007 -0700
@@ -46,6 +46,13 @@
             raise
     return False
 
+def find_path_to(program):
+    for p in os.environ.get('PATH', os.defpath).split(os.pathsep):
+        name = os.path.join(p, program)
+        if os.access(name, os.X_OK):
+            return p
+    return None
+        
 class example:
     shell = '/usr/bin/env bash'
     ps1 = '__run_example_ps1__ '
@@ -147,6 +154,16 @@
         print >> rcfp, 'PS1="%s"' % self.ps1
         print >> rcfp, 'PS2="%s"' % self.ps2
         print >> rcfp, 'unset HISTFILE'
+        path = ['/usr/bin', '/bin']
+        hg = find_path_to('hg')
+        if hg and hg not in path:
+            path.append(hg)
+        def re_export(envar):
+            v = os.getenv(envar)
+            if v is not None:
+                print >> rcfp, 'export ' + envar + '=' + v
+        print >> rcfp, 'export PATH=' + ':'.join(path)
+        re_export('PYTHONPATH')
         print >> rcfp, 'export EXAMPLE_DIR="%s"' % os.getcwd()
         print >> rcfp, 'export HGMERGE=merge'
         print >> rcfp, 'export LANG=C'
@@ -160,8 +177,8 @@
         sys.stderr.flush()
         self.pid, self.cfd = pty.fork()
         if self.pid == 0:
-            cmdline = ['/usr/bin/env', 'bash', '--noediting', '--noprofile',
-                       '--norc']
+            cmdline = ['/usr/bin/env', '-i', 'bash', '--noediting',
+                       '--noprofile', '--norc']
             try:
                 os.execv(cmdline[0], cmdline)
             except OSError, err: