Skip to content

Commit

Permalink
update tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
hofbi committed Feb 7, 2025
1 parent 9af6f7d commit 8c46abd
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 58 deletions.
44 changes: 27 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ repos:
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
rev: v1.6.1
hooks:
- id: check-pre-commit-ci-config
- repo: https://github.com/pre-commit/sync-pre-commit-deps
rev: v0.0.3
hooks:
- id: sync-pre-commit-deps
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-illegal-windows-names
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-yaml
exclude: |
(?x)^(
Expand All @@ -30,6 +42,7 @@ repos:
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: name-tests-test
args:
- --pytest-test-first
Expand All @@ -40,18 +53,21 @@ repos:
)
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/google/keep-sorted
rev: v0.6.0
hooks:
- id: keep-sorted
- repo: https://github.com/luminartech/dev-tools
rev: 0.7.0
rev: 0.8.0
hooks:
- id: check-snake-case
- id: check-cpp-and-cu-unit-test-naming-pattern
- id: check-no-dashes
exclude: ^slides/
- id: check-number-of-lines-count
- id: check-shellscript-set-options
- id: check-non-existing-and-duplicate-excludes
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.19
rev: 0.7.22
hooks:
- id: mdformat
exclude: ^slides/
Expand All @@ -68,7 +84,7 @@ repos:
args: ["--quiet", "--config", ".md-link-config.json"]
exclude: ^slides/homework
- repo: https://github.com/google/yamlfmt
rev: v0.14.0
rev: v0.15.0
hooks:
- id: yamlfmt
exclude: |
Expand All @@ -92,14 +108,8 @@ repos:
rev: v0.24.2
hooks:
- id: toml-sort-fix
- repo: https://github.com/PyCQA/docformatter
# Use tag > v1.7.5 if available
rev: eb1df347edd128b30cd3368dddc3aa65edcfac38
hooks:
- id: docformatter
additional_dependencies: [tomli]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.4
rev: v19.1.7
hooks:
- id: clang-format
- repo: https://github.com/cpplint/cpplint
Expand All @@ -115,7 +125,7 @@ repos:
additional_dependencies: [cmakelang]
exclude: cmake/.*
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
rev: v0.9.4
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -128,16 +138,16 @@ repos:
- 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.13.0
rev: v1.14.1
hooks:
- id: mypy
args: [--python-version, '3.12']
- repo: https://github.com/PyCQA/pylint
rev: v3.3.2
rev: v3.3.4
hooks:
- id: pylint
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py312-plus, --keep-runtime-typing]
Expand All @@ -154,10 +164,10 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.30.0
rev: 0.31.1
hooks:
- id: check-github-workflows
- repo: https://github.com/crate-ci/typos
rev: typos-dict-v0.11.37
rev: typos-dict-v0.12.4
hooks:
- id: typos
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sudo apt-get install -y \
cmake \
llvm \
lcov \
gdb \
zip

curl -LsSf https://astral.sh/uv/install.sh | sh
45 changes: 37 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,53 @@ disable = [
fix = true
target-version = "py312"
line-length = 120
unsafe-fixes = true

[tool.ruff.format]
docstring-code-format = true
docstring-code-line-length = 120

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"A",
"ANN",
"ARG",
"A001",
"A002",
"A005",
"ANN001", # Type annotation
"ANN002",
"ANN003",
"ANN201", # Partially autofixable None return useful for mypy
"ANN202", # Partially autofixable, useful for mypy
"ANN204", # Partially autofixable, useful for mypy
"ANN205",
"ANN206",
"ANN401",
"ARG002",
"ARG004",
"COM", # Done via formatter
"D",
"D100",
"D101",
"D102",
"D103",
"D104",
"D105",
"D106",
"D107",
"D203", # Incompatible with D211
"D213", # Incompatible with D212
"D401",
"D417", # We don't want every argument to be documented
"DTZ001", # TODO: Enable
"E501", # Done via formatter
"FBT",
"FIX",
"INP",
"FBT001",
"FBT002",
"FBT003",
"FIX002",
"INP001",
"ISC001", # Done via formatter
"PERF203",
"PT", # We don't use pytest here
"S",
"T",
"T", # Keep print statements
"TD"
]
2 changes: 1 addition & 1 deletion tools/create_gitlab_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def parse_arguments(arguments: list[str]) -> Namespace:


def main() -> None:
"""main."""
"""Main."""
arguments = parse_arguments(sys.argv)
check_code_for_solutions_code(arguments.source_path, arguments.publish_solutions)
student_repos, group_name = create_repos(
Expand Down
2 changes: 1 addition & 1 deletion tools/export_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_arguments(arguments: list[str]) -> Namespace:


def main() -> None:
"""main."""
"""Main."""
arguments = parse_arguments(sys.argv)

copy_item(arguments.source_path, arguments.output_dir)
Expand Down
2 changes: 1 addition & 1 deletion tools/gitlab_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def parse_arguments(arguments: list[str]) -> Namespace:


def main() -> None:
"""main."""
"""Main."""
args = parse_arguments(sys.argv)
args.func(args)

Expand Down
5 changes: 5 additions & 0 deletions tools/sel_tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
GITLAB_SERVER_URL = "https://gitlab.lrz.de/"
RUNNER_ID = 3666
GIT_MAIN_BRANCH = "master"


def get_branch_from_student_config(student_config: dict) -> str:
"""Get branch from student config."""
return str(student_config.get("branch", GIT_MAIN_BRANCH))
6 changes: 2 additions & 4 deletions tools/sel_tools/file_export/file_content_remover.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Remove block(s) within delimiters defined in config file from file or multiline
string."""
"""Remove block(s) within delimiters defined in config file from file or multilinestring."""

import re
from pathlib import Path
Expand All @@ -23,8 +22,7 @@ def visit_file(self, file: Path) -> None:


def remove_lines_within_limiters_from_string(multiline_string: str) -> str:
"""Remove block(s) within delimiters defined in config file from multiline
string."""
"""Remove block(s) within delimiters defined in config file from multiline string."""
minimal_length_between_markers_pattern = r"\n[\S ]*" + EXPORT_BEGIN + r".*?[\S ]*" + EXPORT_END
return re.sub(minimal_length_between_markers_pattern, "", multiline_string, flags=re.DOTALL)

Expand Down
2 changes: 1 addition & 1 deletion tools/sel_tools/gitlab_api/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pathlib import Path

from gitlab.v4.objects.projects import Project
from gitlab.v4.objects import Project

from sel_tools.config import REPO_DIR

Expand Down
2 changes: 1 addition & 1 deletion tools/sel_tools/gitlab_api/comment_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path

import gitlab
from gitlab.v4.objects.projects import Project
from gitlab.v4.objects import Project
from tqdm import tqdm

from sel_tools.config import GITLAB_SERVER_URL
Expand Down
19 changes: 12 additions & 7 deletions tools/sel_tools/gitlab_api/create_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import git
import gitlab
from gitlab.v4.objects.projects import Project
from gitlab.v4.objects import Project
from tqdm import tqdm

from sel_tools.config import GIT_MAIN_BRANCH, GITLAB_SERVER_URL
from sel_tools.config import GITLAB_SERVER_URL, get_branch_from_student_config
from sel_tools.utils.files import FileTree, FileVisitor


Expand All @@ -31,16 +31,21 @@ def upload_files(source_folder: Path, student_repos_file: Path, gitlab_token: st
student_repos = json.loads(student_repos_file.read_text())
for student_repo in tqdm(student_repos, desc="Uploading files"):
student_homework_project = gitlab_instance.projects.get(student_repo["id"])
create_commit(source_folder, f"Add {source_folder.name}", student_homework_project)
create_commit(
source_folder,
f"Add {source_folder.name}",
get_branch_from_student_config(student_repo),
student_homework_project,
)


def create_commit(source_folder: Path, message: str, gitlab_project: Project) -> None:
def create_commit(source_folder: Path, message: str, branch: str, gitlab_project: Project) -> None:
"""Create commit in gitlab project from source folder with message."""
gitlab_project.commits.create(create_gitlab_commit_data_with_all_files_from(source_folder, message))
gitlab_project.commits.create(create_gitlab_commit_data_with_all_files_from(source_folder, message, branch))


@lru_cache
def create_gitlab_commit_data_with_all_files_from(folder: Path, message: str) -> dict:
def create_gitlab_commit_data_with_all_files_from(folder: Path, message: str, branch: str) -> dict:
"""Create gitlab commit with all files from folder.
Folder is assumed to be root of the repo committing to
Expand All @@ -51,7 +56,7 @@ def create_gitlab_commit_data_with_all_files_from(folder: Path, message: str) ->

return (
{
"branch": GIT_MAIN_BRANCH,
"branch": branch,
"commit_message": message,
"actions": initial_file_commit_actions_visitor.actions,
}
Expand Down
2 changes: 1 addition & 1 deletion tools/sel_tools/gitlab_api/create_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path

import gitlab
from gitlab.v4.objects.projects import Project
from gitlab.v4.objects import Project
from tqdm import tqdm

from sel_tools.config import GITLAB_SERVER_URL
Expand Down
12 changes: 6 additions & 6 deletions tools/sel_tools/gitlab_api/create_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path

import gitlab
from gitlab.v4.objects.projects import Project
from gitlab.v4.objects import Project, ProjectProtectedBranch
from tqdm import tqdm

from sel_tools.config import AVATAR_PATH, GIT_MAIN_BRANCH, GITLAB_SERVER_URL, RUNNER_ID
Expand All @@ -25,9 +25,9 @@ def create_repos(
for repo_number in tqdm(range(1, number_of_repos + 1), desc="Creating Student Repos"):
project = gitlab_instance.projects.create(get_repo_settings(group_id, repo_base_name, repo_number))
configure_project(project)
configure_main_branch(project)
create_commit(source_folder, "Initial commit", project)
student_repos.append({"name": project.name, "id": project.id, "branch": project.default_branch})
main_branch = configure_main_branch(project)
create_commit(source_folder, "Initial commit", main_branch.name, project)
student_repos.append({"name": project.name, "id": project.id, "branch": main_branch.name})

group = gitlab_instance.groups.get(group_id)
return student_repos, group.path
Expand All @@ -40,9 +40,9 @@ def configure_project(gitlab_project: Project) -> None:
gitlab_project.save()


def configure_main_branch(gitlab_project: Project) -> None:
def configure_main_branch(gitlab_project: Project) -> ProjectProtectedBranch:
"""Configure main branch."""
gitlab_project.protectedbranches.create(
return gitlab_project.protectedbranches.create(
{
"name": GIT_MAIN_BRANCH,
"merge_access_level": gitlab.const.DEVELOPER_ACCESS,
Expand Down
6 changes: 3 additions & 3 deletions tools/sel_tools/gitlab_api/fetch_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from pathlib import Path

import gitlab
from gitlab.v4.objects.projects import Project
from gitlab.v4.objects import Project
from tqdm import tqdm

from sel_tools.config import GIT_MAIN_BRANCH, GITLAB_SERVER_URL
from sel_tools.config import GITLAB_SERVER_URL, get_branch_from_student_config
from sel_tools.utils.repo import GitlabProject, GitRepo


Expand All @@ -20,7 +20,7 @@ def fetch_repos(workspace: Path, student_repos_file: Path, gitlab_token: str) ->
gitlab_instance = gitlab.Gitlab(GITLAB_SERVER_URL, private_token=gitlab_token)
return [
fetch_repo(
GitRepo(workspace / student_repo["name"], student_repo.get("branch", GIT_MAIN_BRANCH)),
GitRepo(workspace / student_repo["name"], get_branch_from_student_config(student_repo)),
gitlab_instance.projects.get(student_repo["id"]),
)
for student_repo in tqdm(student_repos, desc="Fetching Repos")
Expand Down
2 changes: 1 addition & 1 deletion tools/sel_tools/utils/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path

import git
from gitlab.v4.objects.projects import Project
from gitlab.v4.objects import Project

from sel_tools.config import GIT_MAIN_BRANCH

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sel_tools.code_evaluation.jobs.common import EvaluationJob
from sel_tools.code_evaluation.jobs.factory import EvaluationJobFactory
from sel_tools.utils.repo import GitlabProject

from tests.helper import SimplePassingJob


Expand Down
Loading

0 comments on commit 8c46abd

Please sign in to comment.