4
4
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
5
5
6
6
import contextlib
7
+ from dataclasses import dataclass
7
8
from io import BytesIO
8
9
import logging
9
10
import os
12
13
import re
13
14
import shutil
14
15
from stat import S_ISLNK , ST_MODE
15
- import subprocess
16
+ from subprocess import CompletedProcess , run
16
17
import tempfile
17
18
18
19
import ddt
19
20
import pytest
20
- from sumtypes import constructor , sumtype
21
21
22
22
from git import (
23
23
BlobFilter ,
@@ -66,34 +66,48 @@ def _get_windows_ansi_encoding():
66
66
return f"cp{ value } "
67
67
68
68
69
- @sumtype
70
69
class WinBashStatus :
71
- """Status of bash.exe for native Windows . Affects which commit hook tests can pass.
70
+ """Namespace of native-Windows bash.exe statuses . Affects what hook tests can pass.
72
71
73
72
Call check() to check the status. (CheckError and WinError should not typically be
74
73
used to trigger skip or xfail, because they represent unexpected situations.)
75
74
"""
76
75
77
- Inapplicable = constructor ()
78
- """This system is not native Windows: either not Windows at all, or Cygwin."""
76
+ @dataclass
77
+ class Inapplicable :
78
+ """This system is not native Windows: either not Windows at all, or Cygwin."""
79
79
80
- Absent = constructor ()
81
- """No command for bash.exe is found on the system."""
80
+ @dataclass
81
+ class Absent :
82
+ """No command for bash.exe is found on the system."""
82
83
83
- Native = constructor ()
84
- """Running bash.exe operates outside any WSL distribution (as with Git Bash)."""
84
+ @dataclass
85
+ class Native :
86
+ """Running bash.exe operates outside any WSL distribution (as with Git Bash)."""
85
87
86
- Wsl = constructor ()
87
- """Running bash.exe calls bash in a WSL distribution."""
88
+ @dataclass
89
+ class Wsl :
90
+ """Running bash.exe calls bash in a WSL distribution."""
88
91
89
- WslNoDistro = constructor ("process" , "message" )
90
- """Running bash.exe tries to run bash on a WSL distribution, but none exists."""
92
+ @dataclass
93
+ class WslNoDistro :
94
+ """Running bash.exe tries to run bash on a WSL distribution, but none exists."""
91
95
92
- CheckError = constructor ( " process" , "message" )
93
- """Running bash.exe fails in an unexpected error or gives unexpected output."""
96
+ process : CompletedProcess [ bytes ]
97
+ message : str
94
98
95
- WinError = constructor ("exception" )
96
- """bash.exe may exist but can't run. CreateProcessW fails unexpectedly."""
99
+ @dataclass
100
+ class CheckError :
101
+ """Running bash.exe fails in an unexpected error or gives unexpected output."""
102
+
103
+ process : CompletedProcess [bytes ]
104
+ message : str
105
+
106
+ @dataclass
107
+ class WinError :
108
+ """bash.exe may exist but can't run. CreateProcessW fails unexpectedly."""
109
+
110
+ exception : OSError
97
111
98
112
@classmethod
99
113
def check (cls ):
@@ -119,7 +133,7 @@ def check(cls):
119
133
# information on ways to check for WSL, see https://superuser.com/a/1749811.
120
134
script = 'test -e /proc/sys/fs/binfmt_misc/WSLInterop; echo "$?"'
121
135
command = ["bash.exe" , "-c" , script ]
122
- process = subprocess . run (command , capture_output = True )
136
+ process = run (command , capture_output = True )
123
137
except FileNotFoundError :
124
138
return cls .Absent ()
125
139
except OSError as error :
0 commit comments