|
msg337683 - (view) |
Author: Anthony Sottile (Anthony Sottile) * |
Date: 2019-03-11 16:09 |
The current code for `os.path.expanduser` in `ntpath` uses `HOME` in preference to `USERPROFILE` / `HOMEDRIVE\\HOMEPATH`
I can't find any documentation of `HOME` being relevant on windows (only on posix). For example, wikipedia only mentions `USERPROFILE` / `HOMEDRIVE\\HOMEPATH` options: https://en.wikipedia.org/wiki/Home_directory#Default_home_directory_per_operating_system
Seems to be (one of) the direct causes of a downstream bug for me: https://github.com/pre-commit/pre-commit/issues/960
(msys sets `HOME` to a bogus value if `HOMEDRIVE` is set, then python uses it)
My proposal is to remove these lines and change the `elif` to an `if`:
https://github.com/python/cpython/blob/d9bd8ec2a40ea67bc4248a72943a409ee645ddf3/Lib/ntpath.py#L302-L304
|
|
msg337750 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2019-03-12 15:17 |
I like the patch, but I'm not sure all the tests are properly preserving the real value of USERPROFILE.
Modifying this value could have a real impact on the rest of the process, so we should be very careful to undo it regardless of test result. (Modifying HOME is not a as big a deal since, as you point out, it's not "real" ;) )
Also, it's probably better to get the current value and check against that, rather than setting it to a known value. One day we might do the right thing and switch expanduser() from the environment variables to the correct API, which would break the test.
|
|
msg337752 - (view) |
Author: Anthony Sottile (Anthony Sottile) * |
Date: 2019-03-12 15:28 |
> Modifying this value could have a real impact on the rest of the process, so we should be very careful to undo it regardless of test result. (Modifying HOME is not a as big a deal since, as you point out, it's not "real" ;) )
Agreed, though I'd like to write it off as an existing problem (if it is a problem, it looks to me like the tests are doing proper environment cleanup). If they are broken, they'd already be leaking environment variables on posix since these tests run on both
Auditing the tests I modified:
- test_netrc: uses `with support.EnvironmentVarGuard() as environ:` (OK!)
- test_ntpath: uses `with support.EnvironmentVarGuard() as env:` (OK!)
- test_dist: `MetadataTestCase` extends `support.EnvironGuard` (OK!)
- test_config: `BasePyPIRCCommandTestCase` extends `support.EnvironGuard` (OK!)
so actually, looks like this is already good to go on that front!
Definitely agree on using the true value in the long term -- I'd like to defer that until that's actually happening though as it'll be a much more involved patch!
|
|
msg337754 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2019-03-12 15:39 |
Great, thanks for checking! I'll merge.
|
|
msg337755 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2019-03-12 15:40 |
New changeset 25ec4a45dcc36c8087f93bd1634b311613244fc6 by Steve Dower (Anthony Sottile) in branch 'master':
bpo-36264: Don't honor POSIX HOME in os.path.expanduser on Windows (GH-12282)
https://github.com/python/cpython/commit/25ec4a45dcc36c8087f93bd1634b311613244fc6
|
|
msg337756 - (view) |
Author: Zachary Ware (zach.ware) *  |
Date: 2019-03-12 15:42 |
If we're going ahead with this, it's worth a mention in whatsnew as this is going to break things for some users.
|
|
msg337763 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2019-03-12 15:54 |
> If we're going ahead with this, it's worth a mention in whatsnew
Good call. I'll do it
|
|
msg337781 - (view) |
Author: Eryk Sun (eryksun) *  |
Date: 2019-03-12 18:01 |
> `os.path.expanduser` in `ntpath` uses `HOME` in preference to
> `USERPROFILE` / `HOMEDRIVE\\HOMEPATH`
Guido intentionally added support for HOME in ntpath.expanduser way back in Python 1.5 (circa 1997), and now we're removing it over 20 years later. I expect this to break some deployments, but it's not a serious problem.
My feeling here is "meh". Practically all use of expanduser() is dubious in Windows, varying from going against convention to being completely wrong. We're long due for a module in the standard library that abstracts access to platform-specific configuration and special directories, but attempts to adopt one keep losing momentum. I guess it's too prone to bike shedding and arguments.
|
|
msg337784 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2019-03-12 18:33 |
> Guido intentionally added support for HOME in ntpath.expanduser way back in Python 1.5 (circa 1997), and now we're removing it over 20 years later.
Wouldn't be the first thing to be removed :)
|
|
msg337813 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2019-03-12 22:15 |
New changeset 8ef864d50fb847cf15d5717c0db04fd60fb13d8d by Steve Dower in branch 'master':
bpo-36264: Updates documentation for change to expanduser on Windows (GH-12294)
https://github.com/python/cpython/commit/8ef864d50fb847cf15d5717c0db04fd60fb13d8d
|
|
msg338162 - (view) |
Author: daniel hahler (blueyed) * |
Date: 2019-03-18 05:50 |
Just as a sidenote: the other day I was checking Python's source to see how to override a user's home (in tests, when os.path.expanduser` is used in code), and found it easy to just set $HOME in the environment in the end.
I guess this change will cause quite some regressions in this regard - even though $HOME might not be used in practice on Windows.
|
|
msg357182 - (view) |
Author: Christoph Reiter (lazka) * |
Date: 2019-11-21 16:34 |
Was pathlib forgotten here? Pathlib.home() is documented to return the same as expanduser("~") but it still prefers HOME instead of USERPROFILE.
Note that this change has some effect on cygwin/mingw environments which all set HOME and now potentially lead to programs no longer being able to find their config files. Not that I disagree with this change, just that it seems a bit rushed to me.
|
|
msg357192 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2019-11-21 18:17 |
> Was pathlib forgotten here? Pathlib.home() is documented to return the same as expanduser("~") but it still prefers HOME instead of USERPROFILE.
Yes, it was forgotten (why doesn't it just use expanduser?). We should file a new bug for that.
> Note that this change has some effect on cygwin/mingw environments which all set HOME and now potentially lead to programs no longer being able to find their config files.
Firstly these are not supported environments, so it's not "rushed" for us to not preemptively consider them (though we'll happily merge most PRs that fix them without impacting supported environments).
And I thought the idea was that they'd use posixpath as os.path rather than ntpath? Cygwin in particular, which provides the full environment. MinGW is a bit lighter to be closer to normal Windows behaviour, which would suggest that using the Windows variables is preferable.
|
|
msg357194 - (view) |
Author: Christoph Reiter (lazka) * |
Date: 2019-11-21 18:36 |
> Was pathlib forgotten here? Pathlib.home() is documented to return
> the same as expanduser("~") but it still prefers HOME instead of
> USERPROFILE.
>
> Yes, it was forgotten (why doesn't it just use expanduser?). We
> should file a new bug for that.
I'll file one.
> > Note that this change has some effect on cygwin/mingw environments
> which all set HOME and now potentially lead to programs no longer
> being able to find their config files.
>
> Firstly these are not supported environments, so it's not "rushed"
> for us to not preemptively consider them (though we'll happily merge
> most PRs that fix them without impacting supported environments).
Yeah, you're right, sorry, my comment wasn't appropriate.
> And I thought the idea was that they'd use posixpath as os.path
> rather than ntpath? Cygwin in particular, which provides the full
> environment. MinGW is a bit lighter to be closer to normal Windows
> behaviour, which would suggest that using the Windows variables is
> preferable.
I meant executing Python scripts with official Python in bash on Windows which sets HOME. But I just checked with "git for Windows" and it sets HOME to USERPROFILE anyway, so that might only affect cygwin/msys2 which have their own user dir.
|
|
msg357197 - (view) |
Author: Christoph Reiter (lazka) * |
Date: 2019-11-21 18:45 |
I've filed issue38883
|
|
msg360846 - (view) |
Author: Steve Dower (steve.dower) *  |
Date: 2020-01-28 09:42 |
New changeset c45a2aa9e255b5c7c211faa79f6b23895b64ab27 by Steve Dower (Christoph Reiter) in branch 'master':
bpo-38883: Don't use POSIX `$HOME` in `pathlib.Path.home/expanduser` on Windows (GH-17961)
https://github.com/python/cpython/commit/c45a2aa9e255b5c7c211faa79f6b23895b64ab27
|
|
msg360853 - (view) |
Author: miss-islington (miss-islington) |
Date: 2020-01-28 09:59 |
New changeset 595b516965ee88b817dc1b3d7713e1f3f263634d by Miss Islington (bot) in branch '3.8':
bpo-38883: Don't use POSIX `$HOME` in `pathlib.Path.home/expanduser` on Windows (GH-17961)
https://github.com/python/cpython/commit/595b516965ee88b817dc1b3d7713e1f3f263634d
|
|
| Date |
User |
Action |
Args |
| 2020-01-28 09:59:47 | miss-islington | set | nosy:
+ miss-islington messages:
+ msg360853
|
| 2020-01-28 09:42:13 | miss-islington | set | pull_requests:
+ pull_request17609 |
| 2020-01-28 09:42:11 | steve.dower | set | messages:
+ msg360846 |
| 2020-01-12 09:23:37 | lazka | set | pull_requests:
+ pull_request17370 |
| 2019-11-21 18:45:40 | lazka | set | messages:
+ msg357197 |
| 2019-11-21 18:36:10 | lazka | set | messages:
+ msg357194 |
| 2019-11-21 18:17:34 | steve.dower | set | messages:
+ msg357192 |
| 2019-11-21 16:34:43 | lazka | set | nosy:
+ lazka messages:
+ msg357182
|
| 2019-03-18 05:50:30 | blueyed | set | nosy:
+ blueyed messages:
+ msg338162
|
| 2019-03-12 22:16:16 | steve.dower | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-03-12 22:15:29 | steve.dower | set | messages:
+ msg337813 |
| 2019-03-12 18:33:18 | steve.dower | set | messages:
+ msg337784 |
| 2019-03-12 18:01:18 | eryksun | set | nosy:
+ eryksun messages:
+ msg337781
|
| 2019-03-12 16:04:12 | steve.dower | set | pull_requests:
+ pull_request12273 |
| 2019-03-12 15:54:13 | steve.dower | set | messages:
+ msg337763 |
| 2019-03-12 15:42:13 | zach.ware | set | messages:
+ msg337756 |
| 2019-03-12 15:40:21 | steve.dower | set | messages:
+ msg337755 |
| 2019-03-12 15:39:21 | steve.dower | set | assignee: steve.dower messages:
+ msg337754 |
| 2019-03-12 15:28:40 | Anthony Sottile | set | messages:
+ msg337752 |
| 2019-03-12 15:17:55 | steve.dower | set | messages:
+ msg337750 |
| 2019-03-11 16:38:11 | Anthony Sottile | set | keywords:
+ patch stage: patch review pull_requests:
+ pull_request12262 |
| 2019-03-11 16:09:57 | Anthony Sottile | create | |