Skip to content

Commit

Permalink
updates CI ci:debug
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Jun 13, 2024
1 parent 3b4e45f commit c689361
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 376 deletions.
5 changes: 3 additions & 2 deletions src/hope_dedup_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# from hope_dedup_engine.config.celery import app as celery_app
from hope_dedup_engine.config.celery import app as celery_app


VERSION = __version__ = "0.1.0"

# __all__ = ("celery_app",)
__all__ = ("celery_app",)
7 changes: 1 addition & 6 deletions src/hope_dedup_engine/apps/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from django.contrib import admin

from hope_dedup_engine.apps.api.models import (
DeduplicationSet,
Duplicate,
HDEToken,
Image,
)
from hope_dedup_engine.apps.api.models import DeduplicationSet, Duplicate, HDEToken, Image

admin.site.register(DeduplicationSet)
admin.site.register(Duplicate)
Expand Down
4 changes: 1 addition & 3 deletions src/hope_dedup_engine/apps/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def has_permission(self, request: Request, view: View) -> bool:

class UserAndDeduplicationSetAreOfTheSameSystem(BasePermission):
def has_permission(self, request: Request, view: View) -> bool:
if deduplication_set_pk := view.kwargs.get(
"deduplication_set_pk"
) or view.kwargs.get("pk"):
if deduplication_set_pk := view.kwargs.get("deduplication_set_pk") or view.kwargs.get("pk"):
return DeduplicationSet.objects.filter(
external_system=request.user.external_system, pk=deduplication_set_pk
).exists()
Expand Down
6 changes: 1 addition & 5 deletions src/hope_dedup_engine/apps/api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
from hope_dedup_engine.apps.api.models.auth import HDEToken # noqa: F401
from hope_dedup_engine.apps.api.models.deduplication import ( # noqa: F401
DeduplicationSet,
Duplicate,
Image,
)
from hope_dedup_engine.apps.api.models.deduplication import DeduplicationSet, Duplicate, Image # noqa: F401
4 changes: 1 addition & 3 deletions src/hope_dedup_engine/apps/api/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@


class HDEToken(Token):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, related_name="auth_tokens", on_delete=models.CASCADE
)
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="auth_tokens", on_delete=models.CASCADE)
33 changes: 6 additions & 27 deletions src/hope_dedup_engine/apps/api/models/deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
class DeduplicationSet(models.Model):
class State(models.IntegerChoices):
CLEAN = 0, "Clean" # Deduplication set is created or already processed
DIRTY = (
1,
"Dirty",
) # Images are added to deduplication set, but not yet processed
DIRTY = 1, "Dirty" # Images are added to deduplication set, but not yet processed
PROCESSING = 2, "Processing" # Images are being processed
ERROR = 3, "Error" # Error occurred

Expand All @@ -30,19 +27,11 @@ class State(models.IntegerChoices):
external_system = models.ForeignKey(ExternalSystem, on_delete=models.CASCADE)
error = models.CharField(max_length=255, null=True, blank=True)
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="+",
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True, related_name="+"
)
created_at = models.DateTimeField(auto_now_add=True)
updated_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="+",
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True, related_name="+"
)
updated_at = models.DateTimeField(auto_now=True)
notification_url = models.CharField(max_length=255, null=True, blank=True)
Expand All @@ -54,11 +43,7 @@ class Image(models.Model):
reference_pk = models.CharField(max_length=REFERENCE_PK_LENGTH)
filename = models.CharField(max_length=255)
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="+",
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True, related_name="+"
)
created_at = models.DateTimeField(auto_now_add=True)

Expand All @@ -78,15 +63,9 @@ class IgnoredKeyPair(models.Model):
second_reference_pk = models.CharField(max_length=REFERENCE_PK_LENGTH)

class Meta:
unique_together = (
"deduplication_set",
"first_reference_pk",
"second_reference_pk",
)
unique_together = "deduplication_set", "first_reference_pk", "second_reference_pk"

@override
def save(self, **kwargs: Any) -> None:
self.first_reference_pk, self.second_reference_pk = sorted(
(self.first_reference_pk, self.second_reference_pk)
)
self.first_reference_pk, self.second_reference_pk = sorted((self.first_reference_pk, self.second_reference_pk))
super().save(**kwargs)
15 changes: 2 additions & 13 deletions src/hope_dedup_engine/apps/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from rest_framework import serializers

from hope_dedup_engine.apps.api.models import DeduplicationSet
from hope_dedup_engine.apps.api.models.deduplication import (
Duplicate,
IgnoredKeyPair,
Image,
)
from hope_dedup_engine.apps.api.models.deduplication import Duplicate, IgnoredKeyPair, Image


class DeduplicationSetSerializer(serializers.ModelSerializer):
Expand All @@ -14,14 +10,7 @@ class DeduplicationSetSerializer(serializers.ModelSerializer):
class Meta:
model = DeduplicationSet
exclude = ("deleted",)
read_only_fields = (
"external_system",
"created_at",
"created_by",
"deleted",
"updated_at",
"updated_by",
)
read_only_fields = "external_system", "created_at", "created_by", "deleted", "updated_at", "updated_by"


class ImageSerializer(serializers.ModelSerializer):
Expand Down
25 changes: 6 additions & 19 deletions src/hope_dedup_engine/apps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,12 @@
)

router = routers.SimpleRouter()
router.register(
DEDUPLICATION_SET_LIST, DeduplicationSetViewSet, basename=DEDUPLICATION_SET_LIST
)
router.register(DEDUPLICATION_SET_LIST, DeduplicationSetViewSet, basename=DEDUPLICATION_SET_LIST)

deduplication_sets_router = nested_routers.NestedSimpleRouter(
router, DEDUPLICATION_SET_LIST, lookup=DEDUPLICATION_SET
)
deduplication_sets_router = nested_routers.NestedSimpleRouter(router, DEDUPLICATION_SET_LIST, lookup=DEDUPLICATION_SET)
deduplication_sets_router.register(IMAGE_LIST, ImageViewSet, basename=IMAGE_LIST)
deduplication_sets_router.register(
BULK_IMAGE_LIST, BulkImageViewSet, basename=BULK_IMAGE_LIST
)
deduplication_sets_router.register(
DUPLICATE_LIST, DuplicateViewSet, basename=DUPLICATE_LIST
)
deduplication_sets_router.register(
IGNORED_KEYS_LIST, IgnoredKeyPairViewSet, basename=IGNORED_KEYS_LIST
)
deduplication_sets_router.register(BULK_IMAGE_LIST, BulkImageViewSet, basename=BULK_IMAGE_LIST)
deduplication_sets_router.register(DUPLICATE_LIST, DuplicateViewSet, basename=DUPLICATE_LIST)
deduplication_sets_router.register(IGNORED_KEYS_LIST, IgnoredKeyPairViewSet, basename=IGNORED_KEYS_LIST)

urlpatterns = [
path("", include(router.urls)),
path("", include(deduplication_sets_router.urls)),
]
urlpatterns = [path("", include(router.urls)), path("", include(deduplication_sets_router.urls))]
80 changes: 16 additions & 64 deletions src/hope_dedup_engine/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@
HDETokenAuthentication,
UserAndDeduplicationSetAreOfTheSameSystem,
)
from hope_dedup_engine.apps.api.const import (
DEDUPLICATION_SET_FILTER,
DEDUPLICATION_SET_PARAM,
)
from hope_dedup_engine.apps.api.const import DEDUPLICATION_SET_FILTER, DEDUPLICATION_SET_PARAM
from hope_dedup_engine.apps.api.models import DeduplicationSet
from hope_dedup_engine.apps.api.models.deduplication import (
Duplicate,
IgnoredKeyPair,
Image,
)
from hope_dedup_engine.apps.api.models.deduplication import Duplicate, IgnoredKeyPair, Image
from hope_dedup_engine.apps.api.serializers import (
DeduplicationSetSerializer,
DuplicateSerializer,
Expand All @@ -43,29 +36,17 @@


class DeduplicationSetViewSet(
mixins.ListModelMixin,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
mixins.ListModelMixin, mixins.CreateModelMixin, mixins.DestroyModelMixin, viewsets.GenericViewSet
):
authentication_classes = (HDETokenAuthentication,)
permission_classes = (
IsAuthenticated,
AssignedToExternalSystem,
UserAndDeduplicationSetAreOfTheSameSystem,
)
permission_classes = IsAuthenticated, AssignedToExternalSystem, UserAndDeduplicationSetAreOfTheSameSystem
serializer_class = DeduplicationSetSerializer

def get_queryset(self) -> QuerySet:
return DeduplicationSet.objects.filter(
external_system=self.request.user.external_system, deleted=False
)
return DeduplicationSet.objects.filter(external_system=self.request.user.external_system, deleted=False)

def perform_create(self, serializer: Serializer) -> None:
serializer.save(
created_by=self.request.user,
external_system=self.request.user.external_system,
)
serializer.save(created_by=self.request.user, external_system=self.request.user.external_system)

def perform_destroy(self, instance: DeduplicationSet) -> None:
instance.updated_by = self.request.user
Expand All @@ -89,9 +70,7 @@ def process(self, request: Request, pk: UUID | None = None) -> Response:
self._start_processing(deduplication_set)
return Response({MESSAGE: STARTED})
case DeduplicationSet.State.PROCESSING:
return Response(
{MESSAGE: ALREADY_PROCESSING}, status=status.HTTP_400_BAD_REQUEST
)
return Response({MESSAGE: ALREADY_PROCESSING}, status=status.HTTP_400_BAD_REQUEST)


class ImageViewSet(
Expand All @@ -102,11 +81,7 @@ class ImageViewSet(
viewsets.GenericViewSet,
):
authentication_classes = (HDETokenAuthentication,)
permission_classes = (
IsAuthenticated,
AssignedToExternalSystem,
UserAndDeduplicationSetAreOfTheSameSystem,
)
permission_classes = IsAuthenticated, AssignedToExternalSystem, UserAndDeduplicationSetAreOfTheSameSystem
serializer_class = ImageSerializer
queryset = Image.objects.all()
parent_lookup_kwargs = {
Expand Down Expand Up @@ -138,18 +113,14 @@ def __setitem__(self, key: str, value: Any) -> None:


class WrapRequestDataMixin:
def initialize_request(
self, request: Request, *args: Any, **kwargs: Any
) -> Request:
def initialize_request(self, request: Request, *args: Any, **kwargs: Any) -> Request:
request = super().initialize_request(request, *args, **kwargs)
request._full_data = ListDataWrapper(request.data)
return request


class UnwrapRequestDataMixin:
def initialize_request(
self, request: Request, *args: Any, **kwargs: Any
) -> Request:
def initialize_request(self, request: Request, *args: Any, **kwargs: Any) -> Request:
request = super().initialize_request(request, *args, **kwargs)
request._full_data = request._full_data.data
return request
Expand All @@ -165,11 +136,7 @@ class BulkImageViewSet(
viewsets.GenericViewSet,
):
authentication_classes = (HDETokenAuthentication,)
permission_classes = (
IsAuthenticated,
AssignedToExternalSystem,
UserAndDeduplicationSetAreOfTheSameSystem,
)
permission_classes = IsAuthenticated, AssignedToExternalSystem, UserAndDeduplicationSetAreOfTheSameSystem
serializer_class = ImageSerializer
queryset = Image.objects.all()
parent_lookup_kwargs = {
Expand All @@ -181,9 +148,7 @@ def get_serializer(self, *args: Any, **kwargs: Any) -> Serializer:

def perform_create(self, serializer: Serializer) -> None:
super().perform_create(serializer)
if deduplication_set := (
serializer.instance[0].deduplication_set if serializer.instance else None
):
if deduplication_set := serializer.instance[0].deduplication_set if serializer.instance else None:
deduplication_set.updated_by = self.request.user
deduplication_set.save()

Expand All @@ -196,15 +161,9 @@ def clear(self, request: Request, deduplication_set_pk: str) -> Response:
return Response(status=status.HTTP_204_NO_CONTENT)


class DuplicateViewSet(
nested_viewsets.NestedViewSetMixin, mixins.ListModelMixin, viewsets.GenericViewSet
):
class DuplicateViewSet(nested_viewsets.NestedViewSetMixin, mixins.ListModelMixin, viewsets.GenericViewSet):
authentication_classes = (HDETokenAuthentication,)
permission_classes = (
IsAuthenticated,
AssignedToExternalSystem,
UserAndDeduplicationSetAreOfTheSameSystem,
)
permission_classes = IsAuthenticated, AssignedToExternalSystem, UserAndDeduplicationSetAreOfTheSameSystem
serializer_class = DuplicateSerializer
queryset = Duplicate.objects.all()
parent_lookup_kwargs = {
Expand All @@ -213,17 +172,10 @@ class DuplicateViewSet(


class IgnoredKeyPairViewSet(
nested_viewsets.NestedViewSetMixin,
mixins.ListModelMixin,
mixins.CreateModelMixin,
viewsets.GenericViewSet,
nested_viewsets.NestedViewSetMixin, mixins.ListModelMixin, mixins.CreateModelMixin, viewsets.GenericViewSet
):
authentication_classes = (HDETokenAuthentication,)
permission_classes = (
IsAuthenticated,
AssignedToExternalSystem,
UserAndDeduplicationSetAreOfTheSameSystem,
)
permission_classes = IsAuthenticated, AssignedToExternalSystem, UserAndDeduplicationSetAreOfTheSameSystem
serializer_class = IgnoredKeyPairSerializer
queryset = IgnoredKeyPair.objects.all()
parent_lookup_kwargs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def add_arguments(self, parser):
parser.add_argument("name")

def handle(self, *args, **options):
system, created = ExternalSystem.objects.get_or_create(
name=(name := options["name"])
)
system, created = ExternalSystem.objects.get_or_create(name=(name := options["name"]))
if created:
self.stdout.write(self.style.SUCCESS(f'"{name}" system created.'))
else:
Expand Down
24 changes: 5 additions & 19 deletions src/hope_dedup_engine/apps/core/management/commands/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,14 @@ def add_arguments(self, parser: "CommandParser") -> None:
default="export {key}={value}",
help="Check env for variable availability (default: 'export {key}=\"{value}\"')",
)
parser.add_argument(
"--develop", action="store_true", help="Display development values"
)
parser.add_argument(
"--config", action="store_true", help="Only list changed values"
)
parser.add_argument("--develop", action="store_true", help="Display development values")
parser.add_argument("--config", action="store_true", help="Only list changed values")
parser.add_argument("--diff", action="store_true", help="Mark changed values")
parser.add_argument(
"--check",
action="store_true",
dest="check",
default=False,
help="Check env for variable availability",
"--check", action="store_true", dest="check", default=False, help="Check env for variable availability"
)
parser.add_argument(
"--ignore-errors",
action="store_true",
dest="ignore_errors",
default=False,
help="Do not fail",
"--ignore-errors", action="store_true", dest="ignore_errors", default=False, help="Do not fail"
)

def handle(self, *args: "Any", **options: "Any") -> None:
Expand All @@ -74,9 +62,7 @@ def handle(self, *args: "Any", **options: "Any") -> None:
else:
value: Any = env.get_value(k)

line: str = pattern.format(
key=k, value=clean(value), help=help, default=default
)
line: str = pattern.format(key=k, value=clean(value), help=help, default=default)
if options["diff"]:
if value != default:
line = self.style.SUCCESS(line)
Expand Down
Loading

0 comments on commit c689361

Please sign in to comment.