From e2d5a920ece97a99dd3347f896b476240c90358c Mon Sep 17 00:00:00 2001 From: mo8it Date: Thu, 2 Nov 2023 20:04:09 +0100 Subject: [PATCH] Apply PL --- advlabdb/actions.py | 2 +- advlabdb/adminModelViews.py | 12 +++++------- advlabdb/database_import.py | 2 +- advlabdb/models.py | 11 +++++------ cli/test/generate_test_db/main.py | 4 ++-- manage.py | 2 +- pyproject.toml | 24 ++++++++++++++++++++++-- 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/advlabdb/actions.py b/advlabdb/actions.py index 8ec8a56..62bbbb0 100644 --- a/advlabdb/actions.py +++ b/advlabdb/actions.py @@ -25,7 +25,7 @@ def backup(backup_prefix): now = datetime.now().strftime("%d_%m_%Y_%H_%M_%S") dest = db_bk_dir / f"{backup_prefix}_{now}.sqlite" - status = subprocess.run(["sqlite3", db_path, f".backup {dest}"]).returncode + status = subprocess.run(["sqlite3", db_path, f".backup {dest}"], check=False).returncode if status == 0: flash(f"Created a database backup at the path {dest}", "success") else: diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 43617ac..a727a3e 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -311,9 +311,8 @@ class UserView(SecureAdminModelView): f"{model.email} registered with role(s): {', '.join(role.name for role in model.roles)}.", category="success", ) - else: - if model == current_user: - flash(f"Active semester is {model.active_semester}.", "warning") + elif model == current_user: + flash(f"Active semester is {model.active_semester}.", "warning") class SemesterView(SecureAdminModelView): @@ -418,10 +417,9 @@ class SemesterView(SecureAdminModelView): else: current_user.active_semester = model flash(f"Active semester changed to the new semester {model}!", "warning") - else: - if model.done: - next_semester = db.session.get(Semester, model.id + 1) - model.set_done(next_semester) + elif model.done: + next_semester = db.session.get(Semester, model.id + 1) + model.set_done(next_semester) def programQueryFactory(): diff --git a/advlabdb/database_import.py b/advlabdb/database_import.py index 6b27b16..7c34d10 100644 --- a/advlabdb/database_import.py +++ b/advlabdb/database_import.py @@ -25,7 +25,7 @@ from .models import ( def is_null(entry): - return entry == "NULL" or entry == "" + return entry in {"NULL", ""} def nullable(entry): diff --git a/advlabdb/models.py b/advlabdb/models.py index fd200e7..820cf71 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -457,13 +457,12 @@ class Appointment(db.Model): if assistant is not None: if assistant not in semesterExperimentAssistants: raise DatabaseException(f"{assistant} is not responsible for {semesterExperiment}!") + elif len(semesterExperimentAssistants) == 1: + assistant = semesterExperimentAssistants[0] else: - if len(semesterExperimentAssistants) == 1: - assistant = semesterExperimentAssistants[0] - else: - raise DatabaseException( - f"Experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}" - ) + raise DatabaseException( + f"Experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}" + ) return assistant diff --git a/cli/test/generate_test_db/main.py b/cli/test/generate_test_db/main.py index 8f2e781..d4049d2 100644 --- a/cli/test/generate_test_db/main.py +++ b/cli/test/generate_test_db/main.py @@ -1,6 +1,6 @@ from datetime import date from math import ceil -from random import randint, random +from random import randint import click from flask_security.utils import hash_password @@ -97,7 +97,7 @@ def _generate_test_db(): part = ss_parts[ind % len(ss_parts)] add_part_student(student, part) - if random() < 0.9: # nosec: B311 + if ind % 10 < 9: # Transfer to the next part in the second semester if part == bs_1_ss_part: add_part_student(student, bs_2_ws_part) diff --git a/manage.py b/manage.py index 3d9a6d8..10e86df 100755 --- a/manage.py +++ b/manage.py @@ -13,7 +13,7 @@ from cli.test.generate_test_db.main import _generate_test_db class Manage: @staticmethod def run(command: str, **kwargs): - return subprocess.run(command, shell=True, **kwargs) # nosec B602 + return subprocess.run(command, shell=True, check=False, **kwargs) # nosec B602 @staticmethod def box(message: str): diff --git a/pyproject.toml b/pyproject.toml index eeb53d8..f0d954d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,8 +27,28 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.ruff] -select = ["E", "W", "F", "I", "UP", "YTT", "S", "B", "C4", "ICN", "PIE", "Q", "RET", "SIM", "TID", "PTH"] -ignore = ["E5", "S3", "S6", "RET504"] +select = [ + "E", + "W", + "F", + "I", + "UP", + "YTT", + "S", + "B", + "C4", + "ICN", + "PIE", + "Q", + "RET", + "SIM", + "TID", + "PTH", + "ERA", + "PL", + "NPY", +] +ignore = ["E5", "S3", "S6", "RET504", "PLR0912", "PLR0915", "PLW2901", "PLR2004"] line-length = 120 [tool.ruff.per-file-ignores]