Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
4013cff
Add GitHub actions (#9)
nbirillo Feb 4, 2021
b70ffb3
Add the build action badge
nbirillo Feb 4, 2021
36d33c7
Fix styles by flake8 (#10)
nbirillo Feb 5, 2021
eff27df
Add docs (#12)
nbirillo Feb 12, 2021
2ed7c11
Refactoring (#13)
nbirillo Feb 16, 2021
143e02a
Refactor/cli (#14)
nbirillo Feb 19, 2021
1a1be0c
minor typo
vyahhi Mar 2, 2021
d1a56ec
Flake8-spellcheck bug fix (#16)
GirZ0n Mar 17, 2021
fddc93f
Fix PR#15 comments: small code refactoring
nbirillo Mar 30, 2021
cdcee95
wps-light support (#17)
GirZ0n Apr 3, 2021
7862043
New flake8 plugins support (#18)
GirZ0n Apr 5, 2021
809a8f6
Radon support (#19)
GirZ0n Apr 12, 2021
f62c91f
updating requirements
dariadiatlova Apr 13, 2021
daee49b
adding script to run tool on xlsx file
dariadiatlova Apr 13, 2021
52d971c
adding testing files
dariadiatlova Apr 13, 2021
45b5919
adding tests
dariadiatlova Apr 13, 2021
e797191
Requirements for xlsx tool
dariadiatlova Apr 14, 2021
2172286
XLSX run_tool
dariadiatlova Apr 14, 2021
52b28ae
Files to test xlsx run tool
dariadiatlova Apr 14, 2021
6a50db5
XLSX run tool tests
dariadiatlova Apr 14, 2021
3df4664
Requirements upgrade (#21)
GirZ0n Apr 14, 2021
5c1c7cf
Update build.yml
dariadiatlova Apr 14, 2021
db4eca8
Update build.yml
dariadiatlova Apr 14, 2021
8f2f19f
Update build.yml
dariadiatlova Apr 14, 2021
6ac1154
Clean xlsx
dariadiatlova Apr 14, 2021
2b3fd79
Merge branch 'xlsx_run_tool' of https://github.com/hyperskill/hyperst…
dariadiatlova Apr 14, 2021
f0cce19
Tempfiles substituted with regular
dariadiatlova Apr 14, 2021
5db8e3d
File name substituted with absolute path
dariadiatlova Apr 14, 2021
b708c1d
Adding new func names
dariadiatlova Apr 15, 2021
c5c75d9
Update evaluation tests
dariadiatlova Apr 15, 2021
f901771
Files for evaluation testing
dariadiatlova Apr 15, 2021
30ba7b2
Update functionality xlsx-run tool
dariadiatlova Apr 15, 2021
61a054f
Adding MAIN_FOLDER
dariadiatlova Apr 15, 2021
62bce7d
Evaluation tool-interface update
dariadiatlova Apr 15, 2021
90edf16
Updating evaluation tests
dariadiatlova Apr 15, 2021
c0eeed2
Change mode for opening file
dariadiatlova Apr 16, 2021
7439faa
Adding file exist exception
dariadiatlova Apr 16, 2021
4641276
Assertation update
dariadiatlova Apr 16, 2021
685d0bb
Adding gitkeep
dariadiatlova Apr 16, 2021
296efac
Adiing gitkeep
dariadiatlova Apr 16, 2021
6acc246
Fixed typing issue
dariadiatlova Apr 17, 2021
fe4877f
Resolving conflicts
dariadiatlova Apr 17, 2021
efd5dcb
Merge branch 'develop' into xlsx_run_tool
GirZ0n Apr 18, 2021
8082f78
Fixed imports
GirZ0n Apr 18, 2021
ab62d8a
Fixed imports
GirZ0n Apr 18, 2021
b8d6156
Updated evaluation module
dariadiatlova Apr 21, 2021
fa2c376
Added common class with run_tool arguments
dariadiatlova Apr 21, 2021
85973c0
Updated run_tool argnames and several functions
dariadiatlova Apr 21, 2021
11772d6
Updated evaluation tests
dariadiatlova Apr 21, 2021
9ceeb73
Updated evaluation resources
dariadiatlova Apr 21, 2021
dc12b8b
Resolving conflicts
dariadiatlova Apr 21, 2021
9653133
Fixed merging issue
dariadiatlova Apr 21, 2021
1a52079
Fixed merging issue
dariadiatlova Apr 21, 2021
4c8a54d
Fixed Flake inspection
dariadiatlova Apr 21, 2021
b7187fd
Fixed Flake inspection issue
dariadiatlova Apr 21, 2021
6ec4240
Added util
dariadiatlova Apr 21, 2021
21f4cfd
Added logger to check test output
dariadiatlova Apr 21, 2021
5303706
Added logger to check test output
dariadiatlova Apr 21, 2021
39d3a38
Save artifacts for debugging
dariadiatlova Apr 22, 2021
137f800
Updated tests to save artefacts
dariadiatlova Apr 22, 2021
1686785
Dedugging loggits
dariadiatlova Apr 22, 2021
ec560a8
Updated resources
dariadiatlova Apr 22, 2021
e6111e1
Remove saved files after debugging
dariadiatlova Apr 22, 2021
31f1235
Added evaluation README.me
dariadiatlova Apr 22, 2021
76ecafe
Updated readme and fixed argname
dariadiatlova Apr 22, 2021
53f45f1
Resolved pull request issues
dariadiatlova Apr 26, 2021
f07a717
Resolved pull request issues
dariadiatlova Apr 26, 2021
7b1a14a
Resolved pull request issues
dariadiatlova Apr 26, 2021
ede99f8
Resolved pull request issues
dariadiatlova Apr 26, 2021
a7fd99f
Updated flags in README.md
dariadiatlova Apr 26, 2021
5dd2adc
Update README.md
dariadiatlova Apr 26, 2021
04123e0
Update README.md
dariadiatlova Apr 26, 2021
9e3873f
Update README.md
dariadiatlova Apr 26, 2021
4ca4610
Update README.md
dariadiatlova Apr 27, 2021
7eab17e
Added a penalty system.
GirZ0n Apr 27, 2021
f54bba8
Fixed bug
GirZ0n Apr 27, 2021
b7be84f
Fixed tests
GirZ0n Apr 27, 2021
bed4b53
Update README.md
dariadiatlova Apr 28, 2021
d6bbc11
Added a separate requirements file for evaluation module
dariadiatlova Apr 28, 2021
7535452
Resolved PR issues
dariadiatlova Apr 28, 2021
b025607
Merge branch 'xlsx_run_tool' of https://github.com/hyperskill/hyperst…
dariadiatlova Apr 28, 2021
e226611
Resolved PR issues
GirZ0n Apr 28, 2021
8c6b0d9
Merge branch 'xlsx_run_tool' into penalty
GirZ0n Apr 28, 2021
7e63044
Removed extra spaces
GirZ0n Apr 28, 2021
3785322
Small fix
GirZ0n Apr 28, 2021
b141186
Merge remote-tracking branch 'origin/penalty' into penalty
GirZ0n Apr 28, 2021
56ba38a
Fixed example
GirZ0n May 1, 2021
2f6cf3a
Fixed description
GirZ0n May 1, 2021
b3e9ae3
Fixed PR issues
GirZ0n May 1, 2021
5d5fc4e
Merge branch 'develop' into penalty
nbirillo May 3, 2021
19e9227
Fix merge conflicts
nbirillo May 3, 2021
4ea2c34
delete evaluation
nbirillo May 3, 2021
e1b628e
add evaluation
nbirillo May 3, 2021
906fe95
Bugfix/tmp files (#27)
nbirillo May 4, 2021
40a3383
Added tests
GirZ0n May 4, 2021
ff2a12d
Moved penalty.py to quality folder
GirZ0n May 4, 2021
3f97c51
Added Punisher
GirZ0n May 4, 2021
0cead1a
Removed unnecessary code
GirZ0n May 4, 2021
d21694c
Fixed PR issues
GirZ0n May 4, 2021
4ec1c6c
Code refactoring
GirZ0n May 4, 2021
15b691d
Removed unnecessary comment
GirZ0n May 4, 2021
661264e
Rollback unwanted changes
GirZ0n May 5, 2021
ca11b1f
Fixed PR issue
GirZ0n May 5, 2021
512a4c1
Added description for Punisher
GirZ0n May 5, 2021
764f665
Code refactoring
GirZ0n May 5, 2021
7cd2f57
small fix
GirZ0n May 5, 2021
7a97e33
Fixed flake issues
GirZ0n May 5, 2021
6dc44ff
Bug fix
GirZ0n May 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Argument | Description
**‑s**, **‑‑start-line**| the first line to be analyzed. By default it starts from `1`.
**‑e**, **‑‑end-line** | the end line to be analyzed. The default value is `None`, which meant to handle file by the end.
**‑‑new-format** | the argument determines whether the tool should use the _new format_. _New format_ means separating the result by the files to allow getting quality and observed issues for each file separately. The default value is `False`.
**‑‑history** | JSON string with a list of issues for each language. For each issue its class and quantity are specified. Example: `--history "{\"python\": [{\"origin_class\": \"SC200\", \"number\": 20}, {\"origin_class\": \"WPS314\", \"number\": 3}]}"`

The output examples:

Expand All @@ -124,7 +125,8 @@ The output examples:
"line": "<the code line>",
"line_number": 54,
"column_number": 0,
"category": "FUNC_LEN"
"category": "FUNC_LEN",
"influence_on_penalty": 0
},
...
]
Expand Down Expand Up @@ -153,7 +155,8 @@ The output examples:
"line": "<the code line>",
"line_number": 174,
"column_number": 12,
"category": "BEST_PRACTICES"
"category": "BEST_PRACTICES",
"influence_on_penalty": 0
},
...
]
Expand Down
4 changes: 4 additions & 0 deletions src/python/common/tool_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ class RunToolArgument(Enum):
NEW_FORMAT = ArgumentsInfo(None, '--new-format',
'The argument determines whether the tool '
'should use the new format')

HISTORY = ArgumentsInfo(None, '--history',
'Json string, which contains lists of issues in the previous submissions '
'for other tasks for one user.')
63 changes: 33 additions & 30 deletions src/python/evaluation/xlsx_run_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from src.python.evaluation.evaluation_config import EvaluationConfig
from src.python.review.application_config import LanguageVersion
from src.python.review.common.file_system import create_file, new_temp_dir
from src.python.review.common.file_system import create_file
from src.python.review.common.subprocess_runner import run_in_subprocess
from src.python.review.reviewers.perform_review import OutputFormat

Expand Down Expand Up @@ -72,6 +72,15 @@ def configure_arguments(parser: argparse.ArgumentParser, run_tool_arguments: Typ
'is enabled argument will not be used otherwise.')


def get_language(lang_key: str) -> LanguageVersion:
try:
return LanguageVersion(lang_key)
except ValueError as e:
logger.error(script_structure_rule)
# We should raise KeyError since it is incorrect value for key in a column
raise KeyError(e)


def create_dataframe(config: EvaluationConfig) -> pd.DataFrame:
report = pd.DataFrame(
{
Expand All @@ -95,35 +104,29 @@ def create_dataframe(config: EvaluationConfig) -> pd.DataFrame:
for lang, code in zip(lang_code_dataframe[ColumnName.LANG.value],
lang_code_dataframe[ColumnName.CODE.value]):

with new_temp_dir() as create_temp_dir:
temp_dir_path = create_temp_dir
lang_extension = LanguageVersion.language_by_extension(lang)
temp_file_path = os.path.join(temp_dir_path, ('file' + lang_extension))
temp_file_path = next(create_file(temp_file_path, code))

try:
assert os.path.exists(temp_file_path)
except AssertionError as e:
logger.exception('Path does not exist.')
raise e

command = config.build_command(temp_file_path, lang)
results = run_in_subprocess(command)
os.remove(temp_file_path)
temp_dir_path.rmdir()
# this regular expression matches final tool grade: EXCELLENT, GOOD, MODERATE or BAD
grades = re.match(r'^.*{"code":\s"([A-Z]+)"', results).group(1)
output_row_values = [lang, code, grades]
column_indices = [ColumnName.LANGUAGE.value,
ColumnName.CODE.value,
ColumnName.GRADE.value]

if config.traceback:
output_row_values.append(results)
column_indices.append(EvaluationArgument.TRACEBACK.value)

new_file_report_row = pd.Series(data=output_row_values, index=column_indices)
report = report.append(new_file_report_row, ignore_index=True)
# Tool does not work correctly with tmp files from <tempfile> module on macOS
# thus we create a real file in the file system
extension = get_language(lang).extension_by_language().value
tmp_file_path = config.xlsx_file_path.parent.absolute() / f'inspected_code{extension}'
temp_file = next(create_file(tmp_file_path, code))

command = config.build_command(temp_file, lang)
results = run_in_subprocess(command)
os.remove(temp_file)

# this regular expression matches final tool grade: EXCELLENT, GOOD, MODERATE or BAD
grades = re.match(r'^.*{"code":\s"([A-Z]+)"', results).group(1)
output_row_values = [lang, code, grades]
column_indices = [ColumnName.LANGUAGE.value,
ColumnName.CODE.value,
ColumnName.GRADE.value]

if config.traceback:
output_row_values.append(results)
column_indices.append(EvaluationArgument.TRACEBACK.value)

new_file_report_row = pd.Series(data=output_row_values, index=column_indices)
report = report.append(new_file_report_row, ignore_index=True)

return report

Expand Down
24 changes: 12 additions & 12 deletions src/python/review/application_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from enum import Enum, unique
from typing import List, Optional, Set
from typing import Dict, List, Optional, Set

from src.python.review.common.file_system import Extension
from src.python.review.inspectors.inspector_type import InspectorType
Expand All @@ -15,6 +15,7 @@ class ApplicationConfig:
start_line: int = 1
end_line: Optional[int] = None
new_format: bool = False
history: Optional[str] = None


@unique
Expand All @@ -31,14 +32,13 @@ def values(cls) -> List[str]:
return [member.value for member in cls.__members__.values()]

@classmethod
def language_to_extension_dict(cls) -> dict:
return {cls.PYTHON_3.value: Extension.PY.value,
cls.JAVA_7.value: Extension.JAVA.value,
cls.JAVA_8.value: Extension.JAVA.value,
cls.JAVA_9.value: Extension.JAVA.value,
cls.JAVA_11.value: Extension.JAVA.value,
cls.KOTLIN.value: Extension.KT.value}

@classmethod
def language_by_extension(cls, lang: str) -> str:
return cls.language_to_extension_dict()[lang]
def language_to_extension_dict(cls) -> Dict['LanguageVersion', Extension]:
return {cls.PYTHON_3: Extension.PY,
cls.JAVA_7: Extension.JAVA,
cls.JAVA_8: Extension.JAVA,
cls.JAVA_9: Extension.JAVA,
cls.JAVA_11: Extension.JAVA,
cls.KOTLIN: Extension.KT}

def extension_by_language(self) -> Extension:
return self.language_to_extension_dict()[self]
6 changes: 5 additions & 1 deletion src/python/review/common/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from contextlib import contextmanager
from enum import Enum, unique
from pathlib import Path
from typing import Callable, List, Union
from typing import Callable, List, Tuple, Union


@unique
Expand Down Expand Up @@ -61,6 +61,10 @@ def new_temp_dir() -> Path:
yield Path(temp_dir)


def new_temp_file(suffix: Extension = Extension.EMPTY) -> Tuple[str, str]:
yield tempfile.mkstemp(suffix=suffix.value)


# File should contain the full path and its extension.
# Create all parents if necessary
def create_file(file_path: Union[str, Path], content: str):
Expand Down
9 changes: 6 additions & 3 deletions src/python/review/quality/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ class QualityType(Enum):
GOOD = 'GOOD'
EXCELLENT = 'EXCELLENT'

def __le__(self, other: 'QualityType') -> bool:
order = {
def to_number(self) -> int:
type_to_number = {
QualityType.BAD: 0,
QualityType.MODERATE: 1,
QualityType.GOOD: 2,
QualityType.EXCELLENT: 3,
}

return order[self] < order[other]
return type_to_number.get(self, 3)

def __le__(self, other: 'QualityType') -> bool:
return self.to_number() < other.to_number()


class Rule(abc.ABC):
Expand Down
Loading