Repository: encode/django-rest-framework

Issue:
import coreapi failure since version 3.8.0
## Checklist
- [x] I have verified that that issue exists against the `master` branch of Django REST framework.
- [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [x] This is not a usage question. (Those should be directed to the [discussion group](https://groups.google.com/forum/#!forum/django-rest-framework) instead.)
- [x] This cannot be dealt with as a third party library. (We prefer new functionality to be [in the form of third party libraries](http://www.django-rest-framework.org/topics/third-party-resources/#about-third-party-packages) where possible.)
- [x] I have reduced the issue to the simplest possible case.
- [ ] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

## Steps to reproduce
Install django 2.0 with latest version of django-rest-framework via pip, and activate in settings.py
Try to open a shell and/or do:
`from rest_framework.authtoken import views`

## Expected behavior
Should just load the views module.

## Actual behavior
`ModuleNotFoundError: No module named 'coreapi'`

## Suggested fix
It seems like the `coreapi` module should no longer be optional, but should be a dependency that installs with a pip install -
https://github.com/encode/django-rest-framework/blob/2709de1310f35dda97fad28ccf555878f5646b17/requirements/requirements-optionals.txt#L7


Discussion:
i have the same issue
Regression in 0d5a3a00b0465a27ecfa6947478cbd57ac2432f2. Ref #5676 
Installing `coreapi` will work, but making it non-optional was not intended. 
The import here should be from `compat`

https://github.com/encode/django-rest-framework/blob/bc353452f4a69304faf84e04f4cfaf827655f1f3/rest_framework/authtoken/views.py#L1-L39

And the `schema` declaration (ln17) needs to be only `if coreapi is not None:`

I'd take a PR on this very happily! 🙂
I'll supply a PR soon (in the next hour, hopefully).

Resolving patch:
diff --git a/rest_framework/authtoken/views.py b/rest_framework/authtoken/views.py
--- a/rest_framework/authtoken/views.py
+++ b/rest_framework/authtoken/views.py
@@ -1,8 +1,7 @@
-import coreapi
-import coreschema
 from rest_framework import parsers, renderers
 from rest_framework.authtoken.models import Token
 from rest_framework.authtoken.serializers import AuthTokenSerializer
+from rest_framework.compat import coreapi, coreschema
 from rest_framework.response import Response
 from rest_framework.schemas import ManualSchema
 from rest_framework.views import APIView
@@ -14,29 +13,30 @@ class ObtainAuthToken(APIView):
     parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
     renderer_classes = (renderers.JSONRenderer,)
     serializer_class = AuthTokenSerializer
-    schema = ManualSchema(
-        fields=[
-            coreapi.Field(
-                name="username",
-                required=True,
-                location='form',
-                schema=coreschema.String(
-                    title="Username",
-                    description="Valid username for authentication",
+    if coreapi is not None and coreschema is not None:
+        schema = ManualSchema(
+            fields=[
+                coreapi.Field(
+                    name="username",
+                    required=True,
+                    location='form',
+                    schema=coreschema.String(
+                        title="Username",
+                        description="Valid username for authentication",
+                    ),
                 ),
-            ),
-            coreapi.Field(
-                name="password",
-                required=True,
-                location='form',
-                schema=coreschema.String(
-                    title="Password",
-                    description="Valid password for authentication",
+                coreapi.Field(
+                    name="password",
+                    required=True,
+                    location='form',
+                    schema=coreschema.String(
+                        title="Password",
+                        description="Valid password for authentication",
+                    ),
                 ),
-            ),
-        ],
-        encoding="application/json",
-    )
+            ],
+            encoding="application/json",
+        )
 
     def post(self, request, *args, **kwargs):
         serializer = self.serializer_class(data=request.data,


Test patch:
diff --git a/tests/test_renderers.py b/tests/test_renderers.py
--- a/tests/test_renderers.py
+++ b/tests/test_renderers.py
@@ -14,8 +14,8 @@
 from django.utils.safestring import SafeText
 from django.utils.translation import ugettext_lazy as _
 
-import coreapi
 from rest_framework import permissions, serializers, status
+from rest_framework.compat import coreapi
 from rest_framework.renderers import (
     AdminRenderer, BaseRenderer, BrowsableAPIRenderer, DocumentationRenderer,
     HTMLFormRenderer, JSONRenderer, SchemaJSRenderer, StaticHTMLRenderer