77
88"""KernelCI API helpers"""
99
10- from typing import Dict
1110import json
1211import os
12+ from typing import Dict
13+
1314import requests
1415
1516from . import API
@@ -36,7 +37,9 @@ def merge(primary: dict, secondary: dict):
3637 for key in primary :
3738 result [key ] = primary [key ]
3839 if key in secondary :
39- if isinstance (primary [key ], dict ) and isinstance (secondary [key ], dict ):
40+ if isinstance (primary [key ], dict ) and isinstance (
41+ secondary [key ], dict
42+ ):
4043 result [key ] = merge (primary [key ], secondary [key ])
4144 else :
4245 result [key ] = secondary [key ]
@@ -62,7 +65,9 @@ def api(self):
6265 """API object"""
6366 return self ._api
6467
65- def subscribe_filters (self , filters = None , channel = "node" , promiscuous = False ):
68+ def subscribe_filters (
69+ self , filters = None , channel = "node" , promiscuous = False
70+ ):
6671 """Subscribe to a channel with some added filters"""
6772 sub_id = self .api .subscribe (channel , promiscuous )
6873 self ._filters [sub_id ] = filters
@@ -140,7 +145,9 @@ def receive_event_node(self, sub_id):
140145 # Crude (provisional) filtering of non-node events
141146 if not node :
142147 continue
143- if all (self .pubsub_event_filter (sub_id , obj ) for obj in [node , event ]):
148+ if all (
149+ self .pubsub_event_filter (sub_id , obj ) for obj in [node , event ]
150+ ):
144151 return node , event .get ("is_hierarchy" )
145152
146153 def _find_container (self , field , node ):
@@ -188,7 +195,9 @@ def _is_allowed(self, rules, key, node):
188195 # the node on the basis that its rules aren; t fulfilled
189196 if not base :
190197 if len (allow ) > 0 :
191- print (f"rules[{ key } ]: attribute '{ key } ' not found in node hierarchy" )
198+ print (
199+ f"rules[{ key } ]: attribute '{ key } ' not found in node hierarchy"
200+ )
192201 return False
193202 return True
194203
@@ -217,7 +226,9 @@ def _is_allowed(self, rules, key, node):
217226 found = True
218227
219228 if not found :
220- print (f"rules[{ key } ]: { key .capitalize ()} missing one of { allow } " )
229+ print (
230+ f"rules[{ key } ]: { key .capitalize ()} missing one of { allow } "
231+ )
221232 return False
222233
223234 else :
@@ -280,7 +291,10 @@ def _match_combos(self, node, combos):
280291 """
281292 match = None
282293 for combo in combos :
283- if node ["tree" ] == combo ["tree" ] and node ["branch" ] == combo ["branch" ]:
294+ if (
295+ node ["tree" ] == combo ["tree" ]
296+ and node ["branch" ] == combo ["branch" ]
297+ ):
284298 match = combo
285299 break
286300 return match
@@ -415,15 +429,17 @@ def should_create_node(self, rules, node):
415429 rule_major = rules [key ]["version" ]
416430 rule_minor = rules [key ]["patchlevel" ]
417431 if key .startswith ("min" ) and (
418- (major < rule_major ) or (major == rule_major and minor < rule_minor )
432+ (major < rule_major )
433+ or (major == rule_major and minor < rule_minor )
419434 ):
420435 print (
421436 f"rules[{ key } ]: Version { major } .{ minor } older than minimum version "
422437 f"({ rule_major } .{ rule_minor } )"
423438 )
424439 return False
425440 if key .startswith ("max" ) and (
426- (major > rule_major ) or (major == rule_major and minor > rule_minor )
441+ (major > rule_major )
442+ or (major == rule_major and minor > rule_minor )
427443 ):
428444 print (
429445 f"rules[{ key } ]: Version { major } .{ minor } newer than maximum version "
@@ -473,7 +489,9 @@ def _is_job_filtered(self, node):
473489 # * jobfilter contains the job name suffixed with '+'
474490 # * at least one element of the node's 'path' appears in jobilfter
475491 # with a '+' suffix
476- for filt in (item .rstrip ("+" ) for item in jobfilter if item .endswith ("+" )):
492+ for filt in (
493+ item .rstrip ("+" ) for item in jobfilter if item .endswith ("+" )
494+ ):
477495 if filt in node ["path" ] or filt == node ["name" ]:
478496 return False
479497
@@ -483,7 +501,13 @@ def _is_job_filtered(self, node):
483501
484502 # pylint: disable=too-many-arguments
485503 def create_job_node (
486- self , job_config , input_node , * , runtime = None , platform = None , retry_counter = 0
504+ self ,
505+ job_config ,
506+ input_node ,
507+ * ,
508+ runtime = None ,
509+ platform = None ,
510+ retry_counter = 0 ,
487511 ):
488512 """Create a new job node based on input and configuration"""
489513 jobfilter = input_node .get ("jobfilter" )
@@ -525,10 +549,14 @@ def create_job_node(
525549 # Test-specific fields inherited from parent node (kbuild or
526550 # job) if available
527551 if job_config .kind == "job" :
528- job_node ["data" ]["kernel_type" ] = input_node ["data" ].get ("kernel_type" )
552+ job_node ["data" ]["kernel_type" ] = input_node ["data" ].get (
553+ "kernel_type"
554+ )
529555 job_node ["data" ]["arch" ] = input_node ["data" ].get ("arch" )
530556 job_node ["data" ]["defconfig" ] = input_node ["data" ].get ("defconfig" )
531- job_node ["data" ]["config_full" ] = input_node ["data" ].get ("config_full" )
557+ job_node ["data" ]["config_full" ] = input_node ["data" ].get (
558+ "config_full"
559+ )
532560 job_node ["data" ]["compiler" ] = input_node ["data" ].get ("compiler" )
533561 # This information is highly useful, as we might
534562 # extract from it the following, for example:
@@ -574,7 +602,9 @@ def create_job_node(
574602 job_node = self ._fsanitize_node_fields (job_node , "commit_message" )
575603
576604 try :
577- job_node ["data" ] = platform .format_params (job_node ["data" ], extra_args )
605+ job_node ["data" ] = platform .format_params (
606+ job_node ["data" ], extra_args
607+ )
578608 except Exception as error :
579609 print (f"Exception Error, node id: { input_node ['id' ]} , { error } " )
580610 raise error
0 commit comments