Skip to content

Commit

Permalink
Merge pull request #680 from ae-utbm/ruff
Browse files Browse the repository at this point in the history
Introduct Ruff as formater and linter
  • Loading branch information
imperosol authored Jun 26, 2024
2 parents a8b9f38 + 3143d3d commit a5cbac1
Show file tree
Hide file tree
Showing 177 changed files with 848 additions and 1,028 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup_project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ runs:
${{ runner.os }}-poetry-
- name: Install dependencies
run: poetry install -E testing -E docs
run: poetry install --with docs,tests
shell: bash

- name: Install xapian
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ on:
workflow_dispatch:

jobs:
black:
name: Black format
ruff:
name: Ruff lint & format
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Setup Project
uses: ./.github/actions/setup_project
- run: poetry run black --check .
- uses: actions/checkout@v4
- name: ruff format
uses: chartboost/ruff-action@v1 # format
with:
args: format --diff
- name: ruff check
uses: chartboost/ruff-action@v1 # lint

tests:
name: Run tests and generate coverage report
Expand Down
1 change: 0 additions & 1 deletion accounting/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from accounting.models import *


admin.site.register(BankAccount)
admin.site.register(ClubAccount)
admin.site.register(GeneralJournal)
Expand Down
5 changes: 3 additions & 2 deletions accounting/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.core.validators
import accounting.models
import django.db.models.deletion
from django.db import migrations, models

import accounting.models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion accounting/migrations/0002_auto_20160824_2152.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion accounting/migrations/0003_auto_20160824_2203.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import phonenumber_field.modelfields
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion accounting/migrations/0004_auto_20161005_1505.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
14 changes: 7 additions & 7 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
#
#

from django.urls import reverse
from django.core.exceptions import ValidationError
from decimal import Decimal

from django.conf import settings
from django.core import validators
from django.core.exceptions import ValidationError
from django.db import models
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from django.template import defaultfilters

from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField

from decimal import Decimal
from core.models import User, SithFile
from club.models import Club
from core.models import SithFile, User


class CurrencyField(models.DecimalField):
Expand Down
10 changes: 5 additions & 5 deletions accounting/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
#
#

from datetime import date, timedelta

from django.test import TestCase
from django.urls import reverse
from django.core.management import call_command
from datetime import date, timedelta

from core.models import User
from accounting.models import (
AccountingType,
GeneralJournal,
Operation,
Label,
AccountingType,
Operation,
SimplifiedAccountingType,
)
from core.models import User


class RefoundAccountTest(TestCase):
Expand Down
56 changes: 28 additions & 28 deletions accounting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@
#
#

from django.views.generic import ListView, DetailView
from django.views.generic.edit import UpdateView, CreateView, DeleteView, FormView
from django.urls import reverse_lazy, reverse
from django.utils.translation import gettext_lazy as _
from django.forms.models import modelform_factory
import collections

from ajax_select.fields import AutoCompleteSelectField
from django import forms
from django.conf import settings
from django.core.exceptions import PermissionDenied, ValidationError
from django.forms import HiddenInput
from django.db import transaction
from django.db.models import Sum
from django.conf import settings
from django import forms
from django.forms import HiddenInput
from django.forms.models import modelform_factory
from django.http import HttpResponse
import collections

from ajax_select.fields import AutoCompleteSelectField
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, ListView
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView

from core.views import (
CanViewMixin,
CanEditMixin,
CanEditPropMixin,
CanCreateMixin,
TabedViewMixin,
)
from core.views.forms import SelectFile, SelectDate
from accounting.models import (
AccountingType,
BankAccount,
ClubAccount,
Company,
GeneralJournal,
Label,
Operation,
AccountingType,
Company,
SimplifiedAccountingType,
Label,
)
from counter.models import Counter, Selling, Product
from core.views import (
CanCreateMixin,
CanEditMixin,
CanEditPropMixin,
CanViewMixin,
TabedViewMixin,
)
from core.views.forms import SelectDate, SelectFile
from counter.models import Counter, Product, Selling

# Main accounting view

Expand Down Expand Up @@ -521,14 +521,14 @@ class OperationPDFView(CanViewMixin, DetailView):
pk_url_kwarg = "op_id"

def get(self, request, *args, **kwargs):
from reportlab.pdfgen import canvas
from reportlab.lib.units import cm
from reportlab.platypus import Table, TableStyle
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import cm
from reportlab.lib.utils import ImageReader
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas
from reportlab.platypus import Table, TableStyle

pdfmetrics.registerFont(TTFont("DejaVu", "DejaVuSerif.ttf"))

Expand Down Expand Up @@ -599,7 +599,7 @@ def get(self, request, *args, **kwargs):
payment_mode = ""
for m in settings.SITH_ACCOUNTING_PAYMENT_METHOD:
if m[0] == mode:
payment_mode += "[\u00D7]"
payment_mode += "[\u00d7]"
else:
payment_mode += "[ ]"
payment_mode += " %s\n" % (m[1])
Expand Down
2 changes: 0 additions & 2 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
#
#

from django.contrib import admin

# Register your models here.
2 changes: 0 additions & 2 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
#
#

from django.db import models

# Create your models here.
2 changes: 0 additions & 2 deletions api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
#
#

from django.test import TestCase

# Create your tests here.
4 changes: 2 additions & 2 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#
#

from django.urls import re_path, path, include
from django.urls import include, path, re_path
from rest_framework import routers

from api.views import *
from rest_framework import routers

# Router config
router = routers.DefaultRouter()
Expand Down
14 changes: 7 additions & 7 deletions api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#
#

from rest_framework.response import Response
from rest_framework import viewsets
from django.core.exceptions import PermissionDenied
from rest_framework.decorators import action
from django.db.models.query import QuerySet
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response

from core.views import can_view, can_edit
from core.views import can_edit, can_view


def check_if(obj, user, test):
Expand Down Expand Up @@ -64,10 +64,10 @@ def dispatch(self, request, *arg, **kwargs):


from .api import *
from .counter import *
from .user import *
from .club import *
from .counter import *
from .group import *
from .launderette import *
from .uv import *
from .sas import *
from .user import *
from .uv import *
2 changes: 1 addition & 1 deletion api/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#
#

from rest_framework.response import Response
from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import StaticHTMLRenderer
from rest_framework.response import Response

from core.templatetags.renderer import markdown

Expand Down
10 changes: 4 additions & 6 deletions api/views/club.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
#
#

from rest_framework.response import Response
from django.conf import settings
from django.core.exceptions import PermissionDenied
from rest_framework import serializers
from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import StaticHTMLRenderer

from django.conf import settings
from django.core.exceptions import PermissionDenied

from club.models import Club, Mailing
from rest_framework.response import Response

from api.views import RightModelViewSet
from club.models import Club, Mailing


class ClubSerializer(serializers.ModelSerializer):
Expand Down
5 changes: 2 additions & 3 deletions api/views/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
#

from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.decorators import action

from counter.models import Counter
from rest_framework.response import Response

from api.views import RightModelViewSet
from counter.models import Counter


class CounterSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 1 addition & 2 deletions api/views/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

from rest_framework import serializers

from core.models import RealGroup

from api.views import RightModelViewSet
from core.models import RealGroup


class GroupSerializer(serializers.ModelSerializer):
Expand Down
5 changes: 2 additions & 3 deletions api/views/launderette.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
#

from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.decorators import action

from launderette.models import Launderette, Machine, Token
from rest_framework.response import Response

from api.views import RightModelViewSet
from launderette.models import Launderette, Machine, Token


class LaunderettePlaceSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 2 additions & 1 deletion api/views/sas.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import List

from rest_framework.decorators import api_view, renderer_classes
from rest_framework.exceptions import PermissionDenied
from rest_framework.generics import get_object_or_404
from rest_framework.renderers import JSONRenderer
from rest_framework.request import Request
from rest_framework.response import Response

from core.views import can_edit
from core.models import User
from core.views import can_edit
from sas.models import Picture


Expand Down
Loading

0 comments on commit a5cbac1

Please sign in to comment.