1010import attr
1111
1212__all__ = [
13- ' TAG_KEY' ,
14- ' TAG_VAL' ,
15- ' ResourceEntry' ,
16- ' ResourceMatch' ,
17- ' Place' ,
18- ' ReservationState' ,
19- ' Reservation' ,
20- ' enable_tcp_nodelay' ,
21- ' monkey_patch_max_msg_payload_size_ws_option' ,
13+ " TAG_KEY" ,
14+ " TAG_VAL" ,
15+ " ResourceEntry" ,
16+ " ResourceMatch" ,
17+ " Place" ,
18+ " ReservationState" ,
19+ " Reservation" ,
20+ " enable_tcp_nodelay" ,
21+ " monkey_patch_max_msg_payload_size_ws_option" ,
2222]
2323
2424TAG_KEY = re .compile (r"[a-z][a-z0-9_]+" )
@@ -30,59 +30,59 @@ class ResourceEntry:
3030 data = attr .ib () # cls, params
3131
3232 def __attrs_post_init__ (self ):
33- self .data .setdefault (' acquired' , None )
34- self .data .setdefault (' avail' , False )
33+ self .data .setdefault (" acquired" , None )
34+ self .data .setdefault (" avail" , False )
3535
3636 @property
3737 def acquired (self ):
38- return self .data [' acquired' ]
38+ return self .data [" acquired" ]
3939
4040 @property
4141 def avail (self ):
42- return self .data [' avail' ]
42+ return self .data [" avail" ]
4343
4444 @property
4545 def cls (self ):
46- return self .data [' cls' ]
46+ return self .data [" cls" ]
4747
4848 @property
4949 def params (self ):
50- return self .data [' params' ]
50+ return self .data [" params" ]
5151
5252 @property
5353 def args (self ):
5454 """arguments for resource construction"""
55- args = self .data [' params' ].copy ()
56- args .pop (' extra' , None )
55+ args = self .data [" params" ].copy ()
56+ args .pop (" extra" , None )
5757 return args
5858
5959 @property
6060 def extra (self ):
6161 """extra resource information"""
62- return self .data [' params' ].get (' extra' , {})
62+ return self .data [" params" ].get (" extra" , {})
6363
6464 def asdict (self ):
6565 return {
66- ' cls' : self .cls ,
67- ' params' : self .params ,
68- ' acquired' : self .acquired ,
69- ' avail' : self .avail ,
66+ " cls" : self .cls ,
67+ " params" : self .params ,
68+ " acquired" : self .acquired ,
69+ " avail" : self .avail ,
7070 }
7171
7272 def update (self , data ):
7373 """apply updated information from the exporter on the coordinator"""
7474 data = data .copy ()
75- data .setdefault (' acquired' , None )
76- data .setdefault (' avail' , False )
75+ data .setdefault (" acquired" , None )
76+ data .setdefault (" avail" , False )
7777 self .data = data
7878
7979 def acquire (self , place_name ):
80- assert self .data [' acquired' ] is None
81- self .data [' acquired' ] = place_name
80+ assert self .data [" acquired" ] is None
81+ self .data [" acquired" ] = place_name
8282
8383 def release (self ):
8484 # ignore repeated releases
85- self .data [' acquired' ] = None
85+ self .data [" acquired" ] = None
8686
8787
8888@attr .s (eq = True , repr = False , str = False )
@@ -99,9 +99,7 @@ class ResourceMatch:
9999 @classmethod
100100 def fromstr (cls , pattern ):
101101 if not 2 <= pattern .count ("/" ) <= 3 :
102- raise ValueError (
103- f"invalid pattern format '{ pattern } ' (use 'exporter/group/cls/name')"
104- )
102+ raise ValueError (f"invalid pattern format '{ pattern } ' (use 'exporter/group/cls/name')" )
105103 return cls (* pattern .split ("/" ))
106104
107105 def __repr__ (self ):
@@ -160,30 +158,30 @@ def asdict(self):
160158 acquired_resources .append (resource .path )
161159
162160 return {
163- ' aliases' : list (self .aliases ),
164- ' comment' : self .comment ,
165- ' tags' : self .tags ,
166- ' matches' : [attr .asdict (x ) for x in self .matches ],
167- ' acquired' : self .acquired ,
168- ' acquired_resources' : acquired_resources ,
169- ' allowed' : list (self .allowed ),
170- ' created' : self .created ,
171- ' changed' : self .changed ,
172- ' reservation' : self .reservation ,
161+ " aliases" : list (self .aliases ),
162+ " comment" : self .comment ,
163+ " tags" : self .tags ,
164+ " matches" : [attr .asdict (x ) for x in self .matches ],
165+ " acquired" : self .acquired ,
166+ " acquired_resources" : acquired_resources ,
167+ " allowed" : list (self .allowed ),
168+ " created" : self .created ,
169+ " changed" : self .changed ,
170+ " reservation" : self .reservation ,
173171 }
174172
175173 def update (self , config ):
176174 fields = attr .fields_dict (type (self ))
177175 for k , v in config .items ():
178176 assert k in fields
179- if k == ' name' :
177+ if k == " name" :
180178 # we cannot rename places
181179 assert v == self .name
182180 continue
183181 setattr (self , k , v )
184182
185183 def show (self , level = 0 ):
186- indent = ' ' * level
184+ indent = " " * level
187185 if self .aliases :
188186 print (indent + f"aliases: { ', ' .join (sorted (self .aliases ))} " )
189187 if self .comment :
@@ -240,7 +238,6 @@ def unmatched(self, resource_paths):
240238 if not any ([match .ismatch (resource ) for resource in resource_paths ]):
241239 return match
242240
243-
244241 def touch (self ):
245242 self .changed = time .time ()
246243
@@ -256,12 +253,14 @@ class ReservationState(enum.Enum):
256253@attr .s (eq = False )
257254class Reservation :
258255 owner = attr .ib (validator = attr .validators .instance_of (str ))
259- token = attr .ib (default = attr .Factory (
260- lambda : '' .join (random .choice (string .ascii_uppercase + string .digits ) for i in range (10 ))))
256+ token = attr .ib (
257+ default = attr .Factory (lambda : "" .join (random .choice (string .ascii_uppercase + string .digits ) for i in range (10 )))
258+ )
261259 state = attr .ib (
262- default = ' waiting' ,
260+ default = " waiting" ,
263261 converter = lambda x : x if isinstance (x , ReservationState ) else ReservationState [x ],
264- validator = attr .validators .instance_of (ReservationState ))
262+ validator = attr .validators .instance_of (ReservationState ),
263+ )
265264 prio = attr .ib (default = 0.0 , validator = attr .validators .instance_of (float ))
266265 # a dictionary of name -> filter dicts
267266 filters = attr .ib (default = attr .Factory (dict ), validator = attr .validators .instance_of (dict ))
@@ -272,13 +271,13 @@ class Reservation:
272271
273272 def asdict (self ):
274273 return {
275- ' owner' : self .owner ,
276- ' state' : self .state .name ,
277- ' prio' : self .prio ,
278- ' filters' : self .filters ,
279- ' allocations' : self .allocations ,
280- ' created' : self .created ,
281- ' timeout' : self .timeout ,
274+ " owner" : self .owner ,
275+ " state" : self .state .name ,
276+ " prio" : self .prio ,
277+ " filters" : self .filters ,
278+ " allocations" : self .allocations ,
279+ " created" : self .created ,
280+ " timeout" : self .timeout ,
282281 }
283282
284283 def refresh (self , delta = 60 ):
@@ -289,7 +288,7 @@ def expired(self):
289288 return self .timeout < time .time ()
290289
291290 def show (self , level = 0 ):
292- indent = ' ' * level
291+ indent = " " * level
293292 print (indent + f"owner: { self .owner } " )
294293 print (indent + f"token: { self .token } " )
295294 print (indent + f"state: { self .state .name } " )
@@ -311,7 +310,7 @@ def enable_tcp_nodelay(session):
311310 asyncio/autobahn does not set TCP_NODELAY by default, so we need to do it
312311 like this for now.
313312 """
314- s = session ._transport .transport .get_extra_info (' socket' )
313+ s = session ._transport .transport .get_extra_info (" socket" )
315314 s .setsockopt (socket .IPPROTO_TCP , socket .TCP_NODELAY , True )
316315
317316
0 commit comments