Skip to content

Commit

Permalink
Make linter setting configurable (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
niosus authored Sep 4, 2022
1 parent 8db9106 commit 26899b9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions homework_checker/core/schema_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def __init__(self: SchemaManager, file_name: Path):
Optional(Tags.TIMEOUT_TAG, default=60): float,
}

style_check_schema = {
Tags.NAME_TAG: str,
}

task_schema = {
Tags.NAME_TAG: str,
Tags.LANGUAGE_TAG: Or(LangTags.CPP, LangTags.BASH),
Expand All @@ -57,6 +61,7 @@ def __init__(self: SchemaManager, file_name: Path):
BuildTags.CMAKE, BuildTags.SIMPLE
),
Optional(Tags.BUILD_TIMEOUT_TAG, default=60): float,
Optional(Tags.STYLE_CHECKERS_TAG): [style_check_schema],
Optional(Tags.TESTS_TAG): [test_schema],
}

Expand Down
1 change: 1 addition & 0 deletions homework_checker/core/schema_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Tags:
OUTPUT_PIPE_TAG = "output_pipe_args"
OUTPUT_TYPE_TAG = "output_type"
RUN_GTESTS_TAG = "run_google_tests"
STYLE_CHECKERS_TAG = "style_checkers"
TASKS_TAG = "tasks"
TESTS_TAG = "tests"
TIMEOUT_TAG = "timeout"
Expand Down
27 changes: 21 additions & 6 deletions homework_checker/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def __init__(
self._binary_name = task_node[Tags.BINARY_NAME_TAG]
self._build_timeout = task_node[Tags.BUILD_TIMEOUT_TAG]

self._style_checkers = []
if Tags.STYLE_CHECKERS_TAG in task_node:
self._style_checkers = task_node[Tags.STYLE_CHECKERS_TAG]

self._test_nodes = []
if Tags.TESTS_TAG in task_node:
self._test_nodes = task_node[Tags.TESTS_TAG]
Expand Down Expand Up @@ -137,9 +141,16 @@ def run_all_tests(
run_all_tests(test_node=test_node, executable_folder=build_folder)
)

style_errors = self._code_style_errors()
if style_errors:
results[STYLE_ERROR_TAG] = style_errors
if self._style_checkers:
for checker in self._style_checkers:
checker_name = checker[Tags.NAME_TAG]
style_errors = self._code_style_errors(checker_name)
if style_errors:
results[
"{tag} {checker}".format(
tag=STYLE_ERROR_TAG, checker=checker_name
)
] = style_errors
return results

def __get_folders_to_inject(
Expand Down Expand Up @@ -177,7 +188,7 @@ def _build_if_needed(self: Task, code_folder: Path):
return None, code_folder

@abc.abstractmethod
def _code_style_errors(self: Task):
def _code_style_errors(self: Task, checker_name: str):
return None


Expand Down Expand Up @@ -219,8 +230,12 @@ def _build_if_needed(
code_folder,
)

def _code_style_errors(self: CppTask) -> Optional[tools.CmdResult]:
def _code_style_errors(
self: CppTask, checker_name: str
) -> Optional[tools.CmdResult]:
"""Check if code conforms to Google Style."""
if checker_name != "cpplint":
return None
command = (
"cpplint --counting=detailed "
+ "--filter=-legal,-readability/todo,"
Expand Down Expand Up @@ -298,7 +313,7 @@ def __init__(self: BashTask, task_node: dict, root_folder: Path, job_file: Path)
def _build_if_needed(self: BashTask, code_folder: Path):
return None, code_folder # There is nothing to build in Bash.

def _code_style_errors(self: BashTask):
def _code_style_errors(self: BashTask, checker_name: str):
return None

def _run_test(
Expand Down
2 changes: 2 additions & 0 deletions schema/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ homeworks:
~[optional]~ compiler_flags: String value
~[optional]~ build_type: Any of ['cmake', 'simple']
~[optional]~ output_type: Any of ['string', 'number']
~[optional]~ style_checkers:
- name: String value
~[optional]~ tests:
- name: String value
~[optional]~ expected_output: Any of ['String value', 'Float value', 'Int value']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from setuptools import find_packages
from setuptools.command.install import install

VERSION_STRING = "1.0.4"
VERSION_STRING = "1.1.0"

PACKAGE_NAME = "homework_checker"

Expand Down

0 comments on commit 26899b9

Please sign in to comment.