Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork939
Commit9ac2438
committed
Handle encodings better; make the sum type "public"
Windows does not have a direct analogue of LANG=C or LC_ALL=C. Someprograms give them special treatment, but they do not affect theway localized behavior of the Windows API operates. In particular,the bash.exe WSL wrapper, as well as wsl.exe and wslconfig.exe, donot produce their own localized messages (for errors notoriginating in a running distribution) when they are set. Windowsalso provides significant localization through localized versionsof Windows, so changing language settings in Windows, evensystem-wide, does not always produce the same effect that many ormost Windows users who use a particular language would experience.Various encodings may appear when bash.exe is WSL-related but givesits own error message. Such a message is often in UTF-16LE, whichis what Windows uses internally, and preserves any localization.That is the more well behaved scenario and already was detected;this commit moves, but does not change, the code for that.The situation where it is not UTF-16LE was previously handled bytreating it as UTF-8. Because the default strict error treatmentwas used, this would error out in test discovery in some localizedsetups, preventing all tests in test_index from running, includingthe majority of them that are not related to hooks. This fixes thatby doing better detection that should decode the mesages correctlymost of the time, that should in practice decode them well enoughto tell (by the aka.ms URL) if the message is complaining aboutthere being no installed distribution all(?) of the time, and thatshould avoid breaking unrelated tests even if that can't be done.An English non-UTF-16LE message appears on GitHub Actions CI whenno distribution is installed. Testing of this situation on otherlanguages was performed in a virtual machine on a developmentmachine.That the message is output in a narrow character set some of thetime when bash.exe produces it appears to be a limitation of thebash.exe wrapper. In particular, with a zh-CN version of Windows(and with the language not changed to anything else), a localizedmessage in Simplified Chinese was correctly printed when runningwsl.exe, but running bash.exe produced literal "?" characters inplace of Chinese characters (it was not a display or font issue,and they were "?" and not Unicode replacement characters). Thechange here does not overcome that; the literal "?" characters willbe included. But "https://aka.ms/wslstore" is still present if itis an error about not having any distributions, so the correctstatus is still inferred.For more information on code pages in Windows, see:https://serverfault.com/a/836221The following alternatives to all or part of the approach takenhere were considered but, at least for now, not done, because theywould not clearly be simpler or more correct:- Abandoning this "run bash.exe and see what it shows us" approach altogether and instead reimplementing the rules CreateProcessW uses, to find if the bash.exe the system finds is the one in System32, and then, if so, checking the metadata in that executable to determine if it's the WSL wrapper. I believe that would be even more complex to do correctly than it seems; the behavior noted in the WinBashStatus docstring and recent commit messages is not the whole story. The documented search order for CreateProcessW seems not to be followed in some circumstances. One is that the Windows Store version of Python seems always to forgo the usual System32 search that precedes seaching directories in PATH. It looks like there may also be some subtleties in which directories 32-bit builds search in.- Using chardet. Although the chardet library is excellent, it is not clear that the code needed to bridge this highly specific use case to it would be simpler than the code currently in use. Some of the work might still need to be done by other means; when I tested it out for this, this did not detect the UTF-16LE messages as such for English. (They are often also valid UTF-8, because interleaving null characters is, while strange, permitted.)- Also calling wsl.exe and/or wslconfig.exe. It's still necessary to call bash.exe, because it may not be the WSL bash, even on a system with WSL fully set up. Furthermore, those tools' output seem to vary in some complex ways, too. Using only one subprocess for the detection seemed the simplest. Even using "wsl --list" would introduce significant additional logic. Sometimes its output is a list of distributions, sometimes it is an error message, and if WSL is not set up it may be a help message.- Using the Windows API to check for WSL systems.https://learn.microsoft.com/en-us/windows/win32/api/wslapi/ does not currently include functions to list registered distributions.- Attempting to get wsl.exe to produce an English message using Windows API techniques like those used in Locale Emulator. This would be complicated, somewhat unintuitive and error prone to do in Python, and I am not sure how well it would work on a system that does not have an English language pack installed.- Checking on disk for WSL distributions in the places they are most often expected to be. This would intertwine WinBashStatus with deep details of how WSL actually operates, and this seems like the sort of thing that is likely to change in the future.However, there may be a more straightforward way to do this (thatis at least as correct and that remains transparent to debug).Especially if the WinBashStatus class remains in test_index forlong (rather than just being used to aid in debugging existing testfalures and possible subsequent design decisions for making commithooks work more robustly on Windows in GitPython), then this maybe worth revisiting.Thus it is *not* with the intention of treating WinBashStatus as a"stable" part of the test suite that it is renamed from_WinBashStatus. This is instead done because:- Like HOOKS_SHEBANG, it makes sense to import it when figuring out how the tests work or debugging them.- When debugging, it is intended that it be imported to call check() and examine the resulting `process` and `message` information, at least in the CheckError case.1 parentd779a75 commit9ac2438
1 file changed
+54
-16
lines changedLines changed: 54 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
44 |
| - | |
| 44 | + | |
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 |
| |
49 | 52 |
| |
50 | 53 |
| |
| |||
84 | 87 |
| |
85 | 88 |
| |
86 | 89 |
| |
87 |
| - | |
88 |
| - | |
89 |
| - | |
90 |
| - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
91 | 94 |
| |
92 | 95 |
| |
93 | 96 |
| |
| |||
105 | 108 |
| |
106 | 109 |
| |
107 | 110 |
| |
108 |
| - | |
109 |
| - | |
110 |
| - | |
| 111 | + | |
111 | 112 |
| |
112 | 113 |
| |
113 | 114 |
| |
| |||
121 | 122 |
| |
122 | 123 |
| |
123 | 124 |
| |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
124 | 162 |
| |
125 |
| - | |
| 163 | + | |
126 | 164 |
| |
127 | 165 |
| |
128 | 166 |
| |
| |||
994 | 1032 |
| |
995 | 1033 |
| |
996 | 1034 |
| |
997 |
| - | |
| 1035 | + | |
998 | 1036 |
| |
999 | 1037 |
| |
1000 | 1038 |
| |
| |||
1005 | 1043 |
| |
1006 | 1044 |
| |
1007 | 1045 |
| |
1008 |
| - | |
| 1046 | + | |
1009 | 1047 |
| |
1010 | 1048 |
| |
1011 | 1049 |
| |
| |||
1016 | 1054 |
| |
1017 | 1055 |
| |
1018 | 1056 |
| |
1019 |
| - | |
| 1057 | + | |
1020 | 1058 |
| |
1021 | 1059 |
| |
1022 | 1060 |
| |
| |||
1032 | 1070 |
| |
1033 | 1071 |
| |
1034 | 1072 |
| |
1035 |
| - | |
| 1073 | + | |
1036 | 1074 |
| |
1037 | 1075 |
| |
1038 | 1076 |
| |
1039 | 1077 |
| |
1040 |
| - | |
| 1078 | + | |
1041 | 1079 |
| |
1042 | 1080 |
| |
1043 | 1081 |
| |
| |||
1055 | 1093 |
| |
1056 | 1094 |
| |
1057 | 1095 |
| |
1058 |
| - | |
| 1096 | + | |
1059 | 1097 |
| |
1060 | 1098 |
| |
1061 | 1099 |
| |
| |||
1066 | 1104 |
| |
1067 | 1105 |
| |
1068 | 1106 |
| |
1069 |
| - | |
| 1107 | + | |
1070 | 1108 |
| |
1071 | 1109 |
| |
1072 | 1110 |
| |
|
0 commit comments
Comments
(0)