flamapy-fm 2.9.0.dev0__tar.gz → 2.9.0.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/PKG-INFO +4 -4
  2. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/models/feature_model.py +14 -1
  3. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_atomic_sets.py +11 -9
  4. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_core_features.py +2 -1
  5. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_estimated_configurations_number.py +3 -1
  6. flamapy_fm-2.9.0.dev2/flamapy/metamodels/fm_metamodel/transformations/flat_fm.py +135 -0
  7. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/cardinality_group_refactoring.py +4 -0
  8. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/splot_writer.py +3 -2
  9. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py +6 -1
  10. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/uvl_writer.py +8 -2
  11. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy_fm.egg-info/PKG-INFO +4 -4
  12. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy_fm.egg-info/requires.txt +3 -3
  13. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/pyproject.toml +4 -4
  14. flamapy_fm-2.9.0.dev0/flamapy/metamodels/fm_metamodel/transformations/flat_fm.py +0 -108
  15. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/LICENSE +0 -0
  16. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/README.md +0 -0
  17. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/__init__.py +0 -0
  18. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/models/__init__.py +0 -0
  19. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/models/clause_set.py +0 -0
  20. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/__init__.py +0 -0
  21. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_average_branching_factor.py +0 -0
  22. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_count_leafs.py +0 -0
  23. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_feature_ancestors.py +0 -0
  24. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_generate_random_attribute.py +0 -0
  25. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_generate_random_feature_model.py +0 -0
  26. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_language_level.py +0 -0
  27. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_leaf_features.py +0 -0
  28. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_max_depth_tree.py +0 -0
  29. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_metrics.py +0 -0
  30. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/fm_variation_points.py +0 -0
  31. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/interfaces/__init__.py +0 -0
  32. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/operations/interfaces/variation_points.py +0 -0
  33. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/__init__.py +0 -0
  34. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/_uvl_lexer.py +0 -0
  35. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/afm_reader.py +0 -0
  36. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/afm_writer.py +0 -0
  37. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py +0 -0
  38. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/featureide_reader.py +0 -0
  39. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py +0 -0
  40. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/fm_secure_features_names.py +0 -0
  41. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/glencoe_reader.py +0 -0
  42. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/glencoe_writer.py +0 -0
  43. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/group_support.py +0 -0
  44. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/json_reader.py +0 -0
  45. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/json_writer.py +0 -0
  46. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/pl_writer.py +0 -0
  47. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/pysat_to_fm.py +0 -0
  48. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/__init__.py +0 -0
  49. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/commitment_feature.py +0 -0
  50. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/deletion_feature.py +0 -0
  51. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/feature_cardinality_refactoring.py +0 -0
  52. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/feature_cardinality_refactoring_paper.py +0 -0
  53. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/multiple_group_decomposition_refactoring.py +0 -0
  54. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/mutex_group_refactoring.py +0 -0
  55. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/or_mandatory_refactoring.py +0 -0
  56. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/pseudocomplex_constraint_refactoring.py +0 -0
  57. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/refactoring_exception.py +0 -0
  58. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/refactoring_interface.py +0 -0
  59. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/strictcomplex_constraint_refactoring.py +0 -0
  60. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/refactorings/xor_mandatory_refactoring.py +0 -0
  61. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/xml_reader.py +0 -0
  62. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy/metamodels/fm_metamodel/transformations/xml_writer.py +0 -0
  63. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy_fm.egg-info/SOURCES.txt +0 -0
  64. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy_fm.egg-info/dependency_links.txt +0 -0
  65. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy_fm.egg-info/entry_points.txt +0 -0
  66. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/flamapy_fm.egg-info/top_level.txt +0 -0
  67. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/setup.cfg +0 -0
  68. {flamapy_fm-2.9.0.dev0 → flamapy_fm-2.9.0.dev2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flamapy-fm
3
- Version: 2.9.0.dev0
3
+ Version: 2.9.0.dev2
4
4
  Summary: flamapy-fm is a plugin to Flamapy module
5
5
  Author-email: Flamapy <flamapy@us.es>
6
6
  License-Expression: GPL-3.0-or-later
@@ -8,7 +8,7 @@ Project-URL: Homepage, https://github.com/flamapy/fm_metamodel
8
8
  Requires-Python: >=3.11
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: flamapy-fw~=2.9.0.dev0
11
+ Requires-Dist: flamapy-fw~=2.9.0.dev2
12
12
  Requires-Dist: uvlparser~=2.5.0
13
13
  Requires-Dist: afmparser~=1.0.3
14
14
  Provides-Extra: dev
@@ -20,8 +20,8 @@ Requires-Dist: coverage; extra == "dev"
20
20
  Requires-Dist: antlr4-tools; extra == "dev"
21
21
  Provides-Extra: test
22
22
  Requires-Dist: pytest; extra == "test"
23
- Requires-Dist: flamapy-sat~=2.9.0.dev0; extra == "test"
24
- Requires-Dist: flamapy-bdd~=2.9.0.dev0; extra == "test"
23
+ Requires-Dist: flamapy-sat~=2.9.0.dev2; extra == "test"
24
+ Requires-Dist: flamapy-bdd~=2.9.0.dev2; extra == "test"
25
25
  Dynamic: license-file
26
26
 
27
27
  # flamapy-fm
@@ -48,7 +48,20 @@ class Relation:
48
48
  )
49
49
 
50
50
  def is_group(self) -> bool:
51
- return len(self.children) > 1
51
+ """Whether the relation is a group: several children, or a single child under a
52
+ cardinality other than mandatory [1..1] and optional [0..1], such as [0..0] or [1..2]."""
53
+ return len(self.children) > 1 or (
54
+ len(self.children) == 1 and not self.is_mandatory() and not self.is_optional()
55
+ )
56
+
57
+ def requires_all_children(self) -> bool:
58
+ """Whether selecting the parent selects every child: a mandatory relation, or a group
59
+ whose minimum is its number of children, such as [2..2] over two children or [1..2]
60
+ over one. False for an impossible cardinality, whose parent cannot be selected."""
61
+ n_children = len(self.children)
62
+ return n_children > 0 and self.card_min == n_children and (
63
+ self.card_max < 0 or self.card_max >= n_children
64
+ )
52
65
 
53
66
  def __str__(self) -> str:
54
67
  parent_name = self.parent.name if self.parent else ""
@@ -7,7 +7,8 @@ from flamapy.metamodels.fm_metamodel.models import FeatureModel, Feature
7
7
 
8
8
  class FMAtomicSets(AtomicSets):
9
9
  """The atomic sets read from the feature tree: the root with its chain of mandatory
10
- descendants, and every other feature with its own chain. Cross-tree constraints, which
10
+ descendants, and every other feature with its own chain. The children of a group that
11
+ needs all of them ([n..n]) count as mandatory. Cross-tree constraints, which
11
12
  can merge sets, are ignored (the facade descriptor is the interface's; the exact sets are
12
13
  computed by the solver-based implementations)."""
13
14
 
@@ -44,11 +45,12 @@ def get_atomic_sets(feature_model: FeatureModel) -> list[set[Feature]]:
44
45
  def compute_atomic_sets(atomic_sets: list[set[Feature]],
45
46
  feature: Feature,
46
47
  current_set: set[Feature]) -> None:
47
- for child in feature.get_children():
48
- if child.is_mandatory():
49
- current_set.add(child)
50
- compute_atomic_sets(atomic_sets, child, current_set)
51
- else:
52
- new_as = {child}
53
- atomic_sets.append(new_as)
54
- compute_atomic_sets(atomic_sets, child, new_as)
48
+ for relation in feature.get_relations():
49
+ for child in relation.children:
50
+ if relation.requires_all_children():
51
+ current_set.add(child)
52
+ compute_atomic_sets(atomic_sets, child, current_set)
53
+ else:
54
+ new_as = {child}
55
+ atomic_sets.append(new_as)
56
+ compute_atomic_sets(atomic_sets, child, new_as)
@@ -47,7 +47,8 @@ def get_core_features(feature_model: FeatureModel) -> list[Feature]:
47
47
  while features:
48
48
  feature = features.pop()
49
49
  for relation in feature.get_relations():
50
- if relation.is_mandatory():
50
+ # mandatory children, and those of a group that needs all of them ([n..n])
51
+ if relation.requires_all_children():
51
52
  core_features.extend(relation.children)
52
53
  features.extend(relation.children)
53
54
 
@@ -116,6 +116,8 @@ def calculate_group_cardinality_configurations(relation: Relation) -> int:
116
116
  dp[i][j] += dp[i-1][j-1] * current_child_config
117
117
 
118
118
  # Sum the configurations for the allowed cardinalities [card_min..card_max]
119
- for k in range(relation.card_min, relation.card_max + 1):
119
+ # The upper bound may be unbounded (-1) or larger than the number of children.
120
+ card_max = num_children if relation.card_max < 0 else min(relation.card_max, num_children)
121
+ for k in range(relation.card_min, card_max + 1):
120
122
  relation_configurations += dp[num_children][k]
121
123
  return relation_configurations
@@ -0,0 +1,135 @@
1
+ import copy
2
+ from typing import cast
3
+
4
+ from flamapy.core.transformations import ModelToModel
5
+ from flamapy.core.models import VariabilityModel, AST
6
+ from flamapy.core.models.ast import ASTOperation, Node
7
+
8
+ from flamapy.metamodels.fm_metamodel.models import FeatureModel, Feature
9
+
10
+
11
+ class FlatFM(ModelToModel):
12
+ """Given a feature model with imports information, it returns a flat feature model with
13
+ all references resolved.
14
+
15
+ That is, it copies all imported feature models in only one feature model ready to be analyzed.
16
+ """
17
+
18
+ @staticmethod
19
+ def get_source_extension() -> str:
20
+ return 'fm'
21
+
22
+ @staticmethod
23
+ def get_destination_extension() -> str:
24
+ return 'fm'
25
+
26
+ def __init__(self, source_model: VariabilityModel) -> None:
27
+ self.feature_model = cast(FeatureModel, source_model)
28
+ self._maintain_namespaces: bool = True
29
+
30
+ def set_maintain_namespaces(self, maintain_namespaces: bool) -> None:
31
+ """Set whether to maintain the namespaces of the imported features."""
32
+ self._maintain_namespaces = maintain_namespaces
33
+
34
+ def transform(self) -> FeatureModel:
35
+ new_feature_model = copy.deepcopy(self.feature_model)
36
+ imported_models = get_imported_models_by_root(new_feature_model)
37
+ if not self._maintain_namespaces:
38
+ for ctc in new_feature_model.ctcs:
39
+ remove_namespace_constraint(ctc.ast, new_feature_model)
40
+ features = [new_feature_model.root]
41
+ while features:
42
+ feature = features.pop()
43
+ if feature.reference is not None:
44
+ imported_fm = imported_models[id(feature.reference)]
45
+ # Copy the feature's attributes and relations from the referenced feature
46
+ feature.relations = feature.reference.relations
47
+ for relation in feature.relations:
48
+ relation.parent = feature
49
+ for child in relation.children:
50
+ child.parent = feature
51
+ feature.attributes.extend(feature.reference.attributes)
52
+ # Process attribute constraints
53
+ # (they are also in the imported model's ctcs, which are processed below)
54
+ feature.constraints_attributes.extend(feature.reference.constraints_attributes)
55
+ if not self._maintain_namespaces:
56
+ feature.name = feature.reference.name
57
+ for ctc in imported_fm.ctcs:
58
+ remove_namespace_constraint(ctc.ast, imported_fm)
59
+ else:
60
+ namespace = '.'.join(feature.name.split('.')[:-1])
61
+ put_namespace_to_features(feature.reference, namespace)
62
+ for ctc in imported_fm.ctcs:
63
+ put_namespace_to_constraint(ctc.ast, namespace)
64
+ # Add the constraints of the imported model (nested imports are reached when
65
+ # their referencing features are visited)
66
+ new_feature_model.ctcs.extend(imported_fm.ctcs)
67
+ feature.reference = None # Clear reference after copying
68
+ features.extend(feature.get_children())
69
+ new_feature_model.imports = {} # Clear imports as they are not needed in the flat model
70
+ new_feature_model.alias_namespace = {} # Clear alias namespace as it is not needed in
71
+ return new_feature_model
72
+
73
+
74
+ def put_namespace_to_features(root: Feature, namespace: str) -> None:
75
+ """Put the namespace to the features in the feature model."""
76
+ features = [root]
77
+ while features:
78
+ feature = features.pop()
79
+ feature.name = f'{namespace}.{feature.name}'
80
+ features.extend(feature.get_children())
81
+
82
+
83
+ def get_imported_models_by_root(feature_model: FeatureModel) -> dict[int, FeatureModel]:
84
+ """Return all the (nested) imported models of the feature model, indexed by the id of their
85
+ root feature, which is the object referenced by the importing feature."""
86
+ imported_models = {}
87
+ models = list(feature_model.imports.values())
88
+ while models:
89
+ imported_fm = models.pop()
90
+ imported_models[id(imported_fm.root)] = imported_fm
91
+ models.extend(imported_fm.imports.values())
92
+ return imported_models
93
+
94
+
95
+ def get_feature_terms(ast: AST) -> list[Node]:
96
+ """Return the terms of the constraint that reference a feature (or a Feature.Attribute).
97
+
98
+ Literals are excluded, and so is the attribute name of the sum/avg aggregates
99
+ (e.g., in sum(Price, B) only B is a feature).
100
+ """
101
+ terms = []
102
+ stack = [ast.root]
103
+ while stack:
104
+ node = stack.pop()
105
+ if node is None:
106
+ continue
107
+ if node.data in (ASTOperation.SUM, ASTOperation.AVG):
108
+ stack.append(node.right)
109
+ elif node.is_op():
110
+ stack.extend([node.left, node.right])
111
+ elif (isinstance(node.data, str) and not node.is_literal()
112
+ and not node.data.startswith("'")):
113
+ terms.append(node)
114
+ return terms
115
+
116
+
117
+ def put_namespace_to_constraint(ast: AST, namespace: str) -> None:
118
+ """Put the namespace to the features referenced in the constraint."""
119
+ for node in get_feature_terms(ast):
120
+ node.data = f'{namespace}.{node.data}'
121
+
122
+
123
+ def remove_namespace_constraint(ast: AST, feature_model: FeatureModel) -> None:
124
+ """Remove the import aliases of the features referenced in a constraint of the model."""
125
+ for node in get_feature_terms(ast):
126
+ node.data = remove_namespace(node.data, feature_model)
127
+
128
+
129
+ def remove_namespace(reference: str, feature_model: FeatureModel) -> str:
130
+ """Remove the import alias prefixing the reference, following nested imports
131
+ (e.g., 's.l.Y' -> 'Y', and 's.B.Price' -> 'B.Price')."""
132
+ for alias, namespace in feature_model.alias_namespace.items():
133
+ if reference.startswith(f'{alias}.') and namespace in feature_model.imports:
134
+ return remove_namespace(reference[len(alias) + 1:], feature_model.imports[namespace])
135
+ return reference
@@ -153,6 +153,10 @@ def get_or_constraints_for_cardinality_group(relation: Relation) -> Node:
153
153
 
154
154
 
155
155
  def get_ast_constraint_for_cardinality_group(feature: Feature, relation: Relation) -> AST:
156
+ n_children = len(relation.children)
157
+ card_max = n_children if relation.card_max < 0 else min(relation.card_max, n_children)
158
+ if relation.card_min > card_max: # no selection of children fits: the feature is dead
159
+ return AST.create_simple_unary_operation(ASTOperation.NOT, feature.name)
156
160
  return AST.create_binary_operation(ASTOperation.IMPLIES,
157
161
  Node(feature.name),
158
162
  get_or_constraints_for_cardinality_group(relation))
@@ -56,8 +56,9 @@ def add_features(feature: Feature, n_tabs: int) -> list[str]:
56
56
  child = relation.children[0]
57
57
  lines.append(indentation + f':m {safename(child.name)} ({safename(child.name)})')
58
58
  lines.extend(add_features(child, n_tabs + 1))
59
- elif relation.is_alternative() or relation.is_or():
60
- lines.append(indentation + f':g [{relation.card_min},{relation.card_max}]')
59
+ elif relation.is_group(): # or, alternative, mutex and any other [m,n]
60
+ card_max = '*' if relation.card_max == -1 else relation.card_max
61
+ lines.append(indentation + f':g [{relation.card_min},{card_max}]')
61
62
  for child in relation.children:
62
63
  lines.append(
63
64
  indentation + TAB + f': {safename(child.name)} ({safename(child.name)})'
@@ -557,7 +557,12 @@ class UVLReader(TextToModel):
557
557
  )
558
558
 
559
559
  # Find ParseTree node of root feature
560
- root_feature_ast = self.parse_tree.features().feature()
560
+ features_node = self.parse_tree.features()
561
+ if features_node is None or features_node.feature() is None:
562
+ raise FlamaException(
563
+ "The UVL model has no 'features' section: a feature model needs a root feature."
564
+ )
565
+ root_feature_ast = features_node.feature()
561
566
  # Get the root and process it
562
567
  feature_text = root_feature_ast.reference().getText().replace('"', '')
563
568
  feature = Feature(feature_text, [])
@@ -82,8 +82,14 @@ class UVLWriter(ModelToText):
82
82
  file.write(serialized_model)
83
83
 
84
84
  for namespace, submodel in self.model.imports.items():
85
- path = f'{"/".join(namespace.split("."))}.uvl'
86
- pathlib.Path(path).parent.mkdir(parents=True, exist_ok=True)
85
+ # An imported model goes where the reader looks for it: under its namespace,
86
+ # next to the importing file. Without a path nothing is written at all.
87
+ path = None
88
+ if self.path is not None:
89
+ submodel_path = pathlib.Path(self.path).parent.joinpath(
90
+ *namespace.split('.')).with_suffix('.uvl')
91
+ submodel_path.parent.mkdir(parents=True, exist_ok=True)
92
+ path = str(submodel_path)
87
93
  submodel_str = UVLWriter(path, submodel).transform()
88
94
  serialized_model += f'\n\n{submodel_str}'
89
95
  return serialized_model
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flamapy-fm
3
- Version: 2.9.0.dev0
3
+ Version: 2.9.0.dev2
4
4
  Summary: flamapy-fm is a plugin to Flamapy module
5
5
  Author-email: Flamapy <flamapy@us.es>
6
6
  License-Expression: GPL-3.0-or-later
@@ -8,7 +8,7 @@ Project-URL: Homepage, https://github.com/flamapy/fm_metamodel
8
8
  Requires-Python: >=3.11
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: flamapy-fw~=2.9.0.dev0
11
+ Requires-Dist: flamapy-fw~=2.9.0.dev2
12
12
  Requires-Dist: uvlparser~=2.5.0
13
13
  Requires-Dist: afmparser~=1.0.3
14
14
  Provides-Extra: dev
@@ -20,8 +20,8 @@ Requires-Dist: coverage; extra == "dev"
20
20
  Requires-Dist: antlr4-tools; extra == "dev"
21
21
  Provides-Extra: test
22
22
  Requires-Dist: pytest; extra == "test"
23
- Requires-Dist: flamapy-sat~=2.9.0.dev0; extra == "test"
24
- Requires-Dist: flamapy-bdd~=2.9.0.dev0; extra == "test"
23
+ Requires-Dist: flamapy-sat~=2.9.0.dev2; extra == "test"
24
+ Requires-Dist: flamapy-bdd~=2.9.0.dev2; extra == "test"
25
25
  Dynamic: license-file
26
26
 
27
27
  # flamapy-fm
@@ -1,4 +1,4 @@
1
- flamapy-fw~=2.9.0.dev0
1
+ flamapy-fw~=2.9.0.dev2
2
2
  uvlparser~=2.5.0
3
3
  afmparser~=1.0.3
4
4
 
@@ -12,5 +12,5 @@ antlr4-tools
12
12
 
13
13
  [test]
14
14
  pytest
15
- flamapy-sat~=2.9.0.dev0
16
- flamapy-bdd~=2.9.0.dev0
15
+ flamapy-sat~=2.9.0.dev2
16
+ flamapy-bdd~=2.9.0.dev2
@@ -4,14 +4,14 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "flamapy-fm"
7
- version = "2.9.0.dev0"
7
+ version = "2.9.0.dev2"
8
8
  description = "flamapy-fm is a plugin to Flamapy module"
9
9
  readme = "README.md"
10
10
  license = "GPL-3.0-or-later"
11
11
  authors = [{ name = "Flamapy", email = "flamapy@us.es" }]
12
12
  requires-python = ">=3.11"
13
13
  dependencies = [
14
- "flamapy-fw~=2.9.0.dev0",
14
+ "flamapy-fw~=2.9.0.dev2",
15
15
  "uvlparser~=2.5.0",
16
16
  "afmparser~=1.0.3",
17
17
  ]
@@ -30,8 +30,8 @@ dev = [
30
30
  # group refactorings through the BDD plugin.
31
31
  test = [
32
32
  "pytest",
33
- "flamapy-sat~=2.9.0.dev0",
34
- "flamapy-bdd~=2.9.0.dev0",
33
+ "flamapy-sat~=2.9.0.dev2",
34
+ "flamapy-bdd~=2.9.0.dev2",
35
35
  ]
36
36
 
37
37
  [project.entry-points."flamapy.plugins"]
@@ -1,108 +0,0 @@
1
- import copy
2
- from typing import cast
3
-
4
- from flamapy.core.transformations import ModelToModel
5
- from flamapy.core.models import VariabilityModel, AST
6
-
7
- from flamapy.metamodels.fm_metamodel.models import FeatureModel, Feature
8
-
9
-
10
- class FlatFM(ModelToModel):
11
- """Given a feature model with imports information, it returns a flat feature model with
12
- all references resolved.
13
-
14
- That is, it copies all imported feature models in only one feature model ready to be analyzed.
15
- """
16
-
17
- @staticmethod
18
- def get_source_extension() -> str:
19
- return 'fm'
20
-
21
- @staticmethod
22
- def get_destination_extension() -> str:
23
- return 'fm'
24
-
25
- def __init__(self, source_model: VariabilityModel) -> None:
26
- self.feature_model = cast(FeatureModel, source_model)
27
- self._maintain_namespaces: bool = True
28
-
29
- def set_maintain_namespaces(self, maintain_namespaces: bool) -> None:
30
- """Set whether to maintain the namespaces of the imported features."""
31
- self._maintain_namespaces = maintain_namespaces
32
-
33
- def transform(self) -> FeatureModel:
34
- new_feature_model = copy.deepcopy(self.feature_model)
35
- features = [new_feature_model.root]
36
- while features:
37
- feature = features.pop()
38
- if feature.reference is not None:
39
- # Copy the feature's attributes and relations from the referenced feature
40
- feature.relations = feature.reference.relations
41
- feature.attributes.extend(feature.reference.attributes)
42
- # Process attribute constraints
43
- feature.constraints_attributes.extend(feature.reference.constraints_attributes)
44
- process_attribute_constraints(feature.reference,
45
- new_feature_model.alias_namespace,
46
- self._maintain_namespaces)
47
- if not self._maintain_namespaces:
48
- feature.name = feature.reference.name
49
- else:
50
- namespace = '.'.join(feature.name.split('.')[:-1])
51
- put_namespace_to_features(feature.reference, namespace)
52
- feature.reference = None # Clear reference after copying
53
- features.extend(feature.get_children())
54
- # Add contraints from imported models
55
- for imported_fm in self.feature_model.imports.values():
56
- new_feature_model.ctcs.extend(imported_fm.ctcs)
57
- if not self._maintain_namespaces:
58
- for ctcs in new_feature_model.ctcs:
59
- process_namespace_constraint(ctcs.ast, new_feature_model.alias_namespace)
60
- new_feature_model.imports = {} # Clear imports as they are not needed in the flat model
61
- new_feature_model.alias_namespace = {} # Clear alias namespace as it is not needed in
62
- return new_feature_model
63
-
64
-
65
- def put_namespace_to_features(root: Feature, namespace: str) -> None:
66
- """Put the namespace to the features in the feature model."""
67
- features = [root]
68
- while features:
69
- feature = features.pop()
70
- feature.name = f'{namespace}.{feature.name}'
71
- features.extend(feature.get_children())
72
-
73
-
74
- def process_attribute_constraints(root: Feature,
75
- alias_namespace: dict[str, str],
76
- maintain_namespaces: bool) -> None:
77
- """Put the namespace to the constraints of the attributes constraints and return them to
78
- incorporate in the new feature model."""
79
- features = [root]
80
- while features:
81
- feature = features.pop()
82
- for ctc in feature.constraints_attributes:
83
- if not maintain_namespaces:
84
- process_namespace_constraint(ctc.ast, alias_namespace)
85
- features.extend(feature.get_children())
86
-
87
-
88
- def process_namespace_constraint(ast: AST, alias_namespace: dict[str, str]) -> None:
89
- """Replace the namespace of the features in the constraints."""
90
- stack = [ast.root]
91
- while stack:
92
- node = stack.pop()
93
- if node is None:
94
- continue
95
- if node.is_unique_term():
96
- if (isinstance(node.data, (int, float)) or node.data.startswith("'")):
97
- continue
98
- feature_reference = node.data.split('.')
99
- if len(feature_reference) > 1:
100
- namespace = feature_reference[0]
101
- feature_name = feature_reference[-1]
102
- if namespace in alias_namespace:
103
- node.data = feature_name
104
- elif node.is_unary_op():
105
- stack.append(node.left)
106
- elif node.is_binary_op():
107
- stack.append(node.right)
108
- stack.append(node.left)
File without changes