Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork939
Commit5d11394
committed
Fix and expand bash.exe xfail marks on hook tests
881456b (#1679) expanded the use of shutil.which in test_index.pyto attempt to mark test_commit_msg_hook_success xfail when bash.exeis a WSL bash wrapper in System32 (because that test currentlyis not passing when the hook is run via bash in a WSL system, whichthe WSL bash.exe wraps). But this was not reliable, due tosignificant differences between shell and non-shell search behaviorfor executable commands on Windows. As the new docstring notes,lookup due to Popen generally checks System32 before going throughdirectories in PATH, as this is how CreateProcessW behaves.-https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw-python/cpython#91558 (comment)The technique I had used in881456b also had the shortcoming ofassuming that a bash.exe in System32 was the WSL wrapper. But sucha file may exist on some systems without WSL, and be a bashinterpreter unrelated to WSL that may be able to run hooks.In addition, one common situation, which was the case on CI beforea step to install a WSL distribution was added, is that WSL ispresent but no WSL distributions are installed. In that situationbash.exe is found in System32, but it can't be used to run anyhooks, because there's no actual system with a bash in it to wrap.This was not covered before. Unlike some conditions that preventa WSL system from being used, such as resource exhaustion blockingit from being started, the absence of a WSL system should probablynot fail the pytest run, for the same reason as we are trying notto have the complete *absence* of bash.exe fail the pytest run.Both conditions should be xfail. Fortunately, the error messagewhen no distribution exists is distinctive and can be checked for.There is probably no correct and reasonable way to check LBYL-stylewhich executable file bash.exe resolves to by using shutil.which,due to shutil.which and subprocess.Popen's differing seach ordersand other subtleties. So this adds code to do it EAFP-style usingsubprocess.run (which itself uses Popen, so giving the sameCreateProcessW behavior). It tries to run a command with bash.exewhose output pretty reliably shows if the system is WSL or not.We may fail to get to the point of running that command at all, ifbash.exe is not usable, in which case the failure's details tell usif bash.exe is absent (xfail), present as the WSL wrapper with no WSLsystems (xfail), or has some other error (not xfail, so the user canbecome aware of and proably fix the problem). If we do get to thatpoint, then a file that is almost always present on both WSL 1 andWSL 2 systems and almost always absent on any other system ischecked for, to distinguish whether the working bash shell operatesin a WSL system, or outside any such system as e.g. Git Bash does.Seehttps://superuser.com/a/1749811 on various techniques forchecking for WSL, including the /proc/sys/fs/binfmt_misc/WSLInteroptechnique used here (which seems overall may be the most reliable).Although the Windows CI runners have Git Bash, and this is even thebash.exe that appears first in PATH (giving rise to the problemwith shutil.which detailed above), it would be a bit awkward totest the behavior when Git Bash is actually used to run hooks onCI, because of how Popen selects the System32 bash.exe first,whether or not any WSL distribution is present. However, localtesting shows that when Git Bash's bash.exe is selected, all fourhook tests in the module pass, both before and after this change,and furthermore that bash.exe is correctly detected as "native",continuing to avoid an erroneous xfail mark in that case.1 parent9717b8d commit5d11394
1 file changed
+113
-13
lines changedLines changed: 113 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3 | 3 |
| |
4 | 4 |
| |
5 | 5 |
| |
| 6 | + | |
6 | 7 |
| |
| 8 | + | |
7 | 9 |
| |
8 | 10 |
| |
9 | 11 |
| |
10 | 12 |
| |
11 |
| - | |
| 13 | + | |
12 | 14 |
| |
13 | 15 |
| |
14 | 16 |
| |
| |||
34 | 36 |
| |
35 | 37 |
| |
36 | 38 |
| |
| 39 | + | |
37 | 40 |
| |
38 |
| - | |
39 |
| - | |
40 |
| - | |
41 |
| - | |
42 | 41 |
| |
| 42 | + | |
| 43 | + | |
43 | 44 |
| |
44 |
| - | |
| 45 | + | |
| 46 | + | |
45 | 47 |
| |
46 |
| - | |
47 |
| - | |
48 |
| - | |
49 |
| - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
50 | 130 |
| |
51 | 131 |
| |
52 | 132 |
| |
| |||
917 | 997 |
| |
918 | 998 |
| |
919 | 999 |
| |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
920 | 1005 |
| |
921 | 1006 |
| |
922 | 1007 |
| |
923 | 1008 |
| |
924 | 1009 |
| |
925 | 1010 |
| |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
926 | 1016 |
| |
927 | 1017 |
| |
928 | 1018 |
| |
929 | 1019 |
| |
930 | 1020 |
| |
931 | 1021 |
| |
932 | 1022 |
| |
933 |
| - | |
| 1023 | + | |
934 | 1024 |
| |
935 | 1025 |
| |
936 | 1026 |
| |
| |||
946 | 1036 |
| |
947 | 1037 |
| |
948 | 1038 |
| |
949 |
| - | |
| 1039 | + | |
950 | 1040 |
| |
951 | 1041 |
| |
952 | 1042 |
| |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
953 | 1048 |
| |
954 | 1049 |
| |
955 | 1050 |
| |
| |||
963 | 1058 |
| |
964 | 1059 |
| |
965 | 1060 |
| |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
966 | 1066 |
| |
967 | 1067 |
| |
968 | 1068 |
| |
969 | 1069 |
| |
970 | 1070 |
| |
971 | 1071 |
| |
972 | 1072 |
| |
973 |
| - | |
| 1073 | + | |
974 | 1074 |
| |
975 | 1075 |
| |
976 | 1076 |
| |
|
0 commit comments
Comments
(0)