@@ -26,8 +26,12 @@ def match(cls, options: ServerOptions) -> str:
26
26
return cls .match_runtime (runtime , runtimes )
27
27
28
28
@staticmethod
29
- def match_runtime (runtime : RuntimeFrameworkVersion , runtimes : List [RuntimeFrameworkVersion ]) -> str :
30
- sorted_runtimes = sorted (runtimes , key = lambda x : (x .major , x .minor , x .patch ), reverse = True )
29
+ def match_runtime (
30
+ runtime : RuntimeFrameworkVersion , runtimes : List [RuntimeFrameworkVersion ]
31
+ ) -> str :
32
+ sorted_runtimes = sorted (
33
+ runtimes , key = lambda x : (x .major , x .minor , x .patch ), reverse = True
34
+ )
31
35
32
36
for version in sorted_runtimes :
33
37
if runtime .match (version ):
@@ -44,7 +48,10 @@ def needs_match(cls, options: ServerOptions) -> bool:
44
48
return False
45
49
46
50
framework_version = options .framework_version .lower ()
47
- if cls .WILDCARD not in framework_version and cls .GREATER_OR_EQUAL not in framework_version :
51
+ if (
52
+ cls .WILDCARD not in framework_version
53
+ and cls .GREATER_OR_EQUAL not in framework_version
54
+ ):
48
55
return False
49
56
50
57
return True
@@ -59,14 +66,19 @@ def get_framework_versions(options: ServerOptions):
59
66
60
67
try :
61
68
with subprocess .Popen (
62
- process_command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True
69
+ process_command ,
70
+ stdout = subprocess .PIPE ,
71
+ stderr = subprocess .PIPE ,
72
+ text = True ,
63
73
) as process :
64
74
inside_runtimes = False
65
75
runtime_lines = []
66
76
67
77
for line in process .stdout :
68
78
line = line .strip ()
69
- if line .startswith (".NET runtimes installed:" ) or line .startswith (".NET Core runtimes installed:" ):
79
+ if line .startswith (".NET runtimes installed:" ) or line .startswith (
80
+ ".NET Core runtimes installed:"
81
+ ):
70
82
inside_runtimes = True
71
83
continue
72
84
if inside_runtimes and line .startswith ("Microsoft.NETCore.App" ):
@@ -81,7 +93,9 @@ def get_framework_versions(options: ServerOptions):
81
93
runtimes .append (RuntimeFrameworkVersion (values [1 ]))
82
94
83
95
except Exception as e :
84
- raise RuntimeError ("Unable to execute dotnet to retrieve list of installed runtimes" ) from e
96
+ raise RuntimeError (
97
+ "Unable to execute dotnet to retrieve list of installed runtimes"
98
+ ) from e
85
99
finally :
86
100
if process :
87
101
process .kill ()
@@ -100,22 +114,28 @@ def __init__(self, framework_version: str):
100
114
101
115
framework_version = framework_version .lower ()
102
116
103
- suffixes = [s for s in framework_version .split (self .SUFFIX_SEPARATOR ) if s .strip ()]
117
+ suffixes = [
118
+ s for s in framework_version .split (self .SUFFIX_SEPARATOR ) if s .strip ()
119
+ ]
104
120
if len (suffixes ) != 1 :
105
121
framework_version = suffixes [0 ]
106
122
self .suffix = self .SUFFIX_SEPARATOR .join (suffixes [1 :])
107
123
else :
108
124
self .suffix = None
109
125
110
- versions = [v .strip () for v in framework_version .split (self .SEPARATORS ) if v .strip ()]
126
+ versions = [
127
+ v .strip () for v in framework_version .split (self .SEPARATORS ) if v .strip ()
128
+ ]
111
129
for i , version in enumerate (versions ):
112
130
if RuntimeFrameworkVersionMatcher .WILDCARD not in version :
113
131
tuple_values = self .parse (version )
114
132
self ._set (i , version , * tuple_values )
115
133
continue
116
134
117
135
if version != RuntimeFrameworkVersionMatcher .WILDCARD :
118
- raise RuntimeError (f"Wildcard character must be a sole part of the version string, but was '{ version } '" )
136
+ raise RuntimeError (
137
+ f"Wildcard character must be a sole part of the version string, but was '{ version } '"
138
+ )
119
139
120
140
self ._set (i , None , None , MatchingType .EQUAL )
121
141
@@ -161,12 +181,22 @@ def parse(value: str) -> Tuple[int, MatchingType]:
161
181
value_as_int = int (value_to_parse )
162
182
return value_as_int , matching_type
163
183
164
- def _set (self , i : int , value_as_string : Optional [str ], value : Optional [int ], matching_type : MatchingType ) -> None :
184
+ def _set (
185
+ self ,
186
+ i : int ,
187
+ value_as_string : Optional [str ],
188
+ value : Optional [int ],
189
+ matching_type : MatchingType ,
190
+ ) -> None :
165
191
if i == 0 :
166
- self .assert_matching_type ("major" , value_as_string , MatchingType .EQUAL , matching_type )
192
+ self .assert_matching_type (
193
+ "major" , value_as_string , MatchingType .EQUAL , matching_type
194
+ )
167
195
self .major = value
168
196
elif i == 1 :
169
- self .assert_matching_type ("minor" , value_as_string , MatchingType .EQUAL , matching_type )
197
+ self .assert_matching_type (
198
+ "minor" , value_as_string , MatchingType .EQUAL , matching_type
199
+ )
170
200
self .minor = value
171
201
elif i == 2 :
172
202
self .assert_matching_type ("patch" , value_as_string , None , matching_type )
@@ -189,7 +219,10 @@ def assert_matching_type(
189
219
f"is not allowed when suffix ('{ self .suffix } ') is set."
190
220
)
191
221
192
- if expected_matching_type is not None and expected_matching_type != matching_type :
222
+ if (
223
+ expected_matching_type is not None
224
+ and expected_matching_type != matching_type
225
+ ):
193
226
raise RuntimeError (
194
227
f"Cannot set '{ field_name } ' with value '{ value_as_string } ' "
195
228
f"because '{ self .matching_type_to_string (matching_type )} ' "
@@ -213,9 +246,15 @@ def match(self, version: RuntimeFrameworkVersion) -> bool:
213
246
return False
214
247
215
248
if self .patch is not None :
216
- if self .patch_matching_type == MatchingType .EQUAL and self .patch != version .patch :
249
+ if (
250
+ self .patch_matching_type == MatchingType .EQUAL
251
+ and self .patch != version .patch
252
+ ):
217
253
return False
218
- elif self .patch_matching_type == MatchingType .GREATER_OR_EQUAL and self .patch > version .patch :
254
+ elif (
255
+ self .patch_matching_type == MatchingType .GREATER_OR_EQUAL
256
+ and self .patch > version .patch
257
+ ):
219
258
return False
220
259
221
260
return self .suffix == version .suffix
0 commit comments