-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add django integration * Remove debug * Add tests * Reformat * Bugfixes, refactor * Fix tests * Fix workflows * Formatter and test setup * Chmod manage.py * Python 3.10 * Fix workflows * Remove arch --------- Co-authored-by: Tomasz Kwiatkowski <[email protected]>
- Loading branch information
1 parent
b093aa4
commit f8b49f5
Showing
33 changed files
with
543 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: migrations | ||
run-name: Check if all migrations are created | ||
on: | ||
push: | ||
branches: 'main' | ||
pull_request: | ||
jobs: | ||
pytest: | ||
runs-on: ubuntu-latest | ||
name: migrations-ubuntu | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.12 | ||
- name: Install dependencies | ||
run: | | ||
pip3 install .[django] | ||
- name: Check migrations | ||
run: | | ||
python3 tests/test_django/manage.py makemigrations --dry-run --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ build | |
.vscode | ||
.idea | ||
__pycache__ | ||
tests/test_django/db.sqlite3 | ||
|
||
# pytest-cov | ||
.coverage* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ include_trailing_comma = true | |
|
||
[tool.black] | ||
line_length = 120 | ||
exclude = "migrations/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = test_django.settings | ||
pythonpath = ./tests/test_django | ||
markers = | ||
no_django: marks tests that should be run without Django |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sio3pack.django.sinolpack.models import SinolpackPackage | ||
from sio3pack.packages.exceptions import PackageAlreadyExists | ||
from sio3pack.packages.package.django.handler import DjangoHandler | ||
|
||
|
||
class SinolpackDjangoHandler(DjangoHandler): | ||
def save_to_db(self): | ||
""" | ||
Save the package to the database. | ||
""" | ||
if SinolpackPackage.objects.filter(problem_id=self.problem_id).exists(): | ||
raise PackageAlreadyExists(self.problem_id) | ||
|
||
SinolpackPackage.objects.create( | ||
problem_id=self.problem_id, | ||
short_name=self.package.short_name, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 5.1.3 on 2024-12-01 17:22 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="SinolpackPackage", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("problem_id", models.IntegerField()), | ||
("short_name", models.CharField(max_length=100)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.db import models | ||
|
||
|
||
class SinolpackPackage(models.Model): | ||
""" | ||
A package for the sinolpack package type. | ||
""" | ||
|
||
problem_id = models.IntegerField() | ||
short_name = models.CharField(max_length=100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
class UnknownPackageType(Exception): | ||
def __init__(self, path: str) -> None: | ||
self.path = path | ||
super().__init__(f"Unknown package type for file {path}.") | ||
def __init__(self, arg: str | int) -> None: | ||
if isinstance(arg, str): | ||
self.path = arg | ||
super().__init__(f"Unknown package type for file {arg}.") | ||
else: | ||
self.problem_id = arg | ||
super().__init__(f"Unknown package type for problem with id={arg}.") | ||
|
||
|
||
class ImproperlyConfigured(Exception): | ||
def __init__(self, message: str) -> None: | ||
super().__init__(message) | ||
|
||
|
||
class PackageAlreadyExists(Exception): | ||
def __init__(self, problem_id: int) -> None: | ||
self.problem_id = problem_id | ||
super().__init__(f"A package already exists for problem with id={problem_id}.") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import Type | ||
|
||
from sio3pack.packages.exceptions import ImproperlyConfigured | ||
|
||
|
||
class DjangoHandler: | ||
def __init__(self, package: Type["Package"], problem_id: int): | ||
self.package = package | ||
self.problem_id = problem_id | ||
|
||
|
||
class NoDjangoHandler: | ||
def __call__(self, *args, **kwargs): | ||
raise ImproperlyConfigured("sio3pack is not installed with Django support.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.