diff --git a/.github/workflows/formatter.yml b/.github/workflows/formatter.yml index e930f84..175a59c 100644 --- a/.github/workflows/formatter.yml +++ b/.github/workflows/formatter.yml @@ -19,5 +19,5 @@ jobs: pip install isort black - name: Run isort and black run: | - isort -c . - black --check . + isort -c src tests + black --check src tests diff --git a/pyproject.toml b/pyproject.toml index 8dcf968..d18517b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,14 @@ build-backend = "setuptools.build_meta" line_length = 120 multi_line_output = 1 include_trailing_comma = true +skip = ["migrations", ".venv"] [tool.black] line_length = 120 -exclude = "migrations/" +exclude = ''' +/^( + migrations + | sio3pack$ + | \.venv$ +)/ +''' diff --git a/src/sio3pack/django/sinolpack/handler.py b/src/sio3pack/django/sinolpack/handler.py index e0f73a4..eebf186 100644 --- a/src/sio3pack/django/sinolpack/handler.py +++ b/src/sio3pack/django/sinolpack/handler.py @@ -5,8 +5,13 @@ from django.db import transaction from sio3pack import LocalFile -from sio3pack.django.sinolpack.models import SinolpackPackage, SinolpackConfig, SinolpackNameTranslation, \ - SinolpackModelSolution, SinolpackAdditionalFile, SinolpackProblemStatement, SinolpackAttachment +from sio3pack.django.sinolpack.models import (SinolpackAdditionalFile, + SinolpackAttachment, + SinolpackConfig, + SinolpackModelSolution, + SinolpackNameTranslation, + SinolpackPackage, + SinolpackProblemStatement,) from sio3pack.packages.exceptions import PackageAlreadyExists from sio3pack.packages.package.django.handler import DjangoHandler diff --git a/src/sio3pack/django/sinolpack/models.py b/src/sio3pack/django/sinolpack/models.py index a4db5b2..fa8a591 100644 --- a/src/sio3pack/django/sinolpack/models.py +++ b/src/sio3pack/django/sinolpack/models.py @@ -1,9 +1,10 @@ import os + import yaml from django.conf import settings from django.db import models -from django.utils.translation import gettext_lazy as _ from django.utils.text import get_valid_filename +from django.utils.translation import gettext_lazy as _ from sio3pack.packages.sinolpack.enums import ModelSolutionKind @@ -18,9 +19,10 @@ def make_problem_filename(instance, filename): try: instance = instance.package except AttributeError: - raise ValueError(f'make_problem_filename used on an object {type(instance)} which does not have ' - f'a package attribute') - return f'sio3pack/sinolpack/{instance.problem_id}/{get_valid_filename(filename)}' + raise ValueError( + f"make_problem_filename used on an object {type(instance)} which does not have " f"a package attribute" + ) + return f"sio3pack/sinolpack/{instance.problem_id}/{get_valid_filename(filename)}" class SinolpackPackage(models.Model): @@ -88,7 +90,7 @@ def __str__(self): @property def short_name(self): - return self.name.rsplit('.', 1)[0] + return self.name.rsplit(".", 1)[0] @property def kind(self): diff --git a/src/sio3pack/files/local_file.py b/src/sio3pack/files/local_file.py index 3d09c85..59cd75c 100644 --- a/src/sio3pack/files/local_file.py +++ b/src/sio3pack/files/local_file.py @@ -18,7 +18,7 @@ def get_file_matching_extension(cls, dir: str, filename: str, extensions: list[s :return: The file object. """ for ext in extensions: - path = os.path.join(dir, filename + '.' + ext) + path = os.path.join(dir, filename + "." + ext) if os.path.exists(path): return cls(path) raise FileNotFoundError diff --git a/src/sio3pack/packages/sinolpack/enums.py b/src/sio3pack/packages/sinolpack/enums.py index afeb93a..5cd91cb 100644 --- a/src/sio3pack/packages/sinolpack/enums.py +++ b/src/sio3pack/packages/sinolpack/enums.py @@ -2,9 +2,9 @@ class ModelSolutionKind(Enum): - NORMAL = '' - SLOW = 's' - INCORRECT = 'b' + NORMAL = "" + SLOW = "s" + INCORRECT = "b" @classmethod def from_regex(cls, group): diff --git a/src/sio3pack/packages/sinolpack/model.py b/src/sio3pack/packages/sinolpack/model.py index eae6fce..b2f736c 100644 --- a/src/sio3pack/packages/sinolpack/model.py +++ b/src/sio3pack/packages/sinolpack/model.py @@ -313,9 +313,7 @@ def _process_prog_files(self): for file in ("ingen", "inwer", "soc", "chk"): try: self.additional_files.append( - LocalFile.get_file_matching_extension( - self.get_prog_dir(), self.short_name + file, extensions - ) + LocalFile.get_file_matching_extension(self.get_prog_dir(), self.short_name + file, extensions) ) self.special_files[file] = True except FileNotFoundError: diff --git a/tests/test_django/test_sio3pack/test_sinolpack.py b/tests/test_django/test_sio3pack/test_sinolpack.py index e1208b8..5811ec1 100644 --- a/tests/test_django/test_sio3pack/test_sinolpack.py +++ b/tests/test_django/test_sio3pack/test_sinolpack.py @@ -1,8 +1,10 @@ import pytest import sio3pack -from sio3pack.django.sinolpack.models import SinolpackPackage, SinolpackConfig, SinolpackModelSolution, \ - SinolpackAdditionalFile +from sio3pack.django.sinolpack.models import (SinolpackAdditionalFile, + SinolpackConfig, + SinolpackModelSolution, + SinolpackPackage,) from sio3pack.packages import Sinolpack from tests.fixtures import Compression, PackageInfo, get_archived_package from tests.utils import assert_contents_equal @@ -59,7 +61,7 @@ def test_model_solutions(get_archived_package): ms = db_model_solutions.get(order_key=order) assert ms.name == solution.filename assert ms.kind == kind - assert_contents_equal(ms.source_file.read().decode('utf-8'), solution.read()) + assert_contents_equal(ms.source_file.read().decode("utf-8"), solution.read()) @pytest.mark.django_db @@ -74,5 +76,5 @@ def test_additional_files(get_archived_package): for file in additional_files: af = db_additional_files.get(name=file.filename) - assert_contents_equal(af.file.read().decode('utf-8'), file.read()) + assert_contents_equal(af.file.read().decode("utf-8"), file.read()) assert af.name == file.filename diff --git a/tests/utils.py b/tests/utils.py index 394e43e..fc057ba 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,8 +1,8 @@ def assert_contents_equal(content1, content2): if isinstance(content1, bytes): - content1 = content1.decode('utf-8') + content1 = content1.decode("utf-8") if isinstance(content2, bytes): - content2 = content2.decode('utf-8') - content1 = content1.replace('\r\n', '\n') - content2 = content2.replace('\r\n', '\n') + content2 = content2.decode("utf-8") + content1 = content1.replace("\r\n", "\n") + content2 = content2.replace("\r\n", "\n") assert content1 == content2