Skip to content

Commit

Permalink
Fix imports for DRF 3.10 (#408)
Browse files Browse the repository at this point in the history
Fixes #410
Fixes #411
  • Loading branch information
tfranzel authored and axnsan12 committed Jul 16, 2019
1 parent 1e380fe commit 1904b04
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion requirements/testproj.txt
Expand Up @@ -3,7 +3,9 @@ Pillow>=4.3.0
django-cors-headers>=2.1.0
django-filter>=1.1.0,<2.0; python_version == "2.7"
django-filter>=1.1.0; python_version >= "3.5"
djangorestframework-camel-case>=0.2.0
#djangorestframework-camel-case>=0.2.0
# tempory replacement of broken lib
-e git+https://github.com/tfranzel/djangorestframework-camel-case.git@bd556d38fa7382acadfe91d93d92d99c663248a9#egg=djangorestframework_camel_case
djangorestframework-recursive>=0.1.2
dj-database-url>=0.4.2
user_agents>=1.1.0
Expand Down
13 changes: 11 additions & 2 deletions src/drf_yasg/generators.py
Expand Up @@ -4,14 +4,23 @@
from collections import OrderedDict, defaultdict

import uritemplate
import rest_framework
from coreapi.compat import urlparse
from rest_framework import versioning
from rest_framework.compat import URLPattern, URLResolver, get_original_route
from rest_framework.schemas.generators import EndpointEnumerator as _EndpointEnumerator
from rest_framework.schemas.generators import SchemaGenerator, endpoint_ordering, get_pk_name
from rest_framework.schemas.inspectors import get_pk_description
from rest_framework.schemas.generators import endpoint_ordering, get_pk_name

from rest_framework.settings import api_settings

from packaging.version import Version
if Version(rest_framework.__version__) < Version('3.10'):
from rest_framework.schemas.generators import SchemaGenerator
from rest_framework.schemas.inspectors import get_pk_description
else:
from rest_framework.schemas import SchemaGenerator
from rest_framework.schemas.utils import get_pk_description

from . import openapi
from .app_settings import swagger_settings
from .errors import SwaggerGenerationError
Expand Down
7 changes: 6 additions & 1 deletion testproj/snippets/serializers.py
@@ -1,8 +1,13 @@
import rest_framework
from decimal import Decimal

from django.contrib.auth import get_user_model
from packaging.version import Version
if Version(rest_framework.__version__) < Version('3.10'):
from rest_framework.compat import MaxLengthValidator, MinValueValidator
else:
from django.core.validators import MaxLengthValidator, MinValueValidator
from rest_framework import serializers
from rest_framework.compat import MaxLengthValidator, MinValueValidator

from snippets.models import LANGUAGE_CHOICES, STYLE_CHOICES, Snippet, SnippetViewer

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Expand Up @@ -9,6 +9,7 @@ envlist =
py27-django111-drf{38,39},
py{35,36}-django{111,21,22}-drf{38,39},
py37-django{21,22}-drf{38,39},
py37-django{21,22}-drf310,
djmaster, lint, docs

[testenv:.package]
Expand All @@ -23,6 +24,7 @@ deps =

drf38: djangorestframework>=3.8,<3.9
drf39: djangorestframework>=3.9,<3.10
drf310: djangorestframework>=3.10

typing: typing>=3.6.6

Expand Down

1 comment on commit 1904b04

@dkliban
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch introduced a dependency on 'packaging'[0] without adding it to the requirements.

[0] https://pypi.org/project/packaging/

Please sign in to comment.