66
77import logging
88import os
9- import re
10- import subprocess
119from glob import glob
12- from typing import Callable , Optional
10+ from pathlib import Path
11+ from typing import Callable , Optional , cast
1312
1413import networkx
1514import yaml
1615
17- from ..constants import (
18- ARCHS ,
19- BARE_FLAVOR_FEATURE_CONTENT ,
20- BARE_FLAVOR_LIBC_FEATURE_CONTENT ,
21- )
16+ from ..constants import BARE_FLAVOR_FEATURE_CONTENT , BARE_FLAVOR_LIBC_FEATURE_CONTENT
2217from ..logger import LoggerSetup
2318
2419
@@ -42,8 +37,8 @@ class Parser(object):
4237
4338 def __init__ (
4439 self ,
45- gardenlinux_root : Optional [ str ] = None ,
46- feature_dir_name : Optional [ str ] = "features" ,
40+ gardenlinux_root : str | None = None ,
41+ feature_dir_name : str = "features" ,
4742 logger : Optional [logging .Logger ] = None ,
4843 ):
4944 """
@@ -59,7 +54,7 @@ def __init__(
5954 if gardenlinux_root is None :
6055 gardenlinux_root = Parser ._GARDENLINUX_ROOT
6156
62- feature_base_dir = os . path . join (gardenlinux_root , feature_dir_name )
57+ feature_base_dir = Path (gardenlinux_root ). resolve () / feature_dir_name
6358
6459 if not os .access (feature_base_dir , os .R_OK ):
6560 raise ValueError (
@@ -70,7 +65,6 @@ def __init__(
7065 logger = LoggerSetup .get_logger ("gardenlinux.features" )
7166
7267 self ._feature_base_dir = feature_base_dir
73-
7468 self ._graph = None
7569 self ._logger = logger
7670
@@ -108,7 +102,7 @@ def graph(self) -> networkx.Graph:
108102 "{0}/{1}/info.yaml" .format (self ._feature_base_dir , ref )
109103 ):
110104 raise ValueError (
111- f"feature { node } references feature { ref } , but { feature_dir } /{ ref } /info.yaml does not exist"
105+ f"feature { node } references feature { ref } , but { self . _feature_base_dir } /{ ref } /info.yaml does not exist"
112106 )
113107
114108 feature_graph .add_edge (node , ref , attr = attr )
@@ -122,9 +116,9 @@ def graph(self) -> networkx.Graph:
122116
123117 def filter (
124118 self ,
125- cname : str ,
119+ cname : str | None ,
126120 ignore_excludes : bool = False ,
127- additional_filter_func : Optional [Callable [( str ,) , bool ]] = None ,
121+ additional_filter_func : Optional [Callable [[ str ] , bool ]] = None ,
128122 ) -> networkx .Graph :
129123 """
130124 Filters the features graph.
@@ -162,15 +156,15 @@ def filter(
162156 )
163157
164158 if not ignore_excludes :
165- Parser ._exclude_from_filter_set (graph , input_features , filter_set )
159+ Parser ._exclude_from_filter_set (self , graph , input_features , filter_set )
166160
167161 return graph
168162
169163 def filter_as_dict (
170164 self ,
171- cname : str ,
165+ cname : str | None ,
172166 ignore_excludes : bool = False ,
173- additional_filter_func : Optional [Callable [( str ,) , bool ]] = None ,
167+ additional_filter_func : Optional [Callable [[ str ] , bool ]] = None ,
174168 ) -> dict :
175169 """
176170 Filters the features graph and returns it as a dict.
@@ -200,9 +194,9 @@ def filter_as_dict(
200194
201195 def filter_as_list (
202196 self ,
203- cname : str ,
197+ cname : str | None ,
204198 ignore_excludes : bool = False ,
205- additional_filter_func : Optional [Callable [( str ,) , bool ]] = None ,
199+ additional_filter_func : Optional [Callable [[ str ] , bool ]] = None ,
206200 ) -> list :
207201 """
208202 Filters the features graph and returns it as a list.
@@ -220,9 +214,9 @@ def filter_as_list(
220214
221215 def filter_as_string (
222216 self ,
223- cname : str ,
217+ cname : str | None ,
224218 ignore_excludes : bool = False ,
225- additional_filter_func : Optional [Callable [( str ,) , bool ]] = None ,
219+ additional_filter_func : Optional [Callable [[ str ] , bool ]] = None ,
226220 ) -> str :
227221 """
228222 Filters the features graph and returns it as a string.
@@ -240,7 +234,7 @@ def filter_as_string(
240234
241235 return "," .join (features )
242236
243- def _exclude_from_filter_set (graph , input_features , filter_set ):
237+ def _exclude_from_filter_set (self , graph , input_features , filter_set ):
244238 """
245239 Removes the given `filter_set` out of `input_features`.
246240
@@ -250,7 +244,9 @@ def _exclude_from_filter_set(graph, input_features, filter_set):
250244 :since: 0.7.0
251245 """
252246
253- exclude_graph_view = Parser ._get_graph_view_for_attr (graph , "exclude" )
247+ exclude_graph_view = cast (
248+ networkx .DiGraph , Parser ._get_graph_view_for_attr (graph , "exclude" )
249+ )
254250 exclude_list = []
255251
256252 for node in networkx .lexicographical_topological_sort (graph ):
0 commit comments