classification
Title: expanduser("~") on Windows looks for HOME first
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: eldiener, georg.brandl, hdiwan650, schmir
Priority: normal Keywords:

Created on 2007-07-07 12:44 by eldiener, last changed 2007-09-07 07:38 by georg.brandl. This issue is now closed.

Messages (8)
msg32457 - (view) Author: Edward Diener (eldiener) Date: 2007-07-07 12:44
On Windows, using expanduser("~") the home directory is replaced either first by the environment variable HOME or, if that is not found, by a combination of HOMEDRIVE and HOMEPATH."

But HOME is almost never the home directory for Windows, although it is under Linux/Unix, only the combination of HOMEDRIVE and HOMEPATH is valid, which is always set. 

If MSYS is installed under Windows, where HOME must be set to the MSYS home directory for a given user in order to emulate Linux/Unix, attempting to use os.path.expanduser("~") will incorrectly return the MSYS home directory for a given user rather than the Windows home directory for the logged in user. So I think the os.path.expanduser("~") works incorrectly in this case and needs to be fixed, else you are telling users never to use MSYS under Windows. There may be other Linux/Unix emulation packages which can be installed under Windows, and my guess is that if there is then the HOME environment variable gets set to some user home directory under that emulation package, just like it does for MSYS.

The correct order under Windows is to look for the  environment variable combination HOMEDRIVE/HOMEPATH first and only if that is not found ( very unlikely ) should expanduser("~") look for the environment variable HOME.
msg32458 - (view) Author: Hasan Diwan (hdiwan650) Date: 2007-07-07 19:08
This has been fixed as of Rev 54419 in trunk, perhaps someone would be kind enough to backport it?
msg32459 - (view) Author: Hasan Diwan (hdiwan650) Date: 2007-07-07 19:10
This has been fixed as of Rev 54419 in trunk, perhaps someone would be kind enough to backport it?
msg32460 - (view) Author: Hasan Diwan (hdiwan650) Date: 2007-07-07 19:10
This has been fixed as of Rev 54419 in trunk, perhaps someone would be kind enough to backport it?
msg32461 - (view) Author: Hasan Diwan (hdiwan650) Date: 2007-07-07 19:11
This has been fixed as of Rev 54419 in trunk, perhaps someone would be kind enough to backport it?
msg32462 - (view) Author: Edward Diener (eldiener) Date: 2007-07-07 20:00
Let me just correct my original report to say that the fix should be HOMEDRIVE+HOMEPATH, which is probably already known.
msg55176 - (view) Author: Ralf Schmitt (schmir) Date: 2007-08-23 18:24
As a user of msys I would expect that python returns the value of HOME.
If I didn't start python from msys, HOME would either not be set, or I
had set in some windows dialog (and then I would expect python to also
use that).
msg55248 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-24 11:38
So if you don't "start" MSYS and just run Python, even if MSYS is
installed, HOME will not be set? In that case, I agree with schmir.
History
Date User Action Args
2007-09-07 07:38:56georg.brandlsetstatus: pending -> closed
2007-08-24 11:38:18georg.brandlsetstatus: open -> pending
resolution: wont fix
messages: + msg55248
nosy: + georg.brandl
2007-08-23 18:24:44schmirsetnosy: + schmir
messages: + msg55176
2007-07-07 12:44:10eldienercreate