Skip to content

Commit

Permalink
add new hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
hofbi committed Jan 30, 2023
1 parent 2b28954 commit baf2031
Show file tree
Hide file tree
Showing 29 changed files with 196 additions and 82 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[flake8]
max-line-length = 120
known-modules = :[sel_tools,tests,gitlab_projects,create_gitlab_projects,export_files]
24 changes: 6 additions & 18 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,19 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
7 changes: 4 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ python_tests:
script:
- make test
- make coverage_reports
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
expire_in: 1 week
paths:
Expand Down Expand Up @@ -154,9 +155,9 @@ student_code_evaluation:
SEL_CI_MODE: $CI
script:
- mkdir -p $WORKSPACE
- echo "$REPO_INFO_FILE" # has to be set in the schedule definition
- echo "$HOMEWORK_NUMBER" # has to be set in the schedule definition
- echo "$LAST_HOMEWORK_DATE" # has to be set in the schedule definition
- echo "$REPO_INFO_FILE" # has to be set in the schedule definition
- echo "$HOMEWORK_NUMBER" # has to be set in the schedule definition
- echo "$LAST_HOMEWORK_DATE" # has to be set in the schedule definition
- python3 tools/gitlab_projects.py evaluate_code $REPO_INFO_FILE --gitlab-token $GITLAB_TOKEN --homework-number $HOMEWORK_NUMBER --date-last-homework $LAST_HOMEWORK_DATE --workspace $WORKSPACE
# GITLAB_TOKEN is a protected & masked variable set in this project and contains a gitlab API token with "read_api" scope
artifacts:
Expand Down
10 changes: 10 additions & 0 deletions .md-link-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ignorePatterns": [
{
"pattern": "^https://"
},
{
"pattern": "^http://"
}
]
}
50 changes: 42 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repos:
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
- id: check-yaml
exclude: (?x)( .gitlab-ci.yml | .clang-format )
- id: debug-statements
Expand All @@ -39,24 +40,39 @@ repos:
additional_dependencies:
- mdformat-gfm
- mdformat-black
- mdformat-shfmt
- mdformat-config
- mdformat-toc
- repo: https://github.com/tcort/markdown-link-check
rev: v3.10.3
hooks:
- id: markdown-link-check
args: ["--quiet", "--config", ".md-link-config.json"]
exclude: ^slides/homework
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.2
hooks:
- id: yamlfmt
args: [--mapping, '2', --sequence, '4', --offset, '2', --implicit_start]
args: [--mapping=2, --sequence=4, --offset=2, --implicit_start, --preserve-quotes]
exclude: (?x)( .gitlab-ci.yml | .clang-format | .clang-tidy )
- repo: https://github.com/adrienverge/yamllint
rev: v1.29.0
hooks:
- id: yamllint
args: [--strict]
exclude: (?x)( .clang-format | .clang-tidy | docs/theme/tum.yml )
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
rev: v1.5.0
hooks:
- id: docformatter
args: [--in-place, --wrap-summaries, '88', --wrap-descriptions, '81']
additional_dependencies: [tomli]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.6
rev: v15.0.7
hooks:
- id: clang-format
- repo: https://github.com/cpplint/cpplint
Expand All @@ -71,6 +87,20 @@ repos:
- id: cmake-lint
additional_dependencies: [cmakelang]
exclude: cmake/.*
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.237
hooks:
- id: ruff
args: [--fix]
- 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
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
Expand All @@ -79,18 +109,18 @@ repos:
- flake8-use-pathlib
- flake8-bugbear
- flake8-comprehensions
- flake8-requirements
- repo: https://github.com/PyCQA/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort
args: [--profile, black, --multi-line, '3']
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
args: [--python-version, '3.10']
- repo: https://github.com/PyCQA/pylint
rev: v2.15.9
rev: v2.16.0b1
hooks:
- id: pylint
- repo: https://github.com/asottile/pyupgrade
Expand All @@ -110,7 +140,11 @@ repos:
rev: v0.9.0.2
hooks:
- id: shellcheck
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.21.0
hooks:
- id: check-github-workflows
- repo: https://github.com/crate-ci/typos
rev: v1.13.6
rev: typos-dict-v0.9.15
hooks:
- id: typos
10 changes: 10 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends: default

rules:
line-length: disable
document-start: disable
truthy: disable

ignore: |
venv/
workspace/
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
[mypy]
check_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
ignore_missing_imports = True
implicit_reexport = False
no_implicit_optional = True
show_column_numbers = True
show_error_codes = True
show_error_context = True
strict_equality = True
strict_optional = True
warn_no_return = True
warn_redundant_casts = True
warn_return_any = True
warn_unused_configs = True
Expand Down
44 changes: 44 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[tool.ruff]
# TODO test "ANN", "S", "DTZ", "EM", "ISC", "TRY"
select = [
"B",
"BLE",
"C",
"C4",
"C90",
"E",
"ERA",
"EXE",
"F",
"G",
"ICN",
"N",
"PGH",
"PIE",
"PL",
"PTH",
"Q",
"RET",
"RUF",
"SIM",
"T10",
"UP",
"W",
"YTT"
]
ignore = []

line-length = 120

# Assume Python 3.10.
target-version = "py310"

[tool.isort]
profile = "black"
multi_line_output = 3

[tool.docformatter]
in-place = true
recursive = true
wrap-summaries = 88
wrap-descriptions = 81
15 changes: 15 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

Tools to automatically run repeating processes.

<!-- mdformat-toc start --slug=github --no-anchors --maxlevel=6 --minlevel=2 -->

- [File Export](#file-export)
- [GitLab Project Creation](#gitlab-project-creation)
- [Working with the GitLab Projects](#working-with-the-gitlab-projects)
- [GitLab issue creation from homework slides](#gitlab-issue-creation-from-homework-slides)
- [Comment Gitlab issues and change their state](#comment-gitlab-issues-and-change-their-state)
- [Fetch the student code](#fetch-the-student-code)
- [Evaluate the student code](#evaluate-the-student-code)
- [Define Evaluation Jobs](#define-evaluation-jobs)
- [Upload new files to the student code](#upload-new-files-to-the-student-code)
- [Commit changes to the student code](#commit-changes-to-the-student-code)

<!-- mdformat-toc end -->

## File Export

Export files for student homework assignments and lecture templates.
Expand Down
4 changes: 3 additions & 1 deletion tools/sel_tools/code_evaluation/evaluate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def evaluate_code(
class CodeEvaluator:
"""Code evaluator class."""

def __init__(self, jobs: list[EvaluationJob], gitlab_project: GitlabProject):
def __init__(
self, jobs: list[EvaluationJob], gitlab_project: GitlabProject
) -> None:
# Perform a deepcopy to avoid artifact of old job runs
self.__jobs = copy.deepcopy(jobs)
self.__gitlab_project = gitlab_project
Expand Down
5 changes: 3 additions & 2 deletions tools/sel_tools/code_evaluation/jobs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def run(self, repo_path: Path) -> list[EvaluationResult]:
deps_results = [job.run(repo_path) for job in self.dependencies]
print(f"\nRunning {self.name} on {repo_path}")
job_result_score = self._run(repo_path)
return list(itertools.chain(*deps_results)) + [
EvaluationResult(self.name, self.__weight * job_result_score, self.comment)
return [
*list(itertools.chain(*deps_results)),
EvaluationResult(self.name, self.__weight * job_result_score, self.comment),
]

@property
Expand Down
6 changes: 3 additions & 3 deletions tools/sel_tools/code_evaluation/jobs/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CMakeBuildJob(EvaluationJob):

name = "CMake Build"

def __init__(self, weight: int = 1, cmake_options: str = ""):
def __init__(self, weight: int = 1, cmake_options: str = "") -> None:
super().__init__(weight)
self.__cmake_options = cmake_options

Expand Down Expand Up @@ -72,7 +72,7 @@ class CodeCoverageTestJob(EvaluationJob):
name = "Code Coverage"
dependencies = [CMakeBuildJob(cmake_options="-DCMAKE_BUILD_TYPE=Debug")]

def __init__(self, weight: int = 1, min_coverage: int = 75):
def __init__(self, weight: int = 1, min_coverage: int = 75) -> None:
super().__init__(weight)
self.__min_coverage = min_coverage

Expand Down Expand Up @@ -176,7 +176,7 @@ def visit_file(self, file: Path) -> None:
class SourceFilesCountVisitor(FileVisitor):
"""Count the number of source files."""

def __init__(self, max_source_file_count: int):
def __init__(self, max_source_file_count: int) -> None:
self.__max_source_file_count = max_source_file_count
self.__source_file_count = 0
self.__build_folder = f"/{HW_BUILD_FOLDER}/"
Expand Down
6 changes: 4 additions & 2 deletions tools/sel_tools/code_evaluation/jobs/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create(
def load_factory_from_file(module_path: Path) -> type["EvaluationJobFactory"]:
spec = importlib.util.spec_from_file_location(module_path.stem, module_path)
if spec is None:
raise Exception(f"Failed to load module from file in {module_path}")
raise ImportError(f"Failed to load module from file in {module_path}")
module = importlib.util.module_from_spec(spec)
# To enable loading files with additionally required python files lying besides them
with add_temporarily_to_pythonpath(module_path.parent):
Expand All @@ -55,4 +55,6 @@ def load_factory_from_file(module_path: Path) -> type["EvaluationJobFactory"]:
and name != "EvaluationJobFactory"
):
return attribute
raise Exception(f"No subclass of EvaluationJobFactory in {module_path}")
raise ModuleNotFoundError(
f"No subclass of EvaluationJobFactory in {module_path}"
)
4 changes: 3 additions & 1 deletion tools/sel_tools/code_evaluation/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class EvaluationResult:
class EvaluationReport:
"""Evaluation report."""

def __init__(self, gitlab_project: GitlabProject, results: list[EvaluationResult]):
def __init__(
self, gitlab_project: GitlabProject, results: list[EvaluationResult]
) -> None:
self.repo_path = gitlab_project.local_path
self.url = gitlab_project.gitlab_project.web_url
self.score = sum(result.score for result in set(results))
Expand Down
8 changes: 5 additions & 3 deletions tools/sel_tools/diff_creation/create_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_diff(
class DiffCreator:
"""Diff creator class."""

def __init__(self, repo_path: Path, exclude: str | None = None):
def __init__(self, repo_path: Path, exclude: str | None = None) -> None:
self.__path = repo_path
self.__repo = git.Repo(self.__path)
self.__exclude = exclude
Expand All @@ -44,8 +44,10 @@ def create(
)
)
diffs = (
[self.__create_overall_diff(commits_since_last_homework[-1])]
+ self.__create_diff_per_commit(commits_since_last_homework)
[
self.__create_overall_diff(commits_since_last_homework[-1]),
*self.__create_diff_per_commit(commits_since_last_homework),
]
if commits_since_last_homework
else []
)
Expand Down
2 changes: 1 addition & 1 deletion tools/sel_tools/diff_creation/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Diff:
class DiffReport:
"""Git diff model."""

def __init__(self, repo_path: Path, diffs: list[Diff]):
def __init__(self, repo_path: Path, diffs: list[Diff]) -> None:
self.repo_path = repo_path
self.diffs = diffs

Expand Down
Loading

0 comments on commit baf2031

Please sign in to comment.