Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nbirillo committed Jun 22, 2023
1 parent 9f636fb commit 40708e4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import hyperstyle.src.python.review.inspectors.ij_python.proto.model_pb2 as model_pb2
import hyperstyle.src.python.review.inspectors.ij_python.proto.model_pb2_grpc as model_pb2_grpc

TIMEOUT = 1


class IJClient(object):
def __init__(self, host: str = 'localhost', port: int = 8080):
Expand All @@ -14,14 +16,14 @@ def __init__(self, host: str = 'localhost', port: int = 8080):

# bind the client and the server
try:
grpc.channel_ready_future(self.channel).result(timeout=60)
grpc.channel_ready_future(self.channel).result(timeout=TIMEOUT)
except grpc.FutureTimeoutError:
raise Exception("Failed to connect to ij code server")
else:
self.stub = model_pb2_grpc.CodeInspectionServiceStub(self.channel)

def inspect(self, code: model_pb2.Code) -> model_pb2.InspectionResult:
return self.stub.inspect(code, timeout=60)
return self.stub.inspect(code, timeout=TIMEOUT)

def init(self, service: model_pb2.Service) -> model_pb2.InitResult:
return self.stub.init(service, timeout=60)
return self.stub.init(service, timeout=TIMEOUT)
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
from hyperstyle.src.python.review.common.language import Language
from hyperstyle.src.python.review.inspectors.base_inspector import BaseInspector
import hyperstyle.src.python.review.inspectors.ij_python.proto.model_pb2 as model_pb2
from hyperstyle.src.python.review.inspectors.common.base_issue_converter import convert_base_issue
from hyperstyle.src.python.review.inspectors.ij_python.ij_client import IJClient
from hyperstyle.src.python.review.inspectors.ij_python.issue_configs import ISSUE_CONFIGS
from hyperstyle.src.python.review.inspectors.ij_python.issue_types import IJ_PYTHON_CODE_TO_ISSUE_TYPE, \
ISSUE_TYPE_EXCEPTIONS
from hyperstyle.src.python.review.inspectors.inspector_type import InspectorType
from hyperstyle.src.python.review.inspectors.issue import BaseIssue, IssueDifficulty, IssueType
from hyperstyle.src.python.review.inspectors.issue_configs import IssueConfigsHandler

CODE_SERVER_HOST = "CODE_SERVER_HOST"
CODE_SERVER_PORT = "CODE_SERVER_PORT"
Expand Down Expand Up @@ -51,10 +54,10 @@ def choose_issue_type(inspector: str, description: str) -> IssueType:

def convert_to_base_issues(self, inspection_result: model_pb2.InspectionResult, file_path: Path) -> List[BaseIssue]:
base_issues = []
issue_configs_handler = IssueConfigsHandler(*ISSUE_CONFIGS)
for problem in inspection_result.problems:
issue_type = self.choose_issue_type(problem.inspector, problem.name)
base_issues.append(
BaseIssue(
base_issue = BaseIssue(
origin_class=problem.inspector,
type=issue_type,
description=problem.name,
Expand All @@ -63,8 +66,14 @@ def convert_to_base_issues(self, inspection_result: model_pb2.InspectionResult,
column_no=problem.offset,
inspector_type=InspectorType.IJ_PYTHON,
difficulty=IssueDifficulty.get_by_issue_type(issue_type),
),
)
)

issue = convert_base_issue(base_issue, issue_configs_handler)
if issue is None:
logger.error(f'{self.inspector_type.value}: an error occurred during converting a base issue.')
continue

base_issues.append(base_issue)

return base_issues

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from hyperstyle.src.python.review.inspectors.issue_configs import IssueConfig

ISSUE_CONFIGS = [
IssueConfig(
origin_class='E128',
new_description='Incorrect indent',
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
'PyProtectedMemberInspection': IssueType.BEST_PRACTICES,
'PyMethodMayBeStaticInspection': IssueType.BEST_PRACTICES,
'PyChainedComparisonsInspection': IssueType.BEST_PRACTICES,
'PyGlobalUndefinedInspection': IssueType.BEST_PRACTICES,
'PyComparisonWithNoneInspection': IssueType.BEST_PRACTICES,
'PyShadowingNamesInspection': IssueType.BEST_PRACTICES,

# CODE_STYLE
'PyRedundantParenthesesInspection': IssueType.CODE_STYLE,
Expand All @@ -36,11 +39,9 @@
'PyAsyncCallInspection': IssueType.ERROR_PRONE,
'PyByteLiteralInspection': IssueType.ERROR_PRONE,
'PyCallingNonCallableInspection': IssueType.ERROR_PRONE,
'PyComparisonWithNoneInspection': IssueType.ERROR_PRONE,
'PyDictDuplicateKeysInspection': IssueType.ERROR_PRONE,
'PyExceptClausesOrderInspection': IssueType.ERROR_PRONE,
'PyFinalInspection': IssueType.ERROR_PRONE,
'PyGlobalUndefinedInspection': IssueType.ERROR_PRONE,
'PyArgumentListInspection': IssueType.ERROR_PRONE,
'PyMethodFirstArgAssignmentInspection': IssueType.ERROR_PRONE,
'PyStringFormatInspection': IssueType.ERROR_PRONE,
Expand All @@ -56,7 +57,6 @@
'PyDecoratorInspection': IssueType.ERROR_PRONE,
'PyTypeCheckerInspection': IssueType.ERROR_PRONE,
'PyNoneFunctionAssignmentInspection': IssueType.ERROR_PRONE,
'PyShadowingNamesInspection': IssueType.ERROR_PRONE,
'PyAbstractClassInspection': IssueType.ERROR_PRONE,
'PyOverloadsInspection': IssueType.ERROR_PRONE,
'PyTypeHintsInspection': IssueType.ERROR_PRONE,
Expand Down
4 changes: 4 additions & 0 deletions hyperstyle/src/python/review/inspectors/inspector_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class InspectorType(Enum):

UNDEFINED = 'UNDEFINED'
QODANA = 'QODANA'
# TODO: it is used on production for java inspections, remove in the future releases
IJ_OLD = 'INTELLIJ'

@classmethod
def available_values(cls) -> List[str]:
Expand All @@ -49,4 +51,6 @@ def available_values(cls) -> List[str]:

# Go language
cls.GOLANG_LINT.value,

cls.IJ_OLD.value,
]

0 comments on commit 40708e4

Please sign in to comment.