Skip to content

Commit

Permalink
fix tooling for new isort
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Jul 7, 2020
1 parent 9a49de8 commit 010982b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
10 changes: 6 additions & 4 deletions drf_spectacular/contrib/django_oauth_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ class DjangoOAuthToolkitScheme(OpenApiAuthenticationExtension):
name = 'oauth2'

def get_security_requirement(self, auto_schema):
from oauth2_provider.contrib.rest_framework import (
TokenHasScope, TokenMatchesOASRequirements, IsAuthenticatedOrTokenHasScope
)
# TODO generalize (will also be used in versioning)
from collections import namedtuple

from oauth2_provider.contrib.rest_framework import (
IsAuthenticatedOrTokenHasScope, TokenHasScope, TokenMatchesOASRequirements,
)
Request = namedtuple('Request', ['method'])

view = auto_schema.view
Expand All @@ -26,9 +27,10 @@ def get_security_requirement(self, auto_schema):
return {self.name: permission.get_scopes(request, view)}

def get_security_definition(self, auto_schema):
from drf_spectacular.settings import spectacular_settings
from oauth2_provider.settings import oauth2_settings

from drf_spectacular.settings import spectacular_settings

flows = {}
for flow_type in spectacular_settings.OAUTH2_FLOWS:
flows[flow_type] = {}
Expand Down
1 change: 1 addition & 0 deletions drf_spectacular/contrib/rest_framework_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SimpleJWTScheme(OpenApiAuthenticationExtension):

def get_security_definition(self, auto_schema):
from rest_framework_simplejwt.settings import api_settings

from drf_spectacular.plumbing import warn

if len(api_settings.AUTH_HEADER_TYPES) > 1:
Expand Down
2 changes: 1 addition & 1 deletion drf_spectacular/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_lib_doc_excludes():
# do not import on package level due to potential import recursion when loading
# extensions as recommended: USER's settings.py -> USER EXTENSIONS -> extensions.py
# -> plumbing.py -> DRF views -> DRF DefaultSchema -> openapi.py - plumbing.py -> Loop
from rest_framework import generics, viewsets, views
from rest_framework import generics, views, viewsets
return [
views.APIView,
*[getattr(serializers, c) for c in dir(serializers) if c.endswith('Serializer')],
Expand Down
2 changes: 1 addition & 1 deletion requirements/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pytest-cov>=2.8.1
flake8>=3.7.9
mypy>=0.770
djangorestframework-stubs>=1.1.0
isort>=4.3.21
isort>=5.0.4
4 changes: 2 additions & 2 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

MYPY_ARGS = ['--config-file=tox.ini', 'drf_spectacular']

ISORT_ARGS = ['--check', '-df']
ISORT_ARGS = ['--check', '--diff', '.']

sys.path.append(os.path.dirname(__file__))

Expand All @@ -43,7 +43,7 @@ def mypy_main(args):
def isort_main(args):
print('Running isort code linting')
ret = subprocess.call(['isort'] + args)
print('isort failed, run: isort -rc .' if ret else 'isort passed')
print('isort failed, run: isort --interactive .' if ret else 'isort passed')
return ret


Expand Down
3 changes: 2 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def assert_schema(schema, reference_file):
from drf_spectacular.renderers import OpenApiYamlRenderer, OpenApiJsonRenderer
from drf_spectacular.renderers import OpenApiJsonRenderer, OpenApiYamlRenderer

schema_yml = OpenApiYamlRenderer().render(schema, renderer_context={})
# render also a json and provoke serialization issues
Expand All @@ -22,6 +22,7 @@ def generate_schema(route, viewset=None, view=None, view_function=None):
from django.urls import path
from rest_framework import routers
from rest_framework.viewsets import ViewSetMixin

from drf_spectacular.generators import SchemaGenerator

patterns = []
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/test_oauth_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

try:
from oauth2_provider.contrib.rest_framework import (
IsAuthenticatedOrTokenHasScope, OAuth2Authentication,
TokenHasReadWriteScope, TokenHasResourceScope,
IsAuthenticatedOrTokenHasScope, OAuth2Authentication, TokenHasReadWriteScope,
TokenHasResourceScope,
)
except ImportError:
IsAuthenticatedOrTokenHasScope = None
Expand Down
1 change: 1 addition & 0 deletions tests/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

def test_serializer_name_reuse(warnings):
from rest_framework import routers

from drf_spectacular.generators import SchemaGenerator
router = routers.SimpleRouter()

Expand Down

0 comments on commit 010982b

Please sign in to comment.