44# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55
66import contextlib
7+ from dataclasses import dataclass
78from io import BytesIO
89import logging
910import os
1213import re
1314import shutil
1415from stat import S_ISLNK , ST_MODE
15- import subprocess
16+ from subprocess import CompletedProcess , run
1617import tempfile
1718
1819import ddt
1920import pytest
20- from sumtypes import constructor , sumtype
2121
2222from git import (
2323 BlobFilter ,
@@ -66,34 +66,48 @@ def _get_windows_ansi_encoding():
6666 return f"cp{ value } "
6767
6868
69- @sumtype
7069class 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.
7271
7372 Call check() to check the status. (CheckError and WinError should not typically be
7473 used to trigger skip or xfail, because they represent unexpected situations.)
7574 """
7675
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."""
7979
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."""
8283
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)."""
8587
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."""
8891
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."""
9195
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
9498
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
97111
98112 @classmethod
99113 def check (cls ):
@@ -119,7 +133,7 @@ def check(cls):
119133 # information on ways to check for WSL, see https://superuser.com/a/1749811.
120134 script = 'test -e /proc/sys/fs/binfmt_misc/WSLInterop; echo "$?"'
121135 command = ["bash.exe" , "-c" , script ]
122- process = subprocess . run (command , capture_output = True )
136+ process = run (command , capture_output = True )
123137 except FileNotFoundError :
124138 return cls .Absent ()
125139 except OSError as error :
0 commit comments