1414
1515
1616class Parser (object ):
17- def __init__ (self , gardenlinux_root : str = "." , feature_dir_name : str = "features" , logger : Optional [logging .Logger ] = None ):
17+ def __init__ (
18+ self ,
19+ gardenlinux_root : str = "." ,
20+ feature_dir_name : str = "features" ,
21+ logger : Optional [logging .Logger ] = None ,
22+ ):
1823 feature_base_dir = os .path .join (gardenlinux_root , feature_dir_name )
1924
2025 if not os .access (feature_base_dir , os .R_OK ):
21- raise ValueError ("Feature directory given is invalid: {0}" .format (feature_base_dir ))
26+ raise ValueError (
27+ "Feature directory given is invalid: {0}" .format (feature_base_dir )
28+ )
2229
2330 if logger is None or not logger .hasHandlers ():
2431 logger = LoggerSetup .get_logger ("gardenlinux.features" )
@@ -28,7 +35,9 @@ def __init__(self, gardenlinux_root: str = ".", feature_dir_name: str = "feature
2835 self ._graph = None
2936 self ._logger = logger
3037
31- self ._logger .debug ("features.Parser initialized for directory: {0}" .format (feature_base_dir ))
38+ self ._logger .debug (
39+ "features.Parser initialized for directory: {0}" .format (feature_base_dir )
40+ )
3241
3342 @property
3443 def graph (self ) -> networkx .Graph :
@@ -49,7 +58,9 @@ def graph(self) -> networkx.Graph:
4958 continue
5059
5160 for ref in node_features [attr ]:
52- if not os .path .isfile ("{0}/{1}/info.yaml" .format (self ._feature_base_dir , ref )):
61+ if not os .path .isfile (
62+ "{0}/{1}/info.yaml" .format (self ._feature_base_dir , ref )
63+ ):
5364 raise ValueError (
5465 f"feature { node } references feature { ref } , but { feature_dir } /{ ref } /info.yaml does not exist"
5566 )
@@ -67,7 +78,7 @@ def filter(
6778 self ,
6879 cname : str ,
6980 ignore_excludes : bool = False ,
70- additional_filter_func : Optional [Callable [(str ,), bool ]] = None
81+ additional_filter_func : Optional [Callable [(str ,), bool ]] = None ,
7182 ) -> networkx .Graph :
7283 input_features = Parser .get_cname_as_feature_set (cname )
7384 filter_set = input_features .copy ()
@@ -80,9 +91,18 @@ def filter(
8091 self .graph .add_node ("libc" , content = BARE_FLAVOR_LIBC_FEATURE_CONTENT )
8192
8293 for feature in input_features :
83- filter_set .update (networkx .descendants (Parser ._get_graph_view_for_attr (self .graph , "include" ), feature ))
94+ filter_set .update (
95+ networkx .descendants (
96+ Parser ._get_graph_view_for_attr (self .graph , "include" ), feature
97+ )
98+ )
8499
85- graph = networkx .subgraph_view (self .graph , filter_node = self ._get_filter_set_callable (filter_set , additional_filter_func ))
100+ graph = networkx .subgraph_view (
101+ self .graph ,
102+ filter_node = self ._get_filter_set_callable (
103+ filter_set , additional_filter_func
104+ ),
105+ )
86106
87107 if not ignore_excludes :
88108 Parser ._exclude_from_filter_set (graph , input_features , filter_set )
@@ -93,13 +113,13 @@ def filter_as_dict(
93113 self ,
94114 cname : str ,
95115 ignore_excludes : bool = False ,
96- additional_filter_func : Optional [Callable [(str ,), bool ]] = None
116+ additional_filter_func : Optional [Callable [(str ,), bool ]] = None ,
97117 ) -> dict :
98118 """
99- :param str cname: the target cname to get the feature dict for
100- :param str gardenlinux_root: path of garden linux src root
119+ :param str cname: the target cname to get the feature dict for
120+ :param str gardenlinux_root: path of garden linux src root
101121
102- :return: dict with list of features for a given cname, split into platform, element and flag
122+ :return: dict with list of features for a given cname, split into platform, element and flag
103123 """
104124
105125 graph = self .filter (cname , ignore_excludes , additional_filter_func )
@@ -121,13 +141,13 @@ def filter_as_list(
121141 self ,
122142 cname : str ,
123143 ignore_excludes : bool = False ,
124- additional_filter_func : Optional [Callable [(str ,), bool ]] = None
144+ additional_filter_func : Optional [Callable [(str ,), bool ]] = None ,
125145 ) -> list :
126146 """
127- :param str cname: the target cname to get the feature dict for
128- :param str gardenlinux_root: path of garden linux src root
147+ :param str cname: the target cname to get the feature dict for
148+ :param str gardenlinux_root: path of garden linux src root
129149
130- :return: list of features for a given cname
150+ :return: list of features for a given cname
131151 """
132152
133153 graph = self .filter (cname , ignore_excludes , additional_filter_func )
@@ -137,13 +157,13 @@ def filter_as_string(
137157 self ,
138158 cname : str ,
139159 ignore_excludes : bool = False ,
140- additional_filter_func : Optional [Callable [(str ,), bool ]] = None
160+ additional_filter_func : Optional [Callable [(str ,), bool ]] = None ,
141161 ) -> str :
142162 """
143- :param str cname: the target cname to get the feature set for
144- :param str gardenlinux_root: path of garden linux src root
163+ :param str cname: the target cname to get the feature set for
164+ :param str gardenlinux_root: path of garden linux src root
145165
146- :return: a comma separated string with the expanded feature set for the cname
166+ :return: a comma separated string with the expanded feature set for the cname
147167 """
148168
149169 graph = self .filter (cname , ignore_excludes , additional_filter_func )
@@ -200,15 +220,17 @@ def get_cname_as_feature_set(cname):
200220 @staticmethod
201221 def _get_filter_set_callable (filter_set , additional_filter_func ):
202222 def filter_func (node ):
203- additional_filter_result = True if additional_filter_func is None else additional_filter_func (node )
204- return (node in filter_set and additional_filter_result )
223+ additional_filter_result = (
224+ True if additional_filter_func is None else additional_filter_func (node )
225+ )
226+ return node in filter_set and additional_filter_result
205227
206228 return filter_func
207229
208230 @staticmethod
209231 def _get_graph_view_for_attr (graph , attr ):
210232 return networkx .subgraph_view (
211- graph , filter_edge = Parser ._get_graph_view_for_attr_callable (graph , attr )
233+ graph , filter_edge = Parser ._get_graph_view_for_attr_callable (graph , attr )
212234 )
213235
214236 @staticmethod
@@ -231,7 +253,7 @@ def key_function(node):
231253
232254 return f"{ prefix } -{ node } "
233255
234- return list (networkx .lexicographical_topological_sort (graph , key = key_function ))
256+ return list (networkx .lexicographical_topological_sort (graph , key = key_function ))
235257
236258 @staticmethod
237259 def sort_reversed_graph_nodes (graph ):
0 commit comments