Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Dec 9, 2024
1 parent bda7bc5 commit 15241ed
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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$
)/
'''
9 changes: 7 additions & 2 deletions src/sio3pack/django/sinolpack/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 7 additions & 5 deletions src/sio3pack/django/sinolpack/models.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/sio3pack/files/local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/sio3pack/packages/sinolpack/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


class ModelSolutionKind(Enum):
NORMAL = ''
SLOW = 's'
INCORRECT = 'b'
NORMAL = ""
SLOW = "s"
INCORRECT = "b"

@classmethod
def from_regex(cls, group):
Expand Down
4 changes: 1 addition & 3 deletions src/sio3pack/packages/sinolpack/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions tests/test_django/test_sio3pack/test_sinolpack.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15241ed

Please sign in to comment.