Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added workflows for code quality checks #14

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Python CI

on:
push:
branches: [main]
pull_request:
branches:
- '**'


jobs:
run_tests:
name: tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.12']
toxenv: [quality]

steps:
- uses: actions/checkout@v3
- name: setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Dependencies
run: pip install -r requirements/dev.txt

- name: Run Tox
env:
TOXENV: ${{ matrix.toxenv }}
run: tox
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY . /app/

RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -r requirements/base.txt

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ $ pyenv activate venv-3.12.6
### Install dependencies:
At project root run the following command to install dependencies:
```bash
$ pip install -r requirements.txt
$ pip install -r requirements/base.txt
```
### Database setup
Create a new database using command
Expand Down
3 changes: 2 additions & 1 deletion events/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from .models import *

from .models import Event, Tag, VideoAsset

admin.site.register(Event)
admin.site.register(VideoAsset)
Expand Down
1 change: 1 addition & 0 deletions events/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@


class EventsConfig(AppConfig):
""" Configuration for the events app """
default_auto_field = 'django.db.models.BigAutoField'
name = 'events'
13 changes: 9 additions & 4 deletions events/models.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
from django.db import models
from django.contrib.auth import get_user_model
from django.db import models
from django.utils.translation import gettext_lazy as _

User = get_user_model()


class Tag(models.Model):
""" Model to store tags for events """
name = models.CharField(max_length=100, unique=True)
sameeramin marked this conversation as resolved.
Show resolved Hide resolved
description = models.TextField()
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)


def __str__(self):
return self.name


class Event(models.Model):
""" Model to store events """
class EventType(models.TextChoices):
""" Enum for event types """
SESSION = "SESSION", _("Session")

class EventStatus(models.TextChoices):
""" Enum for event status """
DRAFT = "DRAFT", _("Draft")
PUBLISHED = "PUBLISHED", _("Published")
ARCHIVED = "ARCHIVED", _("Archived")


creator = models.ForeignKey(User, on_delete=models.DO_NOTHING, related_name='events')
title = models.CharField(max_length=255)
description = models.TextField()
Expand All @@ -41,12 +45,13 @@ def __str__(self):


class VideoAsset(models.Model):
""" Model to store video assets """
class VideoStatus(models.TextChoices):
""" Enum for video status """
PROCESSING = "PROCESSING", _("Processing")
READY = "READY", _("Ready")
FAILED = "FAILED", _("Failed")


event = models.ForeignKey(Event, on_delete=models.DO_NOTHING, related_name='videos')
title = models.CharField(max_length=255)
cdn_url = models.URLField()
Expand Down
2 changes: 0 additions & 2 deletions events/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.test import TestCase

# Create your tests here.
4 changes: 4 additions & 0 deletions events/v1/filters.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import django_filters

from django.db.models import Q

from events.models import Event


class EventFilter(django_filters.rest_framework.FilterSet):
""" Filter for the Event model """

search = django_filters.CharFilter(method='filter_search')
tag = django_filters.CharFilter(method='filter_tag')
Expand All @@ -14,6 +16,7 @@ class Meta:
fields = ('event_type', 'is_featured', 'status')

def filter_search(self, queryset, _, value):
""" Filter the queryset based on the search value """
return queryset.filter(
Q(title__icontains=value) |
Q(description__icontains=value) |
Expand All @@ -22,6 +25,7 @@ def filter_search(self, queryset, _, value):
)

def filter_tag(self, queryset, _, value):
""" Filter the queryset based on the tag value """
return queryset.filter(
tags__name=value
)
10 changes: 8 additions & 2 deletions events/v1/serializers.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
from rest_framework import serializers
from events.models import Event

from django.contrib.auth import get_user_model

from events.models import Event

user_model = get_user_model()


class PublisherSerializer(serializers.ModelSerializer):
""" Serializer for the publisher field in the Event model """

class Meta:
model = user_model
fields = ('id', 'first_name', 'last_name')


class EventSerializer(serializers.ModelSerializer):
""" Serializer for the Event model """

publisher = PublisherSerializer(source='creator')
tags = serializers.SerializerMethodField()
tags = serializers.SerializerMethodField()

class Meta:
model = Event
Expand All @@ -25,4 +30,5 @@ class Meta:

@staticmethod
def get_tags(event):
""" Get the tags of an event """
return event.tags.all().values_list('name', flat=True)
3 changes: 2 additions & 1 deletion events/v1/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import path
from .views import EventTypeListView, EventsListView

from .views import EventsListView, EventTypeListView

urlpatterns = [
path('event_types/', EventTypeListView.as_view(), name='event-type-list'),
Expand Down
14 changes: 10 additions & 4 deletions events/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
from rest_framework.pagination import PageNumberPagination
from rest_framework.views import APIView
from rest_framework import status
from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView

from events.models import Event
from events.v1.filters import EventFilter
from events.v1.serializers import EventSerializer


class EventTypeListView(APIView):
""" View for listing the event types """
def get(self, request, *args, **kwargs):
""" Get the event types """
event_types = [
{"label": choice[0], "key": choice[1]}
for choice in Event.EventType.choices
]
return Response(event_types, status=status.HTTP_200_OK)



class EventsListView(ListAPIView):
""" View for listing the events """

queryset = Event.objects.all()
serializer_class = EventSerializer
Expand Down
2 changes: 0 additions & 2 deletions events/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.shortcuts import render

# Create your views here.
61 changes: 61 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[MASTER]
ignore = migrations, management
load-plugins = pylint_django

[MESSAGES CONTROL]
disable=
invalid-name,
django-not-configured,
consider-using-with,
bad-option-value,
too-many-positional-arguments,
logging-format-interpolation,
missing-module-docstring,
abstract-method,
sameeramin marked this conversation as resolved.
Show resolved Hide resolved

[FORMAT]
max-line-length = 120
ignore-long-lines = ^\s*(# )?((<?https?://\S+>?)|(\.\. \w+: .*))$
single-line-if-stmt = no
max-module-lines = 1000
indent-string = ' '

[MISCELLANEOUS]
notes = FIXME,XXX,TODO

[SIMILARITIES]
min-similarity-lines = 4
ignore-comments = yes
ignore-docstrings = yes
ignore-imports = no

[VARIABLES]
init-import = no
dummy-variables-rgx = _|dummy|unused|.*_unused
additional-builtins =

[CLASSES]
defining-attr-methods = __init__,__new__,setUp
valid-classmethod-first-arg = cls
valid-metaclass-classmethod-first-arg = mcs

[DESIGN]
max-args = 5
ignored-argument-names = _.*
max-locals = 15
max-returns = 6
max-branches = 12
max-statements = 50
max-parents = 7
max-attributes = 7
min-public-methods = 2
max-public-methods = 20

[IMPORTS]
deprecated-modules = regsub,TERMIOS,Bastion,rexec
import-graph =
ext-import-graph =
int-import-graph =

[EXCEPTIONS]
overgeneral-exceptions = builtins.Exception
File renamed without changes.
5 changes: 5 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tox==4.24.1
pylint==3.3.3
pycodestyle==2.12.1
isort==5.13.2
pylint_django==2.6.1
48 changes: 48 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[tox]
envlist = py312-django{42}

[isort]
line_length = 120
known_django = django
known_first_party = events,users
include_trailing_comma = true
multi_line_output = 3
sections = FUTURE,STDLIB,THIRDPARTY,DJANGO,FIRSTPARTY,LOCALFOLDER

[pycodestyle]
exclude = .git,.tox,migrations
max-line-length = 120

[testenv]
setenv =
TOXENV={envname}
deps =
django42: Django>=4.2,<5.0
-r{toxinidir}/requirements/base.txt
commands =
python check

[testenv:isort]
deps =
-r{toxinidir}/requirements/dev.txt
commands =
isort --skip migrations events users

[testenv:isort-check]
deps =
-r{toxinidir}/requirements/dev.txt
commands =
isort --skip migrations --check-only --diff events users
[testenv:quality]
setenv =
DJANGO_SETTINGS_MODULE = arbisoft_sessions_portal.settings.base
allowlist_externals =
rm
touch
deps =
-r{toxinidir}/requirements/base.txt
-r{toxinidir}/requirements/dev.txt
commands =
pylint events users
pycodestyle events users
isort --skip migrations --check-only --diff events users
2 changes: 0 additions & 2 deletions users/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.contrib import admin

# Register your models here.
1 change: 1 addition & 0 deletions users/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@


class UsersConfig(AppConfig):
""" Configuration for the users app """
default_auto_field = 'django.db.models.BigAutoField'
name = 'users'
2 changes: 0 additions & 2 deletions users/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.db import models

# Create your models here.
2 changes: 0 additions & 2 deletions users/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions users/v1/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from rest_framework import serializers


class LoginUserSerializer(serializers.Serializer):
""" Serializer for the login user """

auth_token = serializers.CharField(required=True)
3 changes: 2 additions & 1 deletion users/v1/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import path
from users.v1.views import LoginUserView, HelloWorldView

from users.v1.views import HelloWorldView, LoginUserView

urlpatterns = [
path('login', LoginUserView.as_view(), name='login_user'),
Expand Down
Loading
Loading