Ask Your Question
0

Customizing rosh initialization

asked 2011-07-01 06:58:12 -0500

bhaskara gravatar image

updated 2011-07-01 07:50:06 -0500

kwc gravatar image

I notice that rosh doesn't seem to exactly have the same initialization behavior as ipython. For example, in ~/.ipython/ipythonrc, I have the line: importmod os sys

So if I start ipython, I have the os module available in the interactive namespace. But with the same setup, starting rosh does not make those names available.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-07-01 07:46:35 -0500

kwc gravatar image

This is probably a bug in rosh. The rosh loader for the shell needs to import os and sys. In order to be 'clean', it then deletes os and sys.

Here's a patch that I think resolves this peculiarity (needs more testing):

diff -r 35d8b08984d6 shell.py
--- a/shell.py  Fri Jul 01 12:45:40 2011 -0700
+++ b/shell.py  Fri Jul 01 12:45:42 2011 -0700
@@ -10,6 +10,14 @@
 # import all symbols after initialization
 from rosh import *

+try:
+    cleanup_os = 'os' not in sys.modules
+    cleanup_sys = False
+except:
+    import sys
+    cleanup_os = 'os' not in sys.modules
+    cleanup_sys = True
+    
 import os, sys
 plugins = sys.argv[1:]

@@ -39,7 +47,9 @@
         del _f

 del plugins
-del sys
-del os
+if cleanup_sys:
+    del sys
+if cleanup_os:
+    del os
 del _roshrcp
 del _rosenv
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-07-01 06:58:12 -0500

Seen: 138 times

Last updated: Jul 01 '11