From 0c8f7142c31b692673c2c72c50b7d6aefedead7f Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Wed, 22 May 2024 18:43:56 -0300 Subject: [PATCH 1/6] Refactor manage.py to reflect django 5.0 --- manage.py | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/manage.py b/manage.py index a164f32..a22657d 100755 --- a/manage.py +++ b/manage.py @@ -1,31 +1,26 @@ #!/usr/bin/env python -""" -Django administration utility. -""" - -from __future__ import absolute_import, unicode_literals - +"""Django's command-line utility for administrative tasks.""" import os import sys PWD = os.path.abspath(os.path.dirname(__file__)) -if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings') + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") sys.path.append(PWD) + try: - from django.core.management import execute_from_command_line # pylint: disable=wrong-import-position - except ImportError: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django # pylint: disable=unused-import, wrong-import-position - except ImportError: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) - raise + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() From 45f96c6f9e39b87f6390306beebb7026c0610181 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Wed, 22 May 2024 18:44:54 -0300 Subject: [PATCH 2/6] Set up ruff --- .isort.cfg | 5 ++--- .pre-commit-config.yaml | 10 ++++++++++ .ruff.toml | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 .ruff.toml diff --git a/.isort.cfg b/.isort.cfg index 7d97fc2..f7a23b4 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,9 +1,8 @@ [settings] -line_length=120 -multi_line_output=5 +line_length=100 known_django=django sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER lines_after_imports=2 atomic=True combine_star=True -skip=/venv,/env,/node_modules,migrations \ No newline at end of file +skip=/venv,/env,/node_modules,migrations diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db257ec..00c7db3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,16 @@ repos: - id: debug-statements - id: detect-private-key + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.4.4 + hooks: + # Run the linter. + - id: ruff + args: [--fix] + # Run the formatter. + - id: ruff-format + - repo: local hooks: - id: isort diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..f5b3785 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,18 @@ +exclude = [ + "env", + "venv", + ".pyenv", + ".pytest_cache", + "*/__pycache__/*", + "*/migrations/*", + "docs", +] + +line-length = 100 + +target-version = "py38" + +[format] +quote-style = "double" +indent-style = "space" +line-ending = "auto" From a9bdf437035335fd346fad9bf881bc2e8ebce671 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Wed, 22 May 2024 19:03:45 -0300 Subject: [PATCH 3/6] Run ruff format --- .isort.cfg | 6 +- conftest.py | 7 +- drf_rw_serializers/apps.py | 2 +- drf_rw_serializers/generics.py | 45 ++++--------- drf_rw_serializers/mixins.py | 12 +--- drf_rw_serializers/viewsets.py | 25 ++++--- example_app/__init__.py | 2 +- example_app/apps.py | 2 +- example_app/models.py | 12 ++-- example_app/serializers.py | 21 +++--- example_app/urls.py | 119 ++++++++++++++++++++------------- setup.py | 58 ++++++++-------- test_settings.py | 20 +++--- test_utils/base_tests.py | 112 +++++++++++++++---------------- tests/test_generics.py | 58 ++++++++-------- tests/test_mixins.py | 26 +++---- tests/test_viewsets.py | 23 ++++--- 17 files changed, 278 insertions(+), 272 deletions(-) diff --git a/.isort.cfg b/.isort.cfg index f7a23b4..91029c2 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,8 +1,12 @@ [settings] line_length=100 +multi_line_output=3 known_django=django -sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER +known_drf=rest_framework +sections=FUTURE,STDLIB,DJANGO,DRF,THIRDPARTY,FIRSTPARTY,LOCALFOLDER lines_after_imports=2 atomic=True combine_star=True +force_grid_wrap=0 +include_trailing_comma=True skip=/venv,/env,/node_modules,migrations diff --git a/conftest.py b/conftest.py index 8b4d2cb..7f19ebd 100644 --- a/conftest.py +++ b/conftest.py @@ -1,11 +1,14 @@ import os -import pytest + import django from django.conf import settings +import pytest + + # We manually designate which settings we will be using in an environment variable # This is similar to what occurs in the `manage.py` -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") # `pytest` automatically calls this function once when tests are run. diff --git a/drf_rw_serializers/apps.py b/drf_rw_serializers/apps.py index 2b56968..82d70f1 100644 --- a/drf_rw_serializers/apps.py +++ b/drf_rw_serializers/apps.py @@ -13,4 +13,4 @@ class DrfRwSerializersConfig(AppConfig): Configuration for the drf_rw_serializers Django application. """ - name = 'drf_rw_serializers' + name = "drf_rw_serializers" diff --git a/drf_rw_serializers/generics.py b/drf_rw_serializers/generics.py index e53ec50..9968e91 100644 --- a/drf_rw_serializers/generics.py +++ b/drf_rw_serializers/generics.py @@ -2,11 +2,10 @@ from rest_framework import generics, mixins -from .mixins import CreateModelMixin, UpdateModelMixin, ListModelMixin, RetrieveModelMixin +from .mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin, UpdateModelMixin class GenericAPIView(generics.GenericAPIView): - def get_serializer_class(self): """ Return the class to use for the serializer. @@ -16,13 +15,12 @@ def get_serializer_class(self): (Eg. admins get full serialization, others get basic serialization) """ assert ( - self.serializer_class is not None or - getattr(self, 'read_serializer_class', None) is not None + self.serializer_class is not None + or getattr(self, "read_serializer_class", None) is not None ), ( "'%s' should either include one of `serializer_class` and `read_serializer_class` " "attribute, or override one of the `get_serializer_class()`, " - "`get_read_serializer_class()` method." - % self.__class__.__name__ + "`get_read_serializer_class()` method." % self.__class__.__name__ ) return self.serializer_class @@ -32,7 +30,7 @@ def get_read_serializer(self, *args, **kwargs): Return the serializer instance that should be used for serializing output. """ serializer_class = self.get_read_serializer_class() - kwargs['context'] = self.get_serializer_context() + kwargs["context"] = self.get_serializer_context() return serializer_class(*args, **kwargs) def get_read_serializer_class(self): @@ -43,7 +41,7 @@ def get_read_serializer_class(self): serializations depending on the incoming request. (Eg. admins get full serialization, others get basic serialization) """ - if getattr(self, 'read_serializer_class', None) is None: + if getattr(self, "read_serializer_class", None) is None: return self.get_serializer_class() return self.read_serializer_class @@ -54,7 +52,7 @@ def get_write_serializer(self, *args, **kwargs): and deserializing input. """ serializer_class = self.get_write_serializer_class() - kwargs['context'] = self.get_serializer_context() + kwargs["context"] = self.get_serializer_context() return serializer_class(*args, **kwargs) def get_write_serializer_class(self): @@ -65,20 +63,18 @@ def get_write_serializer_class(self): serializations depending on the incoming request. (Eg. admins can send extra fields, others cannot) """ - if getattr(self, 'write_serializer_class', None) is None: + if getattr(self, "write_serializer_class", None) is None: return self.get_serializer_class() return self.write_serializer_class class CreateAPIView(CreateModelMixin, GenericAPIView): - def post(self, request, *args, **kwargs): return self.create(request, *args, **kwargs) class UpdateAPIView(UpdateModelMixin, GenericAPIView): - def put(self, request, *args, **kwargs): return self.update(request, *args, **kwargs) @@ -87,21 +83,16 @@ def patch(self, request, *args, **kwargs): class ListAPIView(ListModelMixin, GenericAPIView): - def get(self, request, *args, **kwargs): return self.list(request, *args, **kwargs) class RetrieveAPIView(RetrieveModelMixin, GenericAPIView): - def get(self, request, *args, **kwargs): return self.retrieve(request, *args, **kwargs) -class ListCreateAPIView(ListModelMixin, - CreateModelMixin, - GenericAPIView): - +class ListCreateAPIView(ListModelMixin, CreateModelMixin, GenericAPIView): def get(self, request, *args, **kwargs): return self.list(request, *args, **kwargs) @@ -109,10 +100,7 @@ def post(self, request, *args, **kwargs): return self.create(request, *args, **kwargs) -class RetrieveDestroyAPIView(RetrieveModelMixin, - mixins.DestroyModelMixin, - GenericAPIView): - +class RetrieveDestroyAPIView(RetrieveModelMixin, mixins.DestroyModelMixin, GenericAPIView): def get(self, request, *args, **kwargs): return self.retrieve(request, *args, **kwargs) @@ -120,10 +108,7 @@ def delete(self, request, *args, **kwargs): return self.destroy(request, *args, **kwargs) -class RetrieveUpdateAPIView(RetrieveModelMixin, - UpdateModelMixin, - GenericAPIView): - +class RetrieveUpdateAPIView(RetrieveModelMixin, UpdateModelMixin, GenericAPIView): def get(self, request, *args, **kwargs): return self.retrieve(request, *args, **kwargs) @@ -134,11 +119,9 @@ def patch(self, request, *args, **kwargs): return self.partial_update(request, *args, **kwargs) -class RetrieveUpdateDestroyAPIView(RetrieveModelMixin, - UpdateModelMixin, - mixins.DestroyModelMixin, - GenericAPIView): - +class RetrieveUpdateDestroyAPIView( + RetrieveModelMixin, UpdateModelMixin, mixins.DestroyModelMixin, GenericAPIView +): def get(self, request, *args, **kwargs): return self.retrieve(request, *args, **kwargs) diff --git a/drf_rw_serializers/mixins.py b/drf_rw_serializers/mixins.py index 033bcef..35b5b08 100644 --- a/drf_rw_serializers/mixins.py +++ b/drf_rw_serializers/mixins.py @@ -5,18 +5,15 @@ class UpdateModelMixin(mixins.UpdateModelMixin): - def update(self, request, *args, **kwargs): - partial = kwargs.pop('partial', False) + partial = kwargs.pop("partial", False) instance = self.get_object() - write_serializer = self.get_write_serializer( - instance, data=request.data, partial=partial) + write_serializer = self.get_write_serializer(instance, data=request.data, partial=partial) write_serializer.is_valid(raise_exception=True) self.perform_update(write_serializer) # pylint: disable=protected-access - if getattr(instance, '_prefetched_objects_cache', None) is not None: - + if getattr(instance, "_prefetched_objects_cache", None) is not None: # If 'prefetch_related' has been applied to a queryset, we need to # forcibly invalidate the prefetch cache on the instance. instance._prefetched_objects_cache = {} @@ -27,7 +24,6 @@ def update(self, request, *args, **kwargs): class CreateModelMixin(mixins.CreateModelMixin): - def create(self, request, *args, **kwargs): write_serializer = self.get_write_serializer(data=request.data) write_serializer.is_valid(raise_exception=True) @@ -40,7 +36,6 @@ def create(self, request, *args, **kwargs): class ListModelMixin(mixins.ListModelMixin): - def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) @@ -54,7 +49,6 @@ def list(self, request, *args, **kwargs): class RetrieveModelMixin(mixins.RetrieveModelMixin): - def retrieve(self, request, *args, **kwargs): instance = self.get_object() serializer = self.get_read_serializer(instance) diff --git a/drf_rw_serializers/viewsets.py b/drf_rw_serializers/viewsets.py index c47c6fa..4c341f5 100644 --- a/drf_rw_serializers/viewsets.py +++ b/drf_rw_serializers/viewsets.py @@ -1,26 +1,25 @@ # -*- coding: utf-8 -*- -from rest_framework import viewsets, mixins +from rest_framework import mixins, viewsets from .generics import GenericAPIView -from .mixins import CreateModelMixin, UpdateModelMixin, ListModelMixin, RetrieveModelMixin +from .mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin, UpdateModelMixin -class GenericViewSet(GenericAPIView, - viewsets.GenericViewSet): +class GenericViewSet(GenericAPIView, viewsets.GenericViewSet): pass -class ModelViewSet(CreateModelMixin, - RetrieveModelMixin, - UpdateModelMixin, - mixins.DestroyModelMixin, - ListModelMixin, - GenericViewSet): +class ModelViewSet( + CreateModelMixin, + RetrieveModelMixin, + UpdateModelMixin, + mixins.DestroyModelMixin, + ListModelMixin, + GenericViewSet, +): pass -class ReadOnlyModelViewSet(RetrieveModelMixin, - ListModelMixin, - GenericViewSet): +class ReadOnlyModelViewSet(RetrieveModelMixin, ListModelMixin, GenericViewSet): pass diff --git a/example_app/__init__.py b/example_app/__init__.py index f572456..f35242b 100644 --- a/example_app/__init__.py +++ b/example_app/__init__.py @@ -1 +1 @@ -default_app_config = 'example_app.apps.ExampleAppConfig' # pylint: disable=invalid-name +default_app_config = "example_app.apps.ExampleAppConfig" # pylint: disable=invalid-name diff --git a/example_app/apps.py b/example_app/apps.py index e417738..4e614b8 100644 --- a/example_app/apps.py +++ b/example_app/apps.py @@ -13,4 +13,4 @@ class ExampleAppConfig(AppConfig): Configuration for the example_app Django application. """ - name = 'example_app' + name = "example_app" diff --git a/example_app/models.py b/example_app/models.py index 5d4fb83..ed2efa6 100644 --- a/example_app/models.py +++ b/example_app/models.py @@ -8,16 +8,14 @@ class Order(models.Model): @property def total_price(self): - return sum([ - o.meal.price * o.quantity - for o in self.ordered_meals.select_related('meal').all() - ]) + return sum( + [o.meal.price * o.quantity for o in self.ordered_meals.select_related("meal").all()] + ) class OrderedMeal(models.Model): - order = models.ForeignKey( - 'Order', related_name="ordered_meals", on_delete=models.CASCADE) - meal = models.ForeignKey('Meal', on_delete=models.CASCADE) + order = models.ForeignKey("Order", related_name="ordered_meals", on_delete=models.CASCADE) + meal = models.ForeignKey("Meal", on_delete=models.CASCADE) quantity = models.IntegerField(default=1) diff --git a/example_app/serializers.py b/example_app/serializers.py index ada19ec..492c29f 100644 --- a/example_app/serializers.py +++ b/example_app/serializers.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- from rest_framework import serializers -from .models import Order, OrderedMeal, Meal +from .models import Meal, Order, OrderedMeal -class OrderedMealCreateSerializer(serializers.ModelSerializer): +class OrderedMealCreateSerializer(serializers.ModelSerializer): class Meta: model = OrderedMeal - fields = ('id', 'quantity', 'meal') + fields = ("id", "quantity", "meal") class OrderCreateSerializer(serializers.ModelSerializer): @@ -16,10 +16,10 @@ class OrderCreateSerializer(serializers.ModelSerializer): class Meta: model = Order - fields = ('id', 'table_number', 'ordered_meals', 'total_price') + fields = ("id", "table_number", "ordered_meals", "total_price") def create(self, validated_data): - ordered_meals_dict_list = validated_data.pop('ordered_meals') + ordered_meals_dict_list = validated_data.pop("ordered_meals") instance = Order.objects.create(**validated_data) for ordered_meal_dict in ordered_meals_dict_list: instance.ordered_meals.create(**ordered_meal_dict) @@ -27,9 +27,9 @@ def create(self, validated_data): return instance def update(self, instance, validated_data): - ordered_meals_dict_list = validated_data.pop('ordered_meals', None) + ordered_meals_dict_list = validated_data.pop("ordered_meals", None) - instance.table_number = validated_data.pop('table_number', instance.table_number) + instance.table_number = validated_data.pop("table_number", instance.table_number) instance.save() @@ -42,10 +42,9 @@ def update(self, instance, validated_data): class MealSerializer(serializers.ModelSerializer): - class Meta: model = Meal - fields = ('id', 'name', 'price') + fields = ("id", "name", "price") class OrderedMealDetailsSerializer(serializers.ModelSerializer): @@ -53,7 +52,7 @@ class OrderedMealDetailsSerializer(serializers.ModelSerializer): class Meta: model = OrderedMeal - fields = ('id', 'quantity', 'meal') + fields = ("id", "quantity", "meal") class OrderListSerializer(serializers.ModelSerializer): @@ -61,4 +60,4 @@ class OrderListSerializer(serializers.ModelSerializer): class Meta: model = Order - fields = ('id', 'table_number', 'ordered_meals', 'total_price') + fields = ("id", "table_number", "ordered_meals", "total_price") diff --git a/example_app/urls.py b/example_app/urls.py index 1874d80..2013e19 100644 --- a/example_app/urls.py +++ b/example_app/urls.py @@ -4,56 +4,85 @@ from rest_framework.urlpatterns import format_suffix_patterns from .views import ( - OrderCreateWithGenericEndpoint, OrderCreateWithMixinEndpoint, OrderListCreateEndpoint, OrderListWithGenericEndpoint, - OrderListWithMixinEndpoint, OrderListWithoutReadSerializerEndpoint, OrderRetrieveUpdateDestroyEndpoint, - OrderRetrieveUpdateEndpoint, OrderRetrieveWithGenericEndpoint, OrderRetrieveWithMixinEndpoint, - OrderUpdateWithGenericEndpoint, OrderUpdateWithMixinEndpoint, OrderViewset + OrderCreateWithGenericEndpoint, + OrderCreateWithMixinEndpoint, + OrderListCreateEndpoint, + OrderListWithGenericEndpoint, + OrderListWithMixinEndpoint, + OrderListWithoutReadSerializerEndpoint, + OrderRetrieveUpdateDestroyEndpoint, + OrderRetrieveUpdateEndpoint, + OrderRetrieveWithGenericEndpoint, + OrderRetrieveWithMixinEndpoint, + OrderUpdateWithGenericEndpoint, + OrderUpdateWithMixinEndpoint, + OrderViewset, ) urlpatterns = [ - path('orders-list-without-read-serializer/', + path( + "orders-list-without-read-serializer/", OrderListWithoutReadSerializerEndpoint.as_view(), - name='list_without_read_serializer'), - - path('orders/', OrderListCreateEndpoint.as_view(), name='list_create'), - re_path(r'^orders/(?P[0-9]+)$', OrderRetrieveUpdateDestroyEndpoint.as_view(), - name='retrieve_update_destroy'), - re_path(r'^orders-retrieve-update/(?P[0-9]+)$', OrderRetrieveUpdateEndpoint.as_view(), - name='retrieve_update'), - path('orders-list-generic-view/', OrderListWithGenericEndpoint.as_view(), - name='list'), - re_path(r'^orders-retrieve-generic-view/(?P[0-9]+)$', + name="list_without_read_serializer", + ), + path("orders/", OrderListCreateEndpoint.as_view(), name="list_create"), + re_path( + r"^orders/(?P[0-9]+)$", + OrderRetrieveUpdateDestroyEndpoint.as_view(), + name="retrieve_update_destroy", + ), + re_path( + r"^orders-retrieve-update/(?P[0-9]+)$", + OrderRetrieveUpdateEndpoint.as_view(), + name="retrieve_update", + ), + path("orders-list-generic-view/", OrderListWithGenericEndpoint.as_view(), name="list"), + re_path( + r"^orders-retrieve-generic-view/(?P[0-9]+)$", OrderRetrieveWithGenericEndpoint.as_view(), - name='retrieve'), - path('orders-create-generic-view/', OrderCreateWithGenericEndpoint.as_view(), - name='create'), - re_path(r'^orders-update-generic-view/(?P[0-9]+)$', OrderUpdateWithGenericEndpoint.as_view(), - name='update'), - - path('orders-list-mixin/', OrderListWithMixinEndpoint.as_view(), - name='list_mixin'), - re_path(r'^orders-retrieve-mixin/(?P[0-9]+)$', OrderRetrieveWithMixinEndpoint.as_view(), - name='retrieve_mixin'), - path('orders-create-mixin/', OrderCreateWithMixinEndpoint.as_view(), - name='create_mixin'), - re_path(r'^orders-update-mixin/(?P[0-9]+)$', OrderUpdateWithMixinEndpoint.as_view(), - name='update_mixin'), - - path('orders-viewset/', - OrderViewset.as_view({ - 'get': 'list', - 'post': 'create', - }), - name='viewset_list_create'), - re_path(r'^orders-viewset/(?P[0-9]+)$', - OrderViewset.as_view({ - 'get': 'retrieve', - 'put': 'update', - 'patch': 'partial_update', - 'delete': 'destroy', - }), - name='viewset_retrieve_update_destroy'), + name="retrieve", + ), + path("orders-create-generic-view/", OrderCreateWithGenericEndpoint.as_view(), name="create"), + re_path( + r"^orders-update-generic-view/(?P[0-9]+)$", + OrderUpdateWithGenericEndpoint.as_view(), + name="update", + ), + path("orders-list-mixin/", OrderListWithMixinEndpoint.as_view(), name="list_mixin"), + re_path( + r"^orders-retrieve-mixin/(?P[0-9]+)$", + OrderRetrieveWithMixinEndpoint.as_view(), + name="retrieve_mixin", + ), + path("orders-create-mixin/", OrderCreateWithMixinEndpoint.as_view(), name="create_mixin"), + re_path( + r"^orders-update-mixin/(?P[0-9]+)$", + OrderUpdateWithMixinEndpoint.as_view(), + name="update_mixin", + ), + path( + "orders-viewset/", + OrderViewset.as_view( + { + "get": "list", + "post": "create", + } + ), + name="viewset_list_create", + ), + re_path( + r"^orders-viewset/(?P[0-9]+)$", + OrderViewset.as_view( + { + "get": "retrieve", + "put": "update", + "patch": "partial_update", + "delete": "destroy", + } + ), + name="viewset_retrieve_update_destroy", + ), ] -urlpatterns = format_suffix_patterns(urlpatterns) \ No newline at end of file +urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/setup.py b/setup.py index 9e46afb..8499e86 100755 --- a/setup.py +++ b/setup.py @@ -16,53 +16,53 @@ def get_version(*file_paths): """ filename = os.path.join(os.path.dirname(__file__), *file_paths) version_file = open(filename).read() - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", - version_file, re.M) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) if version_match: return version_match.group(1) - raise RuntimeError('Unable to find version string.') + raise RuntimeError("Unable to find version string.") -VERSION = get_version('drf_rw_serializers', '__init__.py') +VERSION = get_version("drf_rw_serializers", "__init__.py") -if sys.argv[-1] == 'tag': +if sys.argv[-1] == "tag": print("Tagging the version on github:") os.system("git tag -a %s -m 'version %s'" % (VERSION, VERSION)) os.system("git push --tags") sys.exit() -README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read() -CHANGELOG = open(os.path.join(os.path.dirname(__file__), 'CHANGELOG.rst')).read() +README = open(os.path.join(os.path.dirname(__file__), "README.rst")).read() +CHANGELOG = open(os.path.join(os.path.dirname(__file__), "CHANGELOG.rst")).read() setup( - name='drf-rw-serializers', + name="drf-rw-serializers", version=VERSION, - description="""Generic views, viewsets and mixins that extend the Django REST Framework ones adding separated serializers for read and write operations""", - long_description=README + '\n\n' + CHANGELOG, - author='vintasoftware', - author_email='contact@vinta.com.br', - url='https://github.com/vintasoftware/drf-rw-serializers', + description=( + "Generic views, viewsets and mixins that extend the Django REST " + "Framework ones adding separated serializers for read and write operations" + ), + long_description=README + "\n\n" + CHANGELOG, + author="vintasoftware", + author_email="contact@vinta.com.br", + url="https://github.com/vintasoftware/drf-rw-serializers", packages=[ - 'drf_rw_serializers', + "drf_rw_serializers", ], include_package_data=True, - install_requires=[ - "Django>=4.2,<6" - ], + install_requires=["Django>=4.2,<6"], license="MIT", zip_safe=False, - keywords='Django REST Framework, Serializers, REST, API, Django', + keywords="Django REST Framework, Serializers, REST, API, Django", classifiers=[ - 'Framework :: Django', - 'Framework :: Django :: 4.2', - 'Framework :: Django :: 5.0', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Natural Language :: English', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', + "Framework :: Django", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ], ) diff --git a/test_settings.py b/test_settings.py index 7e6acd1..f87427f 100644 --- a/test_settings.py +++ b/test_settings.py @@ -18,23 +18,23 @@ def root(*args): DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:', + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": ":memory:", } } INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'rest_framework', - 'example_app', + "django.contrib.auth", + "django.contrib.contenttypes", + "rest_framework", + "example_app", ) LOCALE_PATHS = [ - root('drf_rw_serializers', 'conf', 'locale'), + root("drf_rw_serializers", "conf", "locale"), ] -ROOT_URLCONF = 'example_app.urls' +ROOT_URLCONF = "example_app.urls" -SECRET_KEY = 'insecure-secret-key' +SECRET_KEY = "insecure-secret-key" diff --git a/test_utils/base_tests.py b/test_utils/base_tests.py index 0627719..477dbec 100644 --- a/test_utils/base_tests.py +++ b/test_utils/base_tests.py @@ -1,141 +1,141 @@ from django.contrib.auth import get_user_model + +from rest_framework.test import APIClient, APITestCase + from model_bakery import baker -from rest_framework.test import APITestCase, APIClient from example_app.models import Order from example_app.serializers import OrderedMealDetailsSerializer class BaseTestCase(APITestCase): - def setUp(self): - self.meals = baker.make('example_app.Meal', _quantity=3) + self.meals = baker.make("example_app.Meal", _quantity=3) user_model = get_user_model() - self.user_email = 'user' - self.user_password = 'the_password' + self.user_email = "user" + self.user_password = "the_password" self.user = user_model.objects.create_user( - username=self.user_email, password=self.user_password) + username=self.user_email, password=self.user_password + ) self.auth_client = APIClient() self.auth_client.force_authenticate(self.user) class TestListRequestSuccess(object): - def test_list_request_success(self): - orders = baker.make('example_app.Order', _quantity=3) + orders = baker.make("example_app.Order", _quantity=3) for order in orders: - baker.make('example_app.OrderedMeal', order=order, _quantity=2) + baker.make("example_app.OrderedMeal", order=order, _quantity=2) - response = self.auth_client.get(self.view_url, format='json') + response = self.auth_client.get(self.view_url, format="json") self.assertEqual(response.status_code, 200) - self.assertCountEqual( - response.data, self.list_serializer_class(orders, many=True).data) + self.assertCountEqual(response.data, self.list_serializer_class(orders, many=True).data) class TestRetrieveRequestSuccess(object): - def test_list_request_success(self): - order = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=order, _quantity=2) - response = self.auth_client.get(self.view_url, format='json') + order = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=order, _quantity=2) + response = self.auth_client.get(self.view_url, format="json") self.assertEqual(response.status_code, 200) - self.assertCountEqual( - response.data, self.retrieve_serializer_class(order).data) + self.assertCountEqual(response.data, self.retrieve_serializer_class(order).data) class TestCreateRequestSuccess(object): - def test_create_request_success(self): data = { - 'table_number': 100, - 'ordered_meals': [ + "table_number": 100, + "ordered_meals": [ { - 'quantity': 1, - 'meal': self.meals[0].id, + "quantity": 1, + "meal": self.meals[0].id, }, { - 'quantity': 2, - 'meal': self.meals[1].id, + "quantity": 2, + "meal": self.meals[1].id, }, ], } - response = self.auth_client.post(self.view_url, data, format='json') + response = self.auth_client.post(self.view_url, data, format="json") self.assertEqual(response.status_code, 201) - order = Order.objects.get(id=response.data['id']) + order = Order.objects.get(id=response.data["id"]) self.assertEqual(response.data, self.create_out_serializer_class(order).data) - self.assertEqual(order.table_number, data['table_number']) + self.assertEqual(order.table_number, data["table_number"]) - for ordered_meal_dict in data['ordered_meals']: - ordered_meal = order.ordered_meals.filter(meal__id=ordered_meal_dict['meal']).first() + for ordered_meal_dict in data["ordered_meals"]: + ordered_meal = order.ordered_meals.filter(meal__id=ordered_meal_dict["meal"]).first() self.assertIsNotNone(ordered_meal) - self.assertEqual(ordered_meal.quantity, ordered_meal_dict['quantity']) + self.assertEqual(ordered_meal.quantity, ordered_meal_dict["quantity"]) class TestUpdateRequestSuccess(object): - def test_update_request_success(self): data = { - 'table_number': 2, - 'ordered_meals': [ + "table_number": 2, + "ordered_meals": [ { - 'quantity': 10, - 'meal': self.meals[0].id, + "quantity": 10, + "meal": self.meals[0].id, }, { - 'quantity': 20, - 'meal': self.meals[1].id, + "quantity": 20, + "meal": self.meals[1].id, }, - ] + ], } - response = self.auth_client.put(self.view_url, data, format='json') + response = self.auth_client.put(self.view_url, data, format="json") self.object.refresh_from_db() self.assertEqual(response.status_code, 200) self.assertEqual(response.data, self.update_out_serializer_class(self.object).data) - self.assertEqual(self.object.table_number, data['table_number']) + self.assertEqual(self.object.table_number, data["table_number"]) - for ordered_meal_dict in data['ordered_meals']: + for ordered_meal_dict in data["ordered_meals"]: ordered_meal = self.object.ordered_meals.filter( - meal__id=ordered_meal_dict['meal']).first() + meal__id=ordered_meal_dict["meal"] + ).first() self.assertIsNotNone(ordered_meal) - self.assertEqual(ordered_meal.quantity, ordered_meal_dict['quantity']) + self.assertEqual(ordered_meal.quantity, ordered_meal_dict["quantity"]) def test_partial_update_table_number_request_success(self): old_ordered_meals = OrderedMealDetailsSerializer( - self.object.ordered_meals.all(), many=True).data + self.object.ordered_meals.all(), many=True + ).data data = { - 'table_number': 2, + "table_number": 2, } - response = self.auth_client.patch(self.view_url, data, format='json') + response = self.auth_client.patch(self.view_url, data, format="json") self.assertEqual(response.status_code, 200) self.object.refresh_from_db() self.assertEqual(response.data, self.update_out_serializer_class(self.object).data) - self.assertEqual(self.object.table_number, data['table_number']) + self.assertEqual(self.object.table_number, data["table_number"]) self.assertCountEqual( OrderedMealDetailsSerializer(self.object.ordered_meals.all(), many=True).data, - old_ordered_meals) + old_ordered_meals, + ) def test_partial_update_ordered_meals_request_success(self): old_table_number = self.object.table_number data = { - 'ordered_meals': [ + "ordered_meals": [ { - 'quantity': 10, - 'meal': self.meals[2].id, + "quantity": 10, + "meal": self.meals[2].id, }, ] } - response = self.auth_client.patch(self.view_url, data, format='json') + response = self.auth_client.patch(self.view_url, data, format="json") self.assertEqual(response.status_code, 200) self.object.refresh_from_db() self.assertEqual(response.data, self.update_out_serializer_class(self.object).data) - for ordered_meal_dict in data['ordered_meals']: + for ordered_meal_dict in data["ordered_meals"]: ordered_meal = self.object.ordered_meals.filter( - meal__id=ordered_meal_dict['meal']).first() + meal__id=ordered_meal_dict["meal"] + ).first() self.assertIsNotNone(ordered_meal) - self.assertEqual(ordered_meal.quantity, ordered_meal_dict['quantity']) + self.assertEqual(ordered_meal.quantity, ordered_meal_dict["quantity"]) self.assertEqual(self.object.table_number, old_table_number) diff --git a/tests/test_generics.py b/tests/test_generics.py index 984a7cf..241085b 100644 --- a/tests/test_generics.py +++ b/tests/test_generics.py @@ -12,91 +12,87 @@ from example_app.serializers import OrderCreateSerializer, OrderListSerializer from test_utils.base_tests import ( - BaseTestCase, TestCreateRequestSuccess, TestListRequestSuccess, TestRetrieveRequestSuccess, TestUpdateRequestSuccess + BaseTestCase, + TestCreateRequestSuccess, + TestListRequestSuccess, + TestRetrieveRequestSuccess, + TestUpdateRequestSuccess, ) -class OrderListCreateEndpointTests( - BaseTestCase, TestListRequestSuccess, TestCreateRequestSuccess): - +class OrderListCreateEndpointTests(BaseTestCase, TestListRequestSuccess, TestCreateRequestSuccess): def setUp(self): super(OrderListCreateEndpointTests, self).setUp() - self.view_url = reverse('list_create') + self.view_url = reverse("list_create") self.list_serializer_class = OrderListSerializer self.create_in_serializer_class = OrderCreateSerializer self.create_out_serializer_class = OrderListSerializer class OrderRetrieveUpdateDestroyEndpointTests( - BaseTestCase, TestRetrieveRequestSuccess, TestUpdateRequestSuccess): - + BaseTestCase, TestRetrieveRequestSuccess, TestUpdateRequestSuccess +): def setUp(self): super(OrderRetrieveUpdateDestroyEndpointTests, self).setUp() - self.object = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=self.object, _quantity=2) - self.view_url = reverse('retrieve_update_destroy', kwargs={'pk': self.object.pk}) + self.object = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=self.object, _quantity=2) + self.view_url = reverse("retrieve_update_destroy", kwargs={"pk": self.object.pk}) self.retrieve_serializer_class = OrderListSerializer self.update_in_serializer_class = OrderCreateSerializer self.update_out_serializer_class = OrderListSerializer -class OrderListWithoutReadSerializerEndpointTests( - BaseTestCase, TestListRequestSuccess): - +class OrderListWithoutReadSerializerEndpointTests(BaseTestCase, TestListRequestSuccess): def setUp(self): super(OrderListWithoutReadSerializerEndpointTests, self).setUp() - self.view_url = reverse('list_without_read_serializer') + self.view_url = reverse("list_without_read_serializer") self.list_serializer_class = OrderListSerializer class OrderRetrieveUpdateEndpointTests( - BaseTestCase, TestRetrieveRequestSuccess, TestUpdateRequestSuccess): - + BaseTestCase, TestRetrieveRequestSuccess, TestUpdateRequestSuccess +): def setUp(self): super(OrderRetrieveUpdateEndpointTests, self).setUp() - self.object = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=self.object, _quantity=2) - self.view_url = reverse('retrieve_update', kwargs={'pk': self.object.pk}) + self.object = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=self.object, _quantity=2) + self.view_url = reverse("retrieve_update", kwargs={"pk": self.object.pk}) self.retrieve_serializer_class = OrderListSerializer self.update_in_serializer_class = OrderCreateSerializer self.update_out_serializer_class = OrderListSerializer class OrderCreateWithGenericEndpointTests(BaseTestCase, TestCreateRequestSuccess): - def setUp(self): super(OrderCreateWithGenericEndpointTests, self).setUp() - self.view_url = reverse('create') + self.view_url = reverse("create") self.list_serializer_class = OrderListSerializer self.create_in_serializer_class = OrderCreateSerializer self.create_out_serializer_class = OrderListSerializer class OrderUpdateWithGenericEndpointTests(BaseTestCase, TestUpdateRequestSuccess): - def setUp(self): super(OrderUpdateWithGenericEndpointTests, self).setUp() - self.object = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=self.object, _quantity=2) - self.view_url = reverse('update', kwargs={'pk': self.object.pk}) + self.object = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=self.object, _quantity=2) + self.view_url = reverse("update", kwargs={"pk": self.object.pk}) self.retrieve_serializer_class = OrderListSerializer self.update_in_serializer_class = OrderCreateSerializer self.update_out_serializer_class = OrderListSerializer class OrderListWithGenericEndpointTests(BaseTestCase, TestListRequestSuccess): - def setUp(self): super(OrderListWithGenericEndpointTests, self).setUp() - self.view_url = reverse('list') + self.view_url = reverse("list") self.list_serializer_class = OrderListSerializer class OrderRetrieveWithGenericEndpointTests(BaseTestCase, TestRetrieveRequestSuccess): - def setUp(self): super(OrderRetrieveWithGenericEndpointTests, self).setUp() - self.object = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=self.object, _quantity=2) - self.view_url = reverse('retrieve', kwargs={'pk': self.object.pk}) + self.object = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=self.object, _quantity=2) + self.view_url = reverse("retrieve", kwargs={"pk": self.object.pk}) self.retrieve_serializer_class = OrderListSerializer diff --git a/tests/test_mixins.py b/tests/test_mixins.py index 321d0a2..57f1792 100644 --- a/tests/test_mixins.py +++ b/tests/test_mixins.py @@ -12,45 +12,45 @@ from example_app.serializers import OrderCreateSerializer, OrderListSerializer from test_utils.base_tests import ( - BaseTestCase, TestCreateRequestSuccess, TestListRequestSuccess, TestRetrieveRequestSuccess, TestUpdateRequestSuccess + BaseTestCase, + TestCreateRequestSuccess, + TestListRequestSuccess, + TestRetrieveRequestSuccess, + TestUpdateRequestSuccess, ) class OrderCreateWithMixinEndpointTests(BaseTestCase, TestCreateRequestSuccess): - def setUp(self): super(OrderCreateWithMixinEndpointTests, self).setUp() - self.view_url = reverse('create_mixin') + self.view_url = reverse("create_mixin") self.list_serializer_class = OrderListSerializer self.create_in_serializer_class = OrderCreateSerializer self.create_out_serializer_class = OrderListSerializer class OrderUpdateWithMixinEndpointTests(BaseTestCase, TestUpdateRequestSuccess): - def setUp(self): super(OrderUpdateWithMixinEndpointTests, self).setUp() - self.object = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=self.object, _quantity=2) - self.view_url = reverse('update_mixin', kwargs={'pk': self.object.pk}) + self.object = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=self.object, _quantity=2) + self.view_url = reverse("update_mixin", kwargs={"pk": self.object.pk}) self.retrieve_serializer_class = OrderListSerializer self.update_in_serializer_class = OrderCreateSerializer self.update_out_serializer_class = OrderListSerializer class OrderListWithMixinEndpointTests(BaseTestCase, TestListRequestSuccess): - def setUp(self): super(OrderListWithMixinEndpointTests, self).setUp() - self.view_url = reverse('list_mixin') + self.view_url = reverse("list_mixin") self.list_serializer_class = OrderListSerializer class OrderRetrieveWithMixinEndpointTests(BaseTestCase, TestRetrieveRequestSuccess): - def setUp(self): super(OrderRetrieveWithMixinEndpointTests, self).setUp() - self.object = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=self.object, _quantity=2) - self.view_url = reverse('retrieve_mixin', kwargs={'pk': self.object.pk}) + self.object = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=self.object, _quantity=2) + self.view_url = reverse("retrieve_mixin", kwargs={"pk": self.object.pk}) self.retrieve_serializer_class = OrderListSerializer diff --git a/tests/test_viewsets.py b/tests/test_viewsets.py index dfcc922..8b27688 100644 --- a/tests/test_viewsets.py +++ b/tests/test_viewsets.py @@ -12,30 +12,31 @@ from example_app.serializers import OrderCreateSerializer, OrderListSerializer from test_utils.base_tests import ( - BaseTestCase, TestCreateRequestSuccess, TestListRequestSuccess, TestRetrieveRequestSuccess, TestUpdateRequestSuccess + BaseTestCase, + TestCreateRequestSuccess, + TestListRequestSuccess, + TestRetrieveRequestSuccess, + TestUpdateRequestSuccess, ) -class OrderViewsetListCreateTests( - BaseTestCase, TestListRequestSuccess, TestCreateRequestSuccess): - +class OrderViewsetListCreateTests(BaseTestCase, TestListRequestSuccess, TestCreateRequestSuccess): def setUp(self): super(OrderViewsetListCreateTests, self).setUp() - self.view_url = reverse('viewset_list_create') + self.view_url = reverse("viewset_list_create") self.list_serializer_class = OrderListSerializer self.create_in_serializer_class = OrderCreateSerializer self.create_out_serializer_class = OrderListSerializer class OrderViewsetRetrieveUpdateDestroyTests( - BaseTestCase, TestRetrieveRequestSuccess, TestUpdateRequestSuccess): - + BaseTestCase, TestRetrieveRequestSuccess, TestUpdateRequestSuccess +): def setUp(self): super(OrderViewsetRetrieveUpdateDestroyTests, self).setUp() - self.object = baker.make('example_app.Order') - baker.make('example_app.OrderedMeal', order=self.object, _quantity=2) - self.view_url = reverse( - 'viewset_retrieve_update_destroy', kwargs={'pk': self.object.pk}) + self.object = baker.make("example_app.Order") + baker.make("example_app.OrderedMeal", order=self.object, _quantity=2) + self.view_url = reverse("viewset_retrieve_update_destroy", kwargs={"pk": self.object.pk}) self.retrieve_serializer_class = OrderListSerializer self.update_in_serializer_class = OrderCreateSerializer self.update_out_serializer_class = OrderListSerializer From 826f4f08e4bffb5355fb5a8eddb3480be4ea5b95 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Thu, 23 May 2024 11:48:36 -0300 Subject: [PATCH 4/6] Configure isort via ruff lint --- .pre-commit-config.yaml | 7 ------- .ruff.toml | 15 +++++++++++++++ manage.py | 1 + requirements/dev.txt | 24 +++++------------------- requirements/doc.txt | 8 +------- requirements/quality.in | 4 ++-- requirements/quality.txt | 13 ++++--------- requirements/test.txt | 14 ++------------ setup.cfg | 7 ------- 9 files changed, 30 insertions(+), 63 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 00c7db3..bb42e99 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,13 +25,6 @@ repos: - repo: local hooks: - - id: isort - name: isort-local - entry: isort - language: python - types: [python] - exclude: .+/(settings|migrations)/.+ - pass_filenames: true - id: eslint name: eslint-local entry: npm run lint diff --git a/.ruff.toml b/.ruff.toml index f5b3785..1811643 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -16,3 +16,18 @@ target-version = "py38" quote-style = "double" indent-style = "space" line-ending = "auto" + +[lint.isort.sections] +django = ["django"] +drf = ["rest_framework"] + +[lint.isort] +section-order = [ + "future", + "standard-library", + "django", + "drf", + "third-party", + "first-party", + "local-folder", +] diff --git a/manage.py b/manage.py index a22657d..9a352b8 100755 --- a/manage.py +++ b/manage.py @@ -1,5 +1,6 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" + import os import sys diff --git a/requirements/dev.txt b/requirements/dev.txt index bc89434..7c4b2cf 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile --output-file=requirements/dev.txt requirements/base.in requirements/dev.in requirements/quality.in @@ -17,8 +17,6 @@ astroid==2.15.8 # requirements-detector authlib==1.3.0 # via safety -backports-tarfile==1.1.1 - # via jaraco-context bandit==1.7.8 # via -r requirements/quality.in build==1.2.1 @@ -71,13 +69,9 @@ flake8-polyfill==1.0.2 idna==3.7 # via requests importlib-metadata==7.1.0 - # via - # keyring - # twine + # via twine isort==5.13.2 - # via - # -r requirements/quality.in - # pylint + # via pylint jaraco-classes==3.4.0 # via keyring jaraco-context==5.3.0 @@ -226,6 +220,8 @@ ruamel-yaml==0.18.6 # safety-schemas ruamel-yaml-clib==0.2.8 # via ruamel-yaml +ruff==0.4.5 + # via -r requirements/quality.in safety==3.2.0 # via -r requirements/quality.in safety-schemas==0.0.2 @@ -248,14 +244,6 @@ stevedore==5.2.0 # via bandit toml==0.10.2 # via requirements-detector -tomli==2.0.1 - # via - # build - # dparse - # pip-tools - # pylint - # pyproject-api - # tox tomlkit==0.12.5 # via pylint tox==3.28.0 @@ -270,8 +258,6 @@ typer==0.12.3 # via safety typing-extensions==4.11.0 # via - # asgiref - # astroid # pydantic # pydantic-core # safety diff --git a/requirements/doc.txt b/requirements/doc.txt index 855f38f..5da7b05 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile --output-file=requirements/doc.txt requirements/base.in requirements/doc.in @@ -73,11 +73,5 @@ sqlparse==0.5.0 # via django stevedore==5.2.0 # via doc8 -tomli==2.0.1 - # via - # doc8 - # sphinx -typing-extensions==4.11.0 - # via asgiref urllib3==2.2.1 # via requests diff --git a/requirements/quality.in b/requirements/quality.in index 150c6d6..eda2b8e 100644 --- a/requirements/quality.in +++ b/requirements/quality.in @@ -1,10 +1,10 @@ # Requirements for code quality checks -isort # to standardize order of imports astroid pylint # linter for python pylint_django # pylint plugin for django pylint_celery # pylint plugin for celery bandit safety -prospector \ No newline at end of file +ruff # Python linter and code formatter +prospector diff --git a/requirements/quality.txt b/requirements/quality.txt index 39d6658..1078f2f 100644 --- a/requirements/quality.txt +++ b/requirements/quality.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile --output-file=requirements/quality.txt requirements/quality.in @@ -44,9 +44,7 @@ flake8-polyfill==1.0.2 idna==3.7 # via requests isort==5.13.2 - # via - # -r requirements/quality.in - # pylint + # via pylint jinja2==3.1.4 # via safety lazy-object-proxy==1.10.0 @@ -142,6 +140,8 @@ ruamel-yaml==0.18.6 # safety-schemas ruamel-yaml-clib==0.2.8 # via ruamel-yaml +ruff==0.4.5 + # via -r requirements/quality.in safety==3.2.0 # via -r requirements/quality.in safety-schemas==0.0.2 @@ -158,17 +158,12 @@ stevedore==5.2.0 # via bandit toml==0.10.2 # via requirements-detector -tomli==2.0.1 - # via - # dparse - # pylint tomlkit==0.12.5 # via pylint typer==0.12.3 # via safety typing-extensions==4.11.0 # via - # astroid # pydantic # pydantic-core # safety diff --git a/requirements/test.txt b/requirements/test.txt index bb20b27..958af4a 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile --output-file=requirements/test.txt requirements/base.in requirements/test.in @@ -7,16 +7,12 @@ asgiref==3.8.1 # via django coverage[toml]==7.5.1 - # via - # coverage - # pytest-cov + # via pytest-cov # via # djangorestframework # model-bakery djangorestframework==3.15.1 # via -r requirements/base.in -exceptiongroup==1.2.1 - # via pytest iniconfig==2.0.0 # via pytest model-bakery==1.18.0 @@ -36,9 +32,3 @@ pytest-django==4.8.0 # via -r requirements/test.in sqlparse==0.5.0 # via django -tomli==2.0.1 - # via - # coverage - # pytest -typing-extensions==4.11.0 - # via asgiref diff --git a/setup.cfg b/setup.cfg index 5066936..5e40900 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,2 @@ -[isort] -line_length = 120 -known_django = django -known_djangoapp = model_utils -known_first_party = drf_rw_serializers -sections = FUTURE,STDLIB,THIRDPARTY,DJANGO,DJANGOAPP,FIRSTPARTY,LOCALFOLDER - [wheel] universal = 1 From dcf71226e42e6e580b96228707baf3f0e72851fa Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Thu, 23 May 2024 11:57:26 -0300 Subject: [PATCH 5/6] Remove no longer used .isort.cfg --- .isort.cfg | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 91029c2..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,12 +0,0 @@ -[settings] -line_length=100 -multi_line_output=3 -known_django=django -known_drf=rest_framework -sections=FUTURE,STDLIB,DJANGO,DRF,THIRDPARTY,FIRSTPARTY,LOCALFOLDER -lines_after_imports=2 -atomic=True -combine_star=True -force_grid_wrap=0 -include_trailing_comma=True -skip=/venv,/env,/node_modules,migrations From 492b7220653d0851f792bb3ac9932b835dc21ad6 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Thu, 23 May 2024 14:52:33 -0300 Subject: [PATCH 6/6] Add missing lint setting --- .ruff.toml | 3 +++ conftest.py | 1 - example_app/urls.py | 1 - example_app/views.py | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index 1811643..c2a1e69 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -17,6 +17,9 @@ quote-style = "double" indent-style = "space" line-ending = "auto" +[lint] +extend-select = ["I"] + [lint.isort.sections] django = ["django"] drf = ["rest_framework"] diff --git a/conftest.py b/conftest.py index 7f19ebd..a51b4e1 100644 --- a/conftest.py +++ b/conftest.py @@ -5,7 +5,6 @@ import pytest - # We manually designate which settings we will be using in an environment variable # This is similar to what occurs in the `manage.py` os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") diff --git a/example_app/urls.py b/example_app/urls.py index 2013e19..e6c6dde 100644 --- a/example_app/urls.py +++ b/example_app/urls.py @@ -19,7 +19,6 @@ OrderViewset, ) - urlpatterns = [ path( "orders-list-without-read-serializer/", diff --git a/example_app/views.py b/example_app/views.py index 85e527b..cafb189 100644 --- a/example_app/views.py +++ b/example_app/views.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -from drf_rw_serializers import generics, viewsets, mixins +from drf_rw_serializers import generics, mixins, viewsets + from .models import Order from .serializers import OrderCreateSerializer, OrderListSerializer