Skip to content

Commit

Permalink
lint (#35)
Browse files Browse the repository at this point in the history
* lint
  • Loading branch information
saxix authored Jun 20, 2024
1 parent bee4c3c commit 8f0e63e
Show file tree
Hide file tree
Showing 22 changed files with 220 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/label-pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
label-pullrequest:
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/')))
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
permissions:
contents: read
pull-requests: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ permissions:

jobs:
changes:
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/')))
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
name: check files
runs-on: ubuntu-latest
timeout-minutes: 3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ permissions:

jobs:
changes:
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/')))
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
name: check files
runs-on: ubuntu-latest
timeout-minutes: 3
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ jobs:
sarif_file: 'trivy-results.sarif'

release:
if:
contains('
refs/heads/develop
refs/heads/staging
refs/heads/master
', github.ref) || contains(github.event.head_commit.message, 'ci:release')

name: "Release Docker"
needs: [ test ]
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion src/hope_dedup_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from hope_dedup_engine.config.celery import app as celery_app


VERSION = __version__ = "0.1.0"

__all__ = ("celery_app",)
7 changes: 6 additions & 1 deletion src/hope_dedup_engine/apps/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
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: 3 additions & 1 deletion src/hope_dedup_engine/apps/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ 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: 5 additions & 1 deletion src/hope_dedup_engine/apps/api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
from hope_dedup_engine.apps.api.models.auth import HDEToken # noqa: F401
from hope_dedup_engine.apps.api.models.deduplication import DeduplicationSet, Duplicate, Image # noqa: F401
from hope_dedup_engine.apps.api.models.deduplication import ( # noqa: F401
DeduplicationSet,
Duplicate,
Image,
)
4 changes: 3 additions & 1 deletion src/hope_dedup_engine/apps/api/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@


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: 27 additions & 6 deletions src/hope_dedup_engine/apps/api/models/deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
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 @@ -27,11 +30,19 @@ 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 @@ -43,7 +54,11 @@ 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 @@ -63,9 +78,15 @@ 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)
25 changes: 19 additions & 6 deletions src/hope_dedup_engine/apps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@
)

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)),
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ 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: 19 additions & 5 deletions src/hope_dedup_engine/apps/core/management/commands/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@ 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 @@ -62,7 +74,9 @@ 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
13 changes: 10 additions & 3 deletions src/hope_dedup_engine/apps/core/management/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def get_options(self, options: dict[str, Any]) -> None:
self.debug = options["debug"]

self.admin_email = str(options["admin_email"] or env("ADMIN_EMAIL", ""))
self.admin_password = str(options["admin_password"] or env("ADMIN_PASSWORD", ""))
self.admin_password = str(
options["admin_password"] or env("ADMIN_PASSWORD", "")
)

def halt(self, e: Exception) -> None:
self.stdout.write(str(e), style_func=self.style.ERROR)
Expand Down Expand Up @@ -123,7 +125,9 @@ def handle(self, *args: Any, **options: Any) -> None: # noqa: C901
call_command("check", deploy=True, verbosity=self.verbosity - 1)
if self.static:
static_root = Path(env("STATIC_ROOT"))
echo(f"Run collectstatic to: '{static_root}' - '{static_root.absolute()}")
echo(
f"Run collectstatic to: '{static_root}' - '{static_root.absolute()}"
)
if not static_root.exists():
static_root.mkdir(parents=True)
call_command("collectstatic", **extra)
Expand All @@ -144,7 +148,10 @@ def handle(self, *args: Any, **options: Any) -> None: # noqa: C901
style_func=self.style.WARNING,
)
else:
echo(f"Creating superuser: {self.admin_email}", style_func=self.style.WARNING)
echo(
f"Creating superuser: {self.admin_email}",
style_func=self.style.WARNING,
)
validate_email(self.admin_email)
os.environ["DJANGO_SUPERUSER_USERNAME"] = self.admin_email
os.environ["DJANGO_SUPERUSER_EMAIL"] = self.admin_email
Expand Down
4 changes: 3 additions & 1 deletion src/hope_dedup_engine/apps/security/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class ExternalSystem(models.Model):


class User(SecurityMixin, AbstractUser):
external_system = models.ForeignKey(ExternalSystem, on_delete=models.SET_NULL, null=True, blank=True)
external_system = models.ForeignKey(
ExternalSystem, on_delete=models.SET_NULL, null=True, blank=True
)

class Meta:
abstract = False
Expand Down
4 changes: 3 additions & 1 deletion src/hope_dedup_engine/apps/social/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from social_core.backends.base import BaseAuth


def save_to_group(backend: BaseAuth, user: Optional[User] = None, **kwargs: Any) -> dict[str, Any]:
def save_to_group(
backend: BaseAuth, user: Optional[User] = None, **kwargs: Any
) -> dict[str, Any]:
if user:
grp = Group.objects.get(name=config.NEW_USER_DEFAULT_GROUP)
user.groups.add(grp)
Expand Down
Loading

0 comments on commit 8f0e63e

Please sign in to comment.