Skip to content

Commit

Permalink
fix: correcting mypy and prospector bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jagalindo committed Jul 18, 2024
1 parent 821deec commit 5d033a6
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 36 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ jobs:
prospector:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v5
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install prospector[with_everything]==1.10.3
pip install prospector[with_everything]
pip install .
- name: Analysing the code with prospector
run: |
prospector -X
prospector
mypy:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
__pycache__
*.egg-info*
env

build
.vscode
4 changes: 0 additions & 4 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ doc-warnings: false
ignore-paths:
- tests
- build
- env
- resources
- flamapy/metamodels/fm_metamodel/transformations/uvl_parser/UVLLexer.py
- flamapy/metamodels/fm_metamodel/transformations/uvl_parser/UVLListener.py
- flamapy/metamodels/fm_metamodel/transformations/uvl_parser/UVLParser.py
- .mypy_cache

pycodestyle:
Expand Down
3 changes: 2 additions & 1 deletion flamapy/metamodels/fm_metamodel/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from .fm_average_branching_factor import FMAverageBranchingFactor, average_branching_factor
from .fm_feature_ancestors import FMFeatureAncestors, get_feature_ancestors
from .fm_max_depth_tree import FMMaxDepthTree, max_depth_tree
from .fm_estimated_configurations_number import FMEstimatedConfigurationsNumber, count_configurations
from .fm_estimated_configurations_number import FMEstimatedConfigurationsNumber, \
count_configurations
from .fm_atomic_sets import FMAtomicSets, get_atomic_sets
from .fm_metrics import FMMetrics
from .fm_generate_random_attribute import GenerateRandomAttribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self) -> None:
self.result = 0
self.feature_model: Optional[FeatureModel] = None

def execute(self, model: VariabilityModel) -> 'FMEstimatedProductsNumber':
def execute(self, model: VariabilityModel) -> 'FMEstimatedConfigurationsNumber':
self.feature_model = cast(FeatureModel, model)
self.result = self.get_configurations_number()
return self
Expand Down
2 changes: 1 addition & 1 deletion flamapy/metamodels/fm_metamodel/operations/fm_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def calculate_metamodel_metrics(self, model: VariabilityModel) -> list[dict[str,
if callable(getattr(self, method_name))
and hasattr(getattr(self, method_name), "_is_metric_method")
]

if self.filter is not None:
metric_methods = [
method for method in metric_methods if method.__name__ in self.filter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from enum import Enum
from typing import Any
from typing import Any, Optional

from flamapy.core.transformations import ModelToText
from flamapy.core.models.ast import ASTOperation
Expand Down Expand Up @@ -93,7 +93,7 @@ def read_feature_attributes(feature: Feature, tab_count: int) -> str:
return result


def parse_group_type(feature: Feature) -> str | None:
def parse_group_type(feature: Feature) -> Optional[str]:
group_type = None
if feature.is_alternative_group():
group_type = 'xor'
Expand Down Expand Up @@ -134,8 +134,8 @@ def attributes_definition(feature_model: FeatureModel) -> str:
result = ''
if attributes:
result = f'abstract {ATTRIBUTED_FEATURE}\n'
for name, type in attributes.items():
result += f'\t{name} -> {type}\n'
for name, v_type in attributes.items():
result += f'\t{name} -> {v_type}\n'
return result


Expand Down
22 changes: 9 additions & 13 deletions flamapy/metamodels/fm_metamodel/transformations/json_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import functools
import json
from typing import Any
from typing import Any, Dict, List, Optional

from flamapy.core.models.ast import Node, AST, ASTOperation
from flamapy.core.exceptions import ParsingException
Expand All @@ -26,7 +26,7 @@ def get_source_extension() -> str:
def __init__(self, path: str) -> None:
self.path = path

def transform(self) -> str:
def transform(self) -> FeatureModel:
with open(self.path, 'r', encoding='utf-8') as file:
data = json.load(file)
features_info = data['features']
Expand All @@ -36,15 +36,15 @@ def transform(self) -> str:
return FeatureModel(root_feature, constraints)

@staticmethod
def parse_json(json_content: str) -> FeatureModel:
def parse_json(json_content: Dict[str, Any]) -> FeatureModel:
features_info = json_content['features']
constraints_info = json_content['constraints']
root_feature = parse_tree(None, features_info)
constraints = parse_constraints(constraints_info)
return FeatureModel(root_feature, constraints)


def parse_tree(parent: Feature, feature_node: dict[str, Any]) -> Feature:
def parse_tree(parent: Optional[Feature], feature_node: Dict[str, Any]) -> Feature:
"""Parse the tree structure and returns the root feature."""
feature_name = feature_node['name']
is_abstract = feature_node['abstract']
Expand All @@ -55,20 +55,17 @@ def parse_tree(parent: Feature, feature_node: dict[str, Any]) -> Feature:
return feature


def parse_attributes(feature: Feature, feature_node: dict[str, Any]) -> None:
def parse_attributes(feature: Feature, feature_node: Dict[str, Any]) -> None:
if 'attributes' in feature_node:
for attribute in feature_node['attributes']:
attribute_name = attribute['name']
if 'value' in attribute:
attribute_value = attribute['value']
else:
attribute_value = None
attribute_value = attribute.get('value')
attr = Attribute(attribute_name, None, attribute_value, None)
attr.set_parent(feature)
feature.add_attribute(attr)


def parse_relations(feature: Feature, feature_node: dict[str, Any]) -> None:
def parse_relations(feature: Feature, feature_node: Dict[str, Any]) -> None:
if 'relations' in feature_node:
for relation in feature_node['relations']:
children = []
Expand All @@ -93,19 +90,18 @@ def parse_relations(feature: Feature, feature_node: dict[str, Any]) -> None:
feature.add_relation(new_relation)


def parse_constraints(constraints_info: dict[str, Any]) -> list[Constraint]:
def parse_constraints(constraints_info: List[Dict[str, Any]]) -> List[Constraint]:
constraints = []
for ctc_info in constraints_info:
name = ctc_info['name']
# ctc_expr = ctc_info['expr'] # not used
ast_tree = ctc_info['ast']
ctc_node = parse_ast_constraint(ast_tree)
ctc = Constraint(name, AST(ctc_node))
constraints.append(ctc)
return constraints


def parse_ast_constraint(ctc_info: dict[str, Any]) -> Node:
def parse_ast_constraint(ctc_info: Dict[str, Any]) -> Node:
ctc_type = ctc_info['type']
ctc_operands = ctc_info['operands']
node = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def to_json(feature_model: FeatureModel) -> dict[str, Any]:
def get_tree_info(feature: Feature) -> dict[str, Any]:
feature_info = {}
feature_info['name'] = feature.name
feature_info['abstract'] = feature.is_abstract
feature_info['abstract'] = str(feature.is_abstract)

relations = []
for relation in feature.get_relations():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import functools
from typing import Optional
from typing import Optional, Union

from flamapy.core.models.ast import AST, Node, ASTOperation
from flamapy.core.transformations import ModelToModel
Expand Down Expand Up @@ -62,7 +62,7 @@ def _identify_root(self) -> Feature:
raise FlamaException('Error converting from SAT to FM. ',
'There is not candidate for the root feature.')

def _get_node_from_clause_term(self, term: Node | int) -> Node:
def _get_node_from_clause_term(self, term: Union[Node, int]) -> Node:
if isinstance(term, Node):
return term
name = self.source_model.features[abs(term)]
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flamapy-fw~=2.0.0.dev2
uvlparser~=2.0.1
afmparser~=1.0.3
flamapy-fw==2.0.0.dev3
uvlparser==2.0.1
afmparser==1.0.3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read_requirements(file):

setuptools.setup(
name="flamapy-fm",
version="2.0.0.dev2",
version="2.0.0.dev3",
author="Flamapy",
author_email="[email protected]",
description="flamapy-fm is a plugin to Flamapy module",
Expand Down

0 comments on commit 5d033a6

Please sign in to comment.