using ipython in Slicer3 show how os.environ['HOME'] is not defined #154

Closed
dmirota opened this Issue Sep 23, 2010 · 3 comments

Comments

Projects
None yet
2 participants
@dmirota

dmirota commented Sep 23, 2010

Currently in genutils.py at line 942 in ipython 0.10 ipython gives up trying to find the home directory which causes ipython to fail to load.

At this point ipython could still try a little harder to find a home directory with something like the following:

import subprocess
p = subprocess.Popen('echo $HOME',shell=True,stdout=subprocess.PIPE)
potential_home = p.communicate()[0].strip()
if len(potential_home) > 0:
     return potential_home
else:
    raise HomeDirError,'undefined $HOME, IPython can not proceed.'

I'm not too sure if this is a Slicer 3 ( http://www.slicer.org/ ) issue or a ipython issue so I'm creating a ticket in each project. The slicer ticket: http://na-mic.org/Mantis/view.php?id=985

This issue occurred on OS X 10.6.4, Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29), Slicer 3.6.1 rev 15021

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Oct 10, 2010

Member

Unfortunately the code you propose is posix-specific, and won't work on Windows. IPython is cross platform, so we need a platform-independent solution.

If you find one, by all means post it, the easiest way to have it merged is to make it as a pull request on github, but a patch on our -dev list or even here will be equally welcome.

Member

fperez commented Oct 10, 2010

Unfortunately the code you propose is posix-specific, and won't work on Windows. IPython is cross platform, so we need a platform-independent solution.

If you find one, by all means post it, the easiest way to have it merged is to make it as a pull request on github, but a patch on our -dev list or even here will be equally welcome.

@dmirota

This comment has been minimized.

Show comment
Hide comment
@dmirota

dmirota Oct 10, 2010

Yes, you are correct my proposal is posix-specific. That's why it's within the block which checks if the OS is posix. Here is a patch:

--- genutils.py 2009-08-04 19:26:20.000000000 -0400
+++ genutils.py 2010-09-23 16:34:45.000000000 -0400
@@ -940,7 +940,13 @@
         return homedir
     except KeyError:
         if os.name == 'posix':
-            raise HomeDirError,'undefined $HOME, IPython can not proceed.'
+            import subprocess
+            p = subprocess.Popen('echo $HOME',shell=True,stdout=subprocess.PIPE)
+            potential_home = p.communicate()[0].strip()
+            if len(potential_home) > 0:
+                return potential_home
+            else:
+                raise HomeDirError,'undefined $HOME, IPython can not proceed.'
         elif os.name == 'nt':
             # For some strange reason, win9x returns 'nt' for os.name.
             try:

dmirota commented Oct 10, 2010

Yes, you are correct my proposal is posix-specific. That's why it's within the block which checks if the OS is posix. Here is a patch:

--- genutils.py 2009-08-04 19:26:20.000000000 -0400
+++ genutils.py 2010-09-23 16:34:45.000000000 -0400
@@ -940,7 +940,13 @@
         return homedir
     except KeyError:
         if os.name == 'posix':
-            raise HomeDirError,'undefined $HOME, IPython can not proceed.'
+            import subprocess
+            p = subprocess.Popen('echo $HOME',shell=True,stdout=subprocess.PIPE)
+            potential_home = p.communicate()[0].strip()
+            if len(potential_home) > 0:
+                return potential_home
+            else:
+                raise HomeDirError,'undefined $HOME, IPython can not proceed.'
         elif os.name == 'nt':
             # For some strange reason, win9x returns 'nt' for os.name.
             try:
@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Mar 13, 2011

Member

Make last-ditch attempt to find $HOME when environment is broken.

Closed by 5a7eee9, thanks to gh user dmirota for report and patch.

Member

fperez commented Mar 13, 2011

Make last-ditch attempt to find $HOME when environment is broken.

Closed by 5a7eee9, thanks to gh user dmirota for report and patch.

markvoorhies pushed a commit to markvoorhies/ipython that referenced this issue Apr 21, 2011

Make last-ditch attempt to find $HOME when environment is broken.
Closes gh-154, thanks to gh user dmirota for report and patch.

minrk pushed a commit to minrk/ipython that referenced this issue Jul 1, 2013

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

Make last-ditch attempt to find $HOME when environment is broken.
Closes gh-154, thanks to gh user dmirota for report and patch.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment