Skip to content

Commit

Permalink
remove linters covered by ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
hofbi committed Jan 23, 2024
1 parent 9c834e4 commit 25176a2
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 58 deletions.
36 changes: 7 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,19 @@ repos:
- id: cmake-lint
additional_dependencies: [cmakelang]
exclude: cmake/.*
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: ruff
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- id: ruff-format
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-pyproject
- flake8-use-pathlib
- flake8-bugbear
- flake8-comprehensions
- flake8-requirements
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- flake8-bugbear # Ruff does not implement all of bugbear
- flake8-requirements # Not yet implemented https://github.com/astral-sh/ruff/issues/4100
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
Expand All @@ -144,14 +130,6 @@ repos:
hooks:
- id: pyupgrade
args: [--py310-plus, --keep-runtime-typing]
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.6
hooks:
Expand All @@ -161,6 +139,6 @@ repos:
hooks:
- id: check-github-workflows
- repo: https://github.com/crate-ci/typos
rev: v1.16.26
rev: v1.17.2
hooks:
- id: typos
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ max-line-length = 120
[tool.flake8.known-modules]
"" = ["sel_tools", "tests", "gitlab_projects", "create_gitlab_projects", "export_files"]

[tool.isort]
profile = "black"

[tool.mypy]
check_untyped_defs = true
disallow_incomplete_defs = true
Expand Down Expand Up @@ -57,19 +54,18 @@ disable = [

[tool.ruff]
fix = true
line-length = 120
target-version = "py310"
select = ["ALL"]
ignore = [
"A",
"ANN",
"ARG",
"COM", # Done via black
"COM", # Done via formatter
"D",
"DTZ001", # TODO: Enable
"E501", # Done via formatter
"FBT",
"FIX",
"I", # Done via isort
"INP",
"PERF203",
"PT", # We don't use pytest here
Expand Down
4 changes: 3 additions & 1 deletion slides/lecture/example/slide-deck.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Author Name

## Key Takeaways

- Having slides in markdown is awesome
<!-- Question: What are your key takeaways? -->

* Having slides in markdown is awesome

---
5 changes: 5 additions & 0 deletions tools/sel_tools/code_evaluation/jobs/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class ClangTidyTestJob(EvaluationJob):
def _run(self, repo_path: Path) -> int:
copy_item(CMAKE_MODULE_PATH, repo_path)
cmake_lists = repo_path / CMAKELISTS_FILE_NAME

if not cmake_lists.exists():
self._comment = f"{CMAKELISTS_FILE_NAME} not found"
return 0

content = cmake_lists.read_text()
content += "\n"
content += f"list(APPEND CMAKE_MODULE_PATH ${{PROJECT_SOURCE_DIR}}/{CMAKE_MODULE_PATH.stem})\n"
Expand Down
6 changes: 3 additions & 3 deletions tools/sel_tools/file_parsing/student_group_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Student:
"""Student information."""

first_name: str
surname: str
last_name: str
mail_addr: str
choice: str
gitlab_user: User = None

@property
def name(self) -> str:
return f"{self.first_name} {self.surname}"
return f"{self.first_name} {self.last_name}"

@property
def valid_choice(self) -> bool:
Expand All @@ -37,7 +37,7 @@ def group_id(self) -> int:
def from_dict(student_dict: dict) -> "Student":
return Student(
student_dict["First name"],
student_dict["Surname"],
student_dict["Last name"],
student_dict["Email address"],
student_dict["Choice"],
)
Expand Down
3 changes: 3 additions & 0 deletions tools/sel_tools/gitlab_api/add_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

import gitlab

from sel_tools.config import GITLAB_SERVER_URL
from sel_tools.file_parsing.student_group_parser import (
Student,
Expand Down Expand Up @@ -37,11 +38,13 @@ def find_gitlab_users_of_students(
]
except IndexError:
student.gitlab_user = None
print(f"Student {student.name} with {student.mail_addr} not found!")
return [student for student in students if student.gitlab_user is not None]


def add_students_to_repos(students: list[Student], repo_from_group_id: dict) -> None:
"""Add students to repositories."""
print(f"Adding {len(students)} to their projects!")
for student in students:
repo = repo_from_group_id[student.group_id]
repo.members.create(
Expand Down
38 changes: 37 additions & 1 deletion tools/tests/code_evaluation/jobs/test_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

from pyfakefs.fake_filesystem_unittest import TestCase
from sel_tools.code_evaluation.jobs.cpp import (
ClangTidyTestJob,
CleanRepoJob,
CMakeBuildJob,
CodeCoverageTestJob,
MakeTestJob,
OOPTestJob,
)
from sel_tools.config import HW_BUILD_FOLDER
from sel_tools.config import CMAKE_MODULE_PATH, HW_BUILD_FOLDER
from sel_tools.utils.config import CMAKELISTS_FILE_NAME


def coverage_file_content(total_coverage: int) -> str:
Expand Down Expand Up @@ -73,6 +75,40 @@ def test_call_with_cmake_options(self, mock: MagicMock) -> None:
self.assertEqual(2, len(mock.call_args_list))


class ClangTidyTestJobTest(TestCase):
"""Tests for the clang-tidy test job."""

def setUp(self) -> None:
self.setUpPyfakefs()
self.unit = ClangTidyTestJob()
self.repo_path = Path("repo")
self.build_folder = self.repo_path / HW_BUILD_FOLDER
self.fs.create_dir(CMAKE_MODULE_PATH)

@patch(
"sel_tools.code_evaluation.jobs.cpp.run_shell_command",
MagicMock(return_value=1),
)
def test_run_impl_success(self) -> None:
cmake_list = self.repo_path / CMAKELISTS_FILE_NAME
self.fs.create_file(cmake_list)
result = self.unit.run(self.repo_path)
self.assertEqual(1, result[0].score)
self.assertIn(
"include(ClangTidy)",
cmake_list.read_text(),
)

@patch(
"sel_tools.code_evaluation.jobs.cpp.run_shell_command",
MagicMock(return_value=1),
)
def test_run_impl_fail_cmake_list_does_not_exist(self) -> None:
result = self.unit.run(self.repo_path)
self.assertEqual(0, result[0].score)
self.assertEqual("CMakeLists.txt not found", result[0].comment)


class MakeTestJobTest(TestCase):
"""Tests for make test job."""

Expand Down
23 changes: 12 additions & 11 deletions tools/tests/file_parsing/test_student_group_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
Student,
get_student_groups_from_file,
)

from tests.helper import STUDENT1, STUDENT2

HEADERS_GERMAN = [
"Nachname",
"Vorname",
"Matrikelnummer",
"E-Mail-Adresse",
"Gruppe",
"Abstimmung",
]
STUDENT_NOT_ANSWERED = {
"Surname": "def",
"Last name": "def",
"First name": "abc",
"matriculation-id": "01234567",
"Email address": "abc.def@tum.de",
Expand All @@ -39,7 +32,7 @@ def test_from_dict(self) -> None:
Student.from_dict(STUDENT1),
Student(
STUDENT1["First name"],
STUDENT1["Surname"],
STUDENT1["Last name"],
STUDENT1["Email address"],
STUDENT1["Choice"],
),
Expand Down Expand Up @@ -86,7 +79,15 @@ def test_not_answered_yet(self) -> None:

def test_file_in_german(self) -> None:
content = DataFrame([STUDENT1, STUDENT2])
content.to_csv("group_formation.csv", header=HEADERS_GERMAN)
headers_german = [
"Nachname",
"Vorname",
"Matrikelnummer",
"E-Mail-Adresse",
"Gruppe",
"Abstimmung",
]
content.to_csv("group_formation.csv", header=headers_german)
self.assertRaises(
KeyError, get_student_groups_from_file, Path("group_formation.csv")
)
Expand Down
11 changes: 6 additions & 5 deletions tools/tests/gitlab_api/test_add_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
add_students_to_repos,
find_gitlab_users_of_students,
)

from tests.helper import STUDENT1, STUDENT2, GitlabUserFake, GitlabUserManagerFake

STUDENT_NO_GITLAB_ACC = {
"Surname": "rst",
"Last name": "rst",
"First name": "abc",
"matriculation-id": "01234567",
"Email address": "abc.rst@mytum.de",
"Group": "Standardgruppe 123456",
"Choice": "Group 2",
}
STUDENT_MISSING_GROUP = {
"Surname": "rst",
"Last name": "rst",
"First name": "opq",
"matriculation-id": "01235813",
"Email address": "opq.rst@tum.de",
Expand All @@ -45,17 +46,17 @@ def setUp(self) -> None:
self.mock_instance.user1 = GitlabUserFake(
"12345",
STUDENT1["Email address"],
f"{STUDENT1['First name']} {STUDENT1['Surname']}",
f"{STUDENT1['First name']} {STUDENT1['Last name']}",
)
self.mock_instance.user2 = GitlabUserFake(
"35711",
STUDENT2["Email address"],
f"{STUDENT2['First name']} {STUDENT2['Surname']}",
f"{STUDENT2['First name']} {STUDENT2['Last name']}",
)
self.mock_instance.user3 = GitlabUserFake(
"35711",
STUDENT_MISSING_GROUP["Email address"],
f"{STUDENT_MISSING_GROUP['First name']} {STUDENT_MISSING_GROUP['Surname']}",
f"{STUDENT_MISSING_GROUP['First name']} {STUDENT_MISSING_GROUP['Last name']}",
)
self.mock_instance.users = GitlabUserManagerFake(
[
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from sel_tools.config import GIT_MAIN_BRANCH

STUDENT1 = {
"Surname": "xyz",
"Last name": "xyz",
"First name": "uvw",
"matriculation-id": "09876543",
"Email address": "uvw.xyz@mytum.de",
"Group": "Standardgruppe 123456",
"Choice": "Group 1",
}
STUDENT2 = {
"Surname": "äöü",
"Last name": "äöü",
"First name": "opq",
"matriculation-id": "02358113",
"Email address": "aeoeue.rst@tum.de",
Expand Down

0 comments on commit 25176a2

Please sign in to comment.