Skip to content

Commit 669e930

Browse files
authored
Modernize package for 2020 (#1)
- move the code to the new folder - use black linter and check it in CI - remove unused build scripts - switch from gtest to googletest - use pipenv for easy setup - add github actions for checking this code
1 parent 750a42d commit 669e930

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+851
-508
lines changed

.github/workflows/main.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-20.04
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Set up Python
12+
uses: actions/setup-python@v2
13+
with:
14+
python-version: '3.8'
15+
architecture: 'x64'
16+
- name: Install prerequisites
17+
run: |
18+
sudo apt install -y libgtest-dev
19+
python -m pip install --upgrade pip pipenv
20+
- name: Initialize workspace
21+
run: >
22+
pipenv install
23+
- name: Lint with Black linter
24+
run: >
25+
pipenv run black homework_checker --check --diff
26+
- name: Run unit tests
27+
run: >
28+
pipenv run python3 -m unittest discover -v homework_checker/tests/
29+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ build/
2222
/.coverage
2323

2424
/coverage.xml
25+
26+
!Pipfile

.gitlab-ci.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

Pipfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
"ruamel.yaml" = "*"
8+
schema = "*"
9+
cpplint = "*"
10+
datetime = "*"
11+
black = "*"
12+
13+
[dev-packages]
14+
15+
[requires]
16+
python_version = "3.8"

Pipfile.lock

Lines changed: 289 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

homework_checker/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Homework checker module."""
2+
3+
name = "homework_checker"
4+
5+
__all__ = (
6+
"check_homework",
7+
"checker",
8+
"md_writer",
9+
"schema_manager",
10+
"schema_tags",
11+
"tasks" "tools" "tests",
12+
)

ipb_homework_checker/check_homework.py renamed to homework_checker/check_homework.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ def main():
1616
"""Run this script."""
1717
parser = argparse.ArgumentParser()
1818
parser.add_argument(
19-
'-v', '--verbose',
20-
help='Make the output verbose.',
21-
action='store_true')
19+
"-v", "--verbose", help="Make the output verbose.", action="store_true"
20+
)
2221
parser.add_argument(
23-
'-i', '--input',
24-
help='An input *.yml file with the job definition.',
25-
required=True)
22+
"-i",
23+
"--input",
24+
help="An input *.yml file with the job definition.",
25+
required=True,
26+
)
2627
parser.add_argument(
27-
'-o', '--output',
28-
help='An output *.md file with the results.',
29-
required=True)
28+
"-o", "--output", help="An output *.md file with the results.", required=True
29+
)
3030
args = parser.parse_args()
3131
if args.verbose:
3232
log.setLevel(logging.DEBUG)
33-
log.debug('Enable DEBUG logging.')
33+
log.debug("Enable DEBUG logging.")
3434
# Read the job file.
3535
log.debug('Reading from file "%s"', args.input)
3636
checker = Checker(args.input)

ipb_homework_checker/checker.py renamed to homework_checker/checker.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616

1717
class Checker:
1818
"""Check homework."""
19-
TESTS_TAG = 'tests'
19+
20+
TESTS_TAG = "tests"
2021

2122
def __init__(self, job_file_path):
2223
"""Initialize the checker from file."""
2324
self._job_file_path = tools.expand_if_needed(job_file_path)
2425
schema_manager = SchemaManager(self._job_file_path)
2526
self._base_node = schema_manager.validated_yaml
2627
self._checked_code_folder = tools.expand_if_needed(
27-
self._base_node[Tags.FOLDER_TAG])
28+
self._base_node[Tags.FOLDER_TAG]
29+
)
2830
# The results of all tests will be kept here.
2931
self._results = {}
3032

@@ -33,22 +35,23 @@ def check_homework(self):
3335
results = {}
3436
for homework_node in self._base_node[Tags.HOMEWORKS_TAG]:
3537
current_folder = path.join(
36-
self._checked_code_folder, homework_node[Tags.FOLDER_TAG])
38+
self._checked_code_folder, homework_node[Tags.FOLDER_TAG]
39+
)
3740
if not path.exists(current_folder):
38-
log.warning("Folder '%s' does not exist. Skiping.",
39-
current_folder)
41+
log.warning("Folder '%s' does not exist. Skiping.", current_folder)
4042
continue
4143
hw_name = homework_node[Tags.NAME_TAG]
4244
results[hw_name] = {}
4345
deadline_str = homework_node[Tags.DEADLINE_TAG]
44-
deadline_datetime = datetime.strptime(deadline_str,
45-
tools.DATE_PATTERN)
46+
deadline_datetime = datetime.strptime(deadline_str, tools.DATE_PATTERN)
4647
if datetime.now() > deadline_datetime:
4748
results[hw_name][tools.EXPIRED_TAG] = True
4849
for task_node in homework_node[Tags.TASKS_TAG]:
49-
task = Task.from_yaml_node(task_node=task_node,
50-
student_hw_folder=current_folder,
51-
job_file=self._job_file_path)
50+
task = Task.from_yaml_node(
51+
task_node=task_node,
52+
student_hw_folder=current_folder,
53+
job_file=self._job_file_path,
54+
)
5255
if not task:
5356
continue
5457
results[hw_name][task.name] = task.check_all_tests()

ipb_homework_checker/md_writer.py renamed to homework_checker/md_writer.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class MdWriter:
3636

3737
def __init__(self):
3838
"""Initialize the writer."""
39-
self._md_table = TABLE_TEMPLATE.format(hw_name='Homework Name',
40-
task_name='Task Name',
41-
test_name='Test Name',
42-
result_sign='Result')
39+
self._md_table = TABLE_TEMPLATE.format(
40+
hw_name="Homework Name",
41+
task_name="Task Name",
42+
test_name="Test Name",
43+
result_sign="Result",
44+
)
4345
self._md_table += TABLE_SEPARATOR
44-
self._errors = '' # Markdown part with errors.
46+
self._errors = "" # Markdown part with errors.
4547

4648
def update(self, hw_results):
4749
"""Update the table of completion."""
@@ -58,34 +60,30 @@ def update(self, hw_results):
5860
continue
5961
need_task_name = True
6062
for test_name, test_result in sorted(ex_dict.items()):
61-
result_sign = SUCCESS_TAG \
62-
if test_result.succeeded() \
63-
else FAILED_TAG
64-
extended_hw_name = hw_name + " `[PAST DEADLINE]`" \
65-
if expired else hw_name
63+
result_sign = SUCCESS_TAG if test_result.succeeded() else FAILED_TAG
64+
extended_hw_name = (
65+
hw_name + " `[PAST DEADLINE]`" if expired else hw_name
66+
)
6667
self._md_table += TABLE_TEMPLATE.format(
67-
hw_name=extended_hw_name if need_hw_name else '',
68-
task_name=task_name if need_task_name else '',
68+
hw_name=extended_hw_name if need_hw_name else "",
69+
task_name=task_name if need_task_name else "",
6970
test_name=test_name,
70-
result_sign=result_sign)
71-
self._add_error(hw_name,
72-
task_name,
73-
test_name,
74-
test_result,
75-
expired)
71+
result_sign=result_sign,
72+
)
73+
self._add_error(hw_name, task_name, test_name, test_result, expired)
7674
need_hw_name = False # We only print homework name once.
7775
need_task_name = False # We only print Task name once.
7876

7977
def write_md_file(self, md_file_path):
8078
"""Write all the added content to the md file."""
81-
md_file_content = '# Test results\n'
79+
md_file_content = "# Test results\n"
8280
md_file_content += self._md_table
8381
if self._errors:
84-
md_file_content += '\n## Encountered errors\n'
82+
md_file_content += "\n## Encountered errors\n"
8583
md_file_content += self._errors
8684
md_file_content += SEPARATOR
8785
md_file_content += FINISHING_NOTE
88-
with open(md_file_path, 'w') as md_file:
86+
with open(md_file_path, "w") as md_file:
8987
md_file.write(md_file_content)
9088

9189
def _add_error(self, hw_name, task_name, test_name, test_result, expired):
@@ -95,8 +93,10 @@ def _add_error(self, hw_name, task_name, test_name, test_result, expired):
9593
if expired:
9694
self._errors += EXPIRED_TEMPLATE.format(hw_name=hw_name)
9795
return
98-
self._errors += ERROR_TEMPLATE.format(hw_name=hw_name,
99-
task_name=task_name,
100-
test_name=test_name,
101-
stderr=test_result.stderr,
102-
stdout=test_result.stdout)
96+
self._errors += ERROR_TEMPLATE.format(
97+
hw_name=hw_name,
98+
task_name=task_name,
99+
test_name=test_name,
100+
stderr=test_result.stderr,
101+
stdout=test_result.stdout,
102+
)

0 commit comments

Comments
 (0)