1111from flamapy .core .exceptions import ConfigurationNotFound
1212from flamapy .core .models import VariabilityModel
1313from flamapy .core .operations import Operation
14- from flamapy .core .plugins import (
15- Operations ,
16- Plugin ,
17- Plugins
18- )
14+ from flamapy .core .plugins import Operations , Plugin , Plugins
1915from flamapy .core .transformations import Transformation
2016from flamapy .core .transformations .text_to_model import TextToModel
2117from flamapy .core .transformations .model_to_model import ModelToModel
2218from flamapy .metamodels .configuration_metamodel .models .configuration import Configuration
2319
2420
25- LOGGER = logging .getLogger (' discover' )
21+ LOGGER = logging .getLogger (" discover" )
2622
2723
2824@runtime_checkable
@@ -38,7 +34,7 @@ def filter_modules_from_plugin_paths() -> list[ModuleType]:
3834 module : ModuleType = import_module (path )
3935 results .append (module )
4036 except ModuleNotFoundError :
41- LOGGER .exception (' ModuleNotFoundError %s' , path )
37+ LOGGER .exception (" ModuleNotFoundError %s" , path )
4238 return results
4339
4440
@@ -49,9 +45,7 @@ def __init__(self) -> None:
4945
5046 def search_classes (self , module : ModuleType ) -> list [Any ]:
5147 classes = []
52- for _ , file_name , ispkg in iter_modules (
53- module .__path__ , module .__name__ + '.'
54- ):
48+ for _ , file_name , ispkg in iter_modules (module .__path__ , module .__name__ + "." ):
5549 if ispkg :
5650 classes += self .search_classes (import_module (file_name ))
5751 else :
@@ -62,9 +56,7 @@ def search_classes(self, module: ModuleType) -> list[Any]:
6256 def discover (self ) -> Plugins :
6357 plugins = Plugins ()
6458 for pkg in self .module_paths :
65- for _ , plugin_name , ispkg in iter_modules (
66- pkg .__path__ , pkg .__name__ + '.'
67- ):
59+ for _ , plugin_name , ispkg in iter_modules (pkg .__path__ , pkg .__name__ + "." ):
6860 if not ispkg :
6961 continue
7062 module = import_module (plugin_name )
@@ -90,7 +82,7 @@ def reload(self) -> None:
9082 self .plugins = self .discover ()
9183
9284 def get_operations (self ) -> list [Type [Operation ]]:
93- """ Get the operations for all modules """
85+ """Get the operations for all modules"""
9486 operations : list [Type [Operation ]] = []
9587 for plugin in self .plugins :
9688 operations += plugin .operations
@@ -100,54 +92,51 @@ def get_name_operations(self) -> list[str]:
10092 operations = []
10193 for operation in self .get_operations ():
10294 operations .append (operation .__name__ )
103- base = operation .__base__ .__name__ if operation .__base__ else ''
104- if base != ' ABC' :
95+ base = operation .__base__ .__name__ if operation .__base__ else ""
96+ if base != " ABC" :
10597 operations .append (base )
10698
10799 return operations
108100
109101 def get_transformations (self ) -> list [Type [Transformation ]]:
110- """ Get transformations for all modules """
102+ """Get transformations for all modules"""
111103 transformations : list [Type [Transformation ]] = []
112104 for plugin in self .plugins :
113105 transformations += plugin .transformations
114106 return transformations
115107
116108 def get_transformations_t2m (self ) -> list [Type [TextToModel ]]:
117- """ Get t2m transformations for all modules """
109+ """Get t2m transformations for all modules"""
118110
119111 transformations : list [Type [TextToModel ]] = []
120112 for plugin in self .plugins :
121- transformations += [
122- t for t in plugin .transformations if issubclass (t , TextToModel )
123- ]
113+ transformations += [t for t in plugin .transformations if issubclass (t , TextToModel )]
124114 return transformations
125115
126116 def get_transformations_m2m (self ) -> list [Type [ModelToModel ]]:
127- """ Get m2m transformations for all modules """
117+ """Get m2m transformations for all modules"""
128118
129119 transformations : list [Type [ModelToModel ]] = []
130120 for plugin in self .plugins :
131- transformations += [
132- t for t in plugin .transformations if issubclass (t , ModelToModel )
133- ]
121+ transformations += [t for t in plugin .transformations if issubclass (t , ModelToModel )]
134122 return transformations
135123
136124 def get_operations_by_plugin (self , plugin_name : str ) -> Operations :
137125 return self .plugins .get_operations_by_plugin_name (plugin_name )
138126
139127 def get_plugins_with_operation (self , operation_name : str ) -> list [Plugin ]:
140128 return [
141- plugin for plugin in self .plugins
129+ plugin
130+ for plugin in self .plugins
142131 if operation_name in self .get_name_operations_by_plugin (plugin .name )
143132 ]
144133
145134 def get_name_operations_by_plugin (self , plugin_name : str ) -> list [str ]:
146135 operations = []
147136 for operation in self .get_operations_by_plugin (plugin_name ):
148137 operations .append (operation .__name__ )
149- base = operation .__base__ .__name__ if operation .__base__ else ''
150- if base != ' ABC' :
138+ base = operation .__base__ .__name__ if operation .__base__ else ""
139+ if base != " ABC" :
151140 operations .append (base )
152141
153142 return operations
@@ -186,25 +175,22 @@ def use_operation_from_vm(
186175 vm_orig : VariabilityModel ,
187176 plugin_name : Optional [str ] = None ,
188177 configuration_file : Optional [str ] = None ,
189- is_full : Optional [bool ] = False
178+ is_full : Optional [bool ] = False ,
190179 ) -> Any :
191-
192180 if operation_name not in self .get_name_operations ():
193181 raise OperationNotFound ()
194182 vm_temp = vm_orig
195183 if plugin_name is not None :
196184 plugin = self .plugins .get_plugin_by_name (plugin_name )
197- #vm_temp = plugin.use_transformation_t2m(file)
185+ # vm_temp = plugin.use_transformation_t2m(file)
198186 else :
199- #vm_temp = self.__transform_to_model_from_file(file)
200- plugin = self .plugins .get_plugin_by_extension (
201- vm_orig .get_extension ())
187+ # vm_temp = self.__transform_to_model_from_file(file)
188+ plugin = self .plugins .get_plugin_by_extension (vm_orig .get_extension ())
202189
203190 if operation_name not in self .get_name_operations_by_plugin (plugin .name ):
204- transformation_way = self .__search_transformation_way (
205- plugin , operation_name )
191+ transformation_way = self .__search_transformation_way (plugin , operation_name )
206192
207- for ( _ , dst ) in transformation_way :
193+ for _ , dst in transformation_way :
208194 _plugin = self .plugins .get_plugin_by_extension (dst )
209195 vm_temp = _plugin .use_transformation_m2m (vm_temp , dst )
210196 plugin = _plugin
@@ -230,9 +216,8 @@ def use_operation_from_file(
230216 file : str ,
231217 plugin_name : Optional [str ] = None ,
232218 configuration_file : Optional [str ] = None ,
233- is_full : Optional [bool ] = False
219+ is_full : Optional [bool ] = False ,
234220 ) -> Any :
235-
236221 if operation_name not in self .get_name_operations ():
237222 raise OperationNotFound ()
238223
@@ -241,14 +226,12 @@ def use_operation_from_file(
241226 vm_temp = plugin .use_transformation_t2m (file )
242227 else :
243228 vm_temp = self .__transform_to_model_from_file (file )
244- plugin = self .plugins .get_plugin_by_extension (
245- vm_temp .get_extension ())
229+ plugin = self .plugins .get_plugin_by_extension (vm_temp .get_extension ())
246230
247231 if operation_name not in self .get_name_operations_by_plugin (plugin .name ):
248- transformation_way = self .__search_transformation_way (
249- plugin , operation_name )
232+ transformation_way = self .__search_transformation_way (plugin , operation_name )
250233
251- for ( _ , dst ) in transformation_way :
234+ for _ , dst in transformation_way :
252235 _plugin = self .plugins .get_plugin_by_extension (dst )
253236 vm_temp = _plugin .use_transformation_m2m (vm_temp , dst )
254237 plugin = _plugin
@@ -268,10 +251,9 @@ def use_operation_from_file(
268251
269252 def __transform_to_model_from_file (self , file : str ) -> VariabilityModel :
270253 t2m_transformations = self .get_transformations_t2m ()
271- extension = file .split ('.' )[- 1 ]
254+ extension = file .split ("." )[- 1 ]
272255 t2m_filters = filter (
273- lambda t2m : t2m .get_source_extension () == extension ,
274- t2m_transformations
256+ lambda t2m : t2m .get_source_extension () == extension , t2m_transformations
275257 )
276258
277259 t2m = next (t2m_filters , None )
@@ -281,27 +263,21 @@ def __transform_to_model_from_file(self, file: str) -> VariabilityModel:
281263 return t2m (file ).transform ()
282264
283265 def __search_transformation_way (
284- self ,
285- plugin : Plugin ,
286- operation_name : str
266+ self , plugin : Plugin , operation_name : str
287267 ) -> list [tuple [str , str ]]:
288- '''
268+ """
289269 Search way to reach plugin with operation_name using m2m transformations
290- '''
270+ """
291271 way : list [tuple [str , str ]] = []
292272
293- plugins_with_operation = self .get_plugins_with_operation (
294- operation_name )
273+ plugins_with_operation = self .get_plugins_with_operation (operation_name )
295274 m2m_transformations = self .get_transformations_m2m ()
296275
297276 input_extension = plugin .get_extension ()
298277
299278 def __search_recursive_way (
300- input_extension : str ,
301- output_extension : str ,
302- tmp_way : list [tuple [str , str ]]
279+ input_extension : str , output_extension : str , tmp_way : list [tuple [str , str ]]
303280 ) -> list [tuple [str , str ]]:
304-
305281 for m2m in m2m_transformations :
306282 in_m2m = m2m .get_source_extension ()
307283 out_m2m = m2m .get_destination_extension ()
@@ -327,4 +303,4 @@ def __search_recursive_way(
327303 if way and output_extension == way [- 1 ][1 ]:
328304 return way
329305
330- raise NotImplementedError (' Way to execute operation not found' )
306+ raise NotImplementedError (" Way to execute operation not found" )
0 commit comments