Author zaytsev
Recipients acdha, zaytsev
Date 2014-01-07.16:38:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1389112711.04.0.0491878764522.issue20164@psf.upfronthosting.co.za>
In-reply-to
Content
Amusingly, it's also the case on BG/Q compute nodes. Only this morning, I cooked up the following patch:

--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -237,7 +237,11 @@ def expanduser(path):
     if i == 1:
         if 'HOME' not in os.environ:
             import pwd
-            userhome = pwd.getpwuid(os.getuid()).pw_dir
+            try:
+                userhome = pwd.getpwuid(os.getuid()).pw_dir
+            except KeyError:
+                import warnings
+                warnings.warn('Unable to auto-detect $HOME, export it or functionality such as user-installed modules will not work!', RuntimeWarning)
         else:
             userhome = os.environ['HOME']
     else:

I think it's a bit harsh to fail completely, but returning silently also doesn't sound like a good idea, so I decided to issue a warning instead; the wording should be probably tweaked by a native speaker of English though.

What do you think?
History
Date User Action Args
2014-01-07 16:38:31zaytsevsetrecipients: + zaytsev, acdha
2014-01-07 16:38:31zaytsevsetmessageid: <1389112711.04.0.0491878764522.issue20164@psf.upfronthosting.co.za>
2014-01-07 16:38:31zaytsevlinkissue20164 messages
2014-01-07 16:38:30zaytsevcreate