diff --git a/IPython/utils/path.py b/IPython/utils/path.py index 5d53dbf..61d4c6a 100644 --- a/IPython/utils/path.py +++ b/IPython/utils/path.py @@ -177,7 +177,17 @@ def get_home_dir(): try: homedir = env['HOME'] except KeyError: - raise HomeDirError('Undefined $HOME, IPython cannot proceed.') + # Last-ditch attempt at finding a suitable $HOME, on systems where + # it may not be defined in the environment but the system shell + # still knows it - reported once as: + # https://github.com/ipython/ipython/issues/154 + from subprocess import Popen, PIPE + homedir = Popen('echo $HOME', shell=True, + stdout=PIPE).communicate()[0].strip() + if homedir: + return homedir.decode(sys.getfilesystemencoding()) + else: + raise HomeDirError('Undefined $HOME, IPython cannot proceed.') else: return homedir.decode(sys.getfilesystemencoding()) elif os.name == 'nt': diff --git a/IPython/utils/tests/test_path.py b/IPython/utils/tests/test_path.py index 332d4fb..1d5ab85 100644 --- a/IPython/utils/tests/test_path.py +++ b/IPython/utils/tests/test_path.py @@ -193,6 +193,7 @@ def test_get_home_dir_7(): env["HOMESHARE"] = abspath(HOME_TEST_DIR) home_dir = path.get_home_dir() nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) + # Should we stub wreg fully so we can run the test on all platforms? @skip_if_not_win32