29
29
import glob
30
30
import os .path
31
31
32
- from .parser import Feature , parse_feature
32
+ from .parser import Feature , FeatureParser
33
33
34
34
# Global features dictionary
35
35
features : dict [str , Feature ] = {}
@@ -52,30 +52,29 @@ def get_feature(base_path: str, filename: str, encoding: str = "utf-8") -> Featu
52
52
full_name = os .path .abspath (os .path .join (base_path , filename ))
53
53
feature = features .get (full_name )
54
54
if not feature :
55
- feature = parse_feature (base_path , filename , encoding = encoding )
55
+ feature = FeatureParser (base_path , filename , encoding ). parse ( )
56
56
features [full_name ] = feature
57
57
return feature
58
58
59
59
60
- def get_features (paths : list [str ], ** kwargs ) -> list [Feature ]:
60
+ def get_features (paths : list [str ], encoding : str = "utf-8" ) -> list [Feature ]:
61
61
"""Get features for given paths.
62
62
63
63
:param list paths: `list` of paths (file or dirs)
64
64
65
65
:return: `list` of `Feature` objects.
66
66
"""
67
67
seen_names = set ()
68
- features = []
68
+ _features = []
69
69
for path in paths :
70
70
if path not in seen_names :
71
71
seen_names .add (path )
72
72
if os .path .isdir (path ):
73
- features .extend (
74
- get_features (glob .iglob (os .path .join (path , "**" , "*.feature" ), recursive = True ), ** kwargs )
75
- )
73
+ file_paths = list (glob .iglob (os .path .join (path , "**" , "*.feature" ), recursive = True ))
74
+ _features .extend (get_features (file_paths , encoding = encoding ))
76
75
else :
77
76
base , name = os .path .split (path )
78
- feature = get_feature (base , name , ** kwargs )
79
- features .append (feature )
80
- features .sort (key = lambda feature : feature .name or feature .filename )
81
- return features
77
+ feature = get_feature (base , name , encoding = encoding )
78
+ _features .append (feature )
79
+ _features .sort (key = lambda _feature : _feature .name or _feature .filename )
80
+ return _features
0 commit comments