Skip to content

Commit

Permalink
LITE-25849 Add isort
Browse files Browse the repository at this point in the history
* Add isort library and settings
* Remove flake8-import-order
* Run isort
* Add isort run information to the README.md
* Fix build.yml
  • Loading branch information
Hairash committed Dec 16, 2022
1 parent 89320a6 commit 9c88d14
Show file tree
Hide file tree
Showing 35 changed files with 157 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Checkout project
uses: actions/checkout@v2
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ Development
===========

1. Python 3.6+
0. Install dependencies `requirements/dev.txt` and `requirements/extra.txt`
2. Install dependencies `requirements/dev.txt` and `requirements/extra.txt`
3. We use `isort` library to order and format our imports, and we check it using `flake8-isort` library (automatically on `flake8` run).
For convenience you may run `isort .` to order imports.

Testing
=======
Expand Down
1 change: 0 additions & 1 deletion dj_rql/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#

from django.db import models

from py_rql.constants import FilterLookups, FilterTypes as FT


Expand Down
4 changes: 2 additions & 2 deletions dj_rql/drf/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#
from threading import Lock

from dj_rql.drf._utils import get_query

from rest_framework.filters import BaseFilterBackend

from dj_rql.drf._utils import get_query


lock = Lock()

Expand Down
10 changes: 5 additions & 5 deletions dj_rql/drf/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

from collections import Counter

from dj_rql.constants import DjangoLookups as DJL, FilterTypes
from dj_rql.drf._utils import get_query
from dj_rql.drf.backend import RQLFilterBackend

from py_rql.constants import (
ComparisonOperators as CO,
RQL_ANY_SYMBOL,
RQL_FALSE,
RQL_LIMIT_PARAM,
RQL_NULL,
RQL_OFFSET_PARAM,
RQL_ORDERING_OPERATOR,
RQL_TRUE,
ComparisonOperators as CO,
SearchOperators as SO,
)
from py_rql.exceptions import RQLFilterParsingError

from dj_rql.constants import DjangoLookups as DJL, FilterTypes
from dj_rql.drf._utils import get_query
from dj_rql.drf.backend import RQLFilterBackend


class CompatibilityRQLFilterBackend(RQLFilterBackend):
"""
Expand Down
8 changes: 3 additions & 5 deletions dj_rql/drf/paginations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
# Copyright © 2022 Ingram Micro Inc. All rights reserved.
#

from dj_rql.drf._utils import get_query
from dj_rql.transformer import RQLLimitOffsetTransformer

from lark.exceptions import LarkError

from py_rql.exceptions import RQLFilterParsingError
from py_rql.parser import RQLParser

from rest_framework.pagination import LimitOffsetPagination, _positive_int
from rest_framework.response import Response

from dj_rql.drf._utils import get_query
from dj_rql.transformer import RQLLimitOffsetTransformer


class RQLLimitOffsetPagination(LimitOffsetPagination):
""" RQL limit offset pagination. """
Expand Down
31 changes: 18 additions & 13 deletions dj_rql/filter_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@
from datetime import datetime
from uuid import uuid4

from dj_rql._dataclasses import FilterArgs, OptimizationArgs
from dj_rql.constants import DjangoLookups, FilterTypes, SUPPORTED_FIELD_TYPES
from dj_rql.fields import SelectField
from dj_rql.openapi import RQLFilterClassSpecification
from dj_rql.qs import Annotation, NPR, NSR
from dj_rql.transformer import RQLToDjangoORMTransformer

from django.db.models import ForeignKey, ManyToManyField, Model, OneToOneField, OneToOneRel, Q
from django.db.models import (
ForeignKey,
ManyToManyField,
Model,
OneToOneField,
OneToOneRel,
Q,
)
from django.utils.dateparse import parse_date, parse_datetime
from django.utils.functional import cached_property

from lark.exceptions import LarkError

from py_rql.constants import (
ComparisonOperators,
FilterLookups,
ListOperators,
RESERVED_FILTER_NAMES,
RQL_ANY_SYMBOL,
RQL_EMPTY,
Expand All @@ -34,11 +29,21 @@
RQL_PLUS,
RQL_SEARCH_PARAM,
RQL_TRUE,
ComparisonOperators,
FilterLookups,
ListOperators,
SearchOperators,
)
from py_rql.exceptions import RQLFilterLookupError, RQLFilterParsingError, RQLFilterValueError
from py_rql.parser import RQLParser

from dj_rql._dataclasses import FilterArgs, OptimizationArgs
from dj_rql.constants import SUPPORTED_FIELD_TYPES, DjangoLookups, FilterTypes
from dj_rql.fields import SelectField
from dj_rql.openapi import RQLFilterClassSpecification
from dj_rql.qs import NPR, NSR, Annotation
from dj_rql.transformer import RQLToDjangoORMTransformer


iterable_types = (list, tuple)

Expand Down
4 changes: 2 additions & 2 deletions dj_rql/management/commands/generate_rql_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import json
import re

from dj_rql.filter_cls import NestedAutoRQLFilterClass

from django.core.management import BaseCommand
from django.db.models import ForeignKey, OneToOneField, OneToOneRel
from django.utils.module_loading import import_string

from dj_rql.filter_cls import NestedAutoRQLFilterClass


TEMPLATE = """from {model_package} import {model_name}
Expand Down
9 changes: 6 additions & 3 deletions dj_rql/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
from copy import copy
from numbers import Number

from dj_rql.constants import FilterTypes

from py_rql.constants import (
FilterLookups, RQL_NULL, RQL_ORDERING_OPERATOR, RQL_SEARCH_PARAM,
RQL_NULL,
RQL_ORDERING_OPERATOR,
RQL_SEARCH_PARAM,
FilterLookups,
)

from dj_rql.constants import FilterTypes


class RQLFilterDescriptionTemplate:
BASE_TEMPLATE = '{description}\n\n**lookups:** {lookups}'
Expand Down
9 changes: 4 additions & 5 deletions dj_rql/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
# Copyright © 2022 Ingram Micro Inc. All rights reserved.
#

from dj_rql._dataclasses import FilterArgs

from lark import Tree

from py_rql.constants import (
RQL_LIMIT_PARAM,
RQL_OFFSET_PARAM,
ComparisonOperators,
ListOperators,
LogicalOperators,
RQL_LIMIT_PARAM,
RQL_OFFSET_PARAM,
)
from py_rql.transformer import BaseRQLTransformer

from dj_rql._dataclasses import FilterArgs


class RQLToDjangoORMTransformer(BaseRQLTransformer):
""" Parsed RQL AST tree transformer to Django ORM Query.
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from datetime import datetime

import django

from setuptools_scm import get_version


Expand Down
5 changes: 3 additions & 2 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flake8-commas==2.0.0
flake8-comprehensions==3.7.0
flake8-debugger==4.0.0
flake8-eradicate==1.1.0
flake8-import-order==0.18.1
flake8-isort==5.0.3
flake8-string-format==0.3.0
importlib-metadata>=4.0.0,<5.0.0
importlib-metadata>=4.0.0,<5.0.0
isort==5.10.1
12 changes: 12 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ addopts = --show-capture=no --create-db --nomigrations --junitxml=tests/reports/
filterwarnings =
ignore::UserWarning
DJANGO_SETTINGS_MODULE = tests.dj_rf.settings

[isort]
src_paths = *
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
group_by_package = True
multi_line_output = 3
force_grid_wrap = 4
combine_as_imports = True
use_parentheses = True
include_trailing_comma = True
line_length = 100
lines_after_imports = 2
7 changes: 6 additions & 1 deletion tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#

from py_rql.constants import (
ComparisonOperators, ListOperators, LogicalOperators, RQL_EMPTY, RQL_NULL, SearchOperators,
RQL_EMPTY,
RQL_NULL,
ComparisonOperators,
ListOperators,
LogicalOperators,
SearchOperators,
)


Expand Down
19 changes: 13 additions & 6 deletions tests/dj_rf/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
from copy import deepcopy

from cachetools import LFUCache, LRUCache
from django.db.models import (
AutoField,
CharField,
F,
IntegerField,
)
from py_rql.constants import RQL_NULL, FilterLookups

from dj_rql.fields import SelectField
from dj_rql.filter_cls import RQLFilterClass
from dj_rql.qs import AN, NSR, PR, SR

from django.db.models import AutoField, CharField, F, IntegerField

from py_rql.constants import FilterLookups, RQL_NULL

from dj_rql.qs import (
AN,
NSR,
PR,
SR,
)
from tests.dj_rf.models import Book


Expand Down
2 changes: 0 additions & 2 deletions tests/dj_rf/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from uuid import uuid4

from django.db import models

from django_fsm import FSMField

from model_utils import Choices


Expand Down
10 changes: 7 additions & 3 deletions tests/dj_rf/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
# Copyright © 2022 Ingram Micro Inc. All rights reserved.
#

from dj_rql.drf.serializers import RQLMixin

from rest_framework import serializers

from tests.dj_rf.models import Author, Book, Page, Publisher
from dj_rql.drf.serializers import RQLMixin
from tests.dj_rf.models import (
Author,
Book,
Page,
Publisher,
)


class PublisherReferenceSerializer(RQLMixin, serializers.ModelSerializer):
Expand Down
1 change: 1 addition & 0 deletions tests/dj_rf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = '6^1@%4#qtc+bookwp4w5k-+nbo+clm!skzdhnyl@rf&06b5tl6'
Expand Down
7 changes: 5 additions & 2 deletions tests/dj_rf/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

from django.conf.urls import include
from django.urls import re_path

from rest_framework.routers import SimpleRouter

from tests.dj_rf.view import (
AutoViewSet, DRFViewSet, DjangoFiltersViewSet, DynamicFilterClsViewSet, NoFilterClsViewSet,
AutoViewSet,
DjangoFiltersViewSet,
DRFViewSet,
DynamicFilterClsViewSet,
NoFilterClsViewSet,
SelectViewSet,
)

Expand Down
14 changes: 7 additions & 7 deletions tests/dj_rf/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# Copyright © 2022 Ingram Micro Inc. All rights reserved.
#

from dj_rql.drf.backend import RQLFilterBackend
from dj_rql.drf.compat import DjangoFiltersRQLFilterBackend
from dj_rql.drf.paginations import RQLContentRangeLimitOffsetPagination
from dj_rql.filter_cls import AutoRQLFilterClass

from django.db.models import CharField, IntegerField, Value

from rest_framework import mixins
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from dj_rql.drf.backend import RQLFilterBackend
from dj_rql.drf.compat import DjangoFiltersRQLFilterBackend
from dj_rql.drf.paginations import RQLContentRangeLimitOffsetPagination
from dj_rql.filter_cls import AutoRQLFilterClass
from tests.dj_rf.filters import (
BooksFilterClass, SelectBooksFilterClass, SelectDetailedBooksFilterClass,
BooksFilterClass,
SelectBooksFilterClass,
SelectDetailedBooksFilterClass,
)
from tests.dj_rf.models import Book
from tests.dj_rf.serializers import BookSerializer, SelectBookSerializer
Expand Down
3 changes: 1 addition & 2 deletions tests/test_commands/test_generate_rql_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import os

from django.core.management import call_command

import pytest
from django.core.management import call_command

from tests.dj_rf.models import AutoMain, Publisher

Expand Down
5 changes: 2 additions & 3 deletions tests/test_drf/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# Copyright © 2021 Ingram Micro Inc. All rights reserved.
#

from dj_rql.drf.backend import RQLFilterBackend, _FilterClassCache

import pytest

from rest_framework.test import APIClient

from dj_rql.drf.backend import RQLFilterBackend, _FilterClassCache


@pytest.fixture
def api_client():
Expand Down
Loading

0 comments on commit 9c88d14

Please sign in to comment.