diff --git a/backend/auto_labeling/pipeline/execution.py b/backend/auto_labeling/pipeline/execution.py index 6c21115b..206e3ded 100644 --- a/backend/auto_labeling/pipeline/execution.py +++ b/backend/auto_labeling/pipeline/execution.py @@ -1,6 +1,11 @@ from typing import Type -from auto_labeling_pipeline.labels import SequenceLabels, Seq2seqLabels, ClassificationLabels, Labels +from auto_labeling_pipeline.labels import ( + ClassificationLabels, + Labels, + Seq2seqLabels, + SequenceLabels, +) from auto_labeling_pipeline.mappings import MappingTemplate from auto_labeling_pipeline.models import RequestModelFactory from auto_labeling_pipeline.pipeline import pipeline diff --git a/backend/auto_labeling/pipeline/labels.py b/backend/auto_labeling/pipeline/labels.py index ec30418f..ada786c0 100644 --- a/backend/auto_labeling/pipeline/labels.py +++ b/backend/auto_labeling/pipeline/labels.py @@ -4,10 +4,10 @@ from typing import List, Type from auto_labeling_pipeline.labels import Labels from django.contrib.auth.models import User -from projects.models import Project from examples.models import Example from label_types.models import CategoryType, LabelType, SpanType -from labels.models import Label, Category, Span, TextLabel +from labels.models import Category, Label, Span, TextLabel +from projects.models import Project class LabelCollection(abc.ABC): diff --git a/backend/auto_labeling/tests/test_views.py b/backend/auto_labeling/tests/test_views.py index b315b092..cedcccdf 100644 --- a/backend/auto_labeling/tests/test_views.py +++ b/backend/auto_labeling/tests/test_views.py @@ -7,13 +7,12 @@ from model_mommy import mommy from rest_framework import status from rest_framework.reverse import reverse - from api.tests.utils import CRUDMixin from auto_labeling.pipeline.labels import Categories, Spans, Texts from examples.tests.utils import make_doc from labels.models import Category, Span, TextLabel +from projects.models import DOCUMENT_CLASSIFICATION, SEQ2SEQ, SEQUENCE_LABELING from projects.tests.utils import prepare_project -from projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ data_dir = pathlib.Path(__file__).parent / "data" diff --git a/backend/auto_labeling/urls.py b/backend/auto_labeling/urls.py index 18418a45..e3504837 100644 --- a/backend/auto_labeling/urls.py +++ b/backend/auto_labeling/urls.py @@ -1,14 +1,14 @@ from django.urls import path from .views import ( - ConfigDetail, AutomatedLabeling, - LabelMapperTesting, - TemplateListAPI, - TemplateDetailAPI, + ConfigDetail, ConfigList, - RestAPIRequestTesting, LabelExtractorTesting, + LabelMapperTesting, + RestAPIRequestTesting, + TemplateDetailAPI, + TemplateListAPI, ) urlpatterns = [ diff --git a/backend/auto_labeling/views.py b/backend/auto_labeling/views.py index 6b116675..aa092611 100644 --- a/backend/auto_labeling/views.py +++ b/backend/auto_labeling/views.py @@ -15,12 +15,17 @@ from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from projects.models import Project -from projects.permissions import IsProjectMember, IsProjectAdmin -from .pipeline.execution import execute_pipeline, get_label_collection -from .exceptions import AWSTokenError, SampleDataException, TemplateMappingError, URLConnectionError +from .exceptions import ( + AWSTokenError, + SampleDataException, + TemplateMappingError, + URLConnectionError, +) from .models import AutoLabelingConfig +from .pipeline.execution import execute_pipeline, get_label_collection from .serializers import AutoLabelingConfigSerializer +from projects.models import Project +from projects.permissions import IsProjectAdmin, IsProjectMember class TemplateListAPI(APIView): diff --git a/backend/cli.py b/backend/cli.py index 9c91e621..cca13d75 100644 --- a/backend/cli.py +++ b/backend/cli.py @@ -48,6 +48,7 @@ def run_on_nix(args): def run_on_windows(args): from waitress import serve + from config.wsgi import application serve(application, port=args.port) diff --git a/backend/data_export/celery_tasks.py b/backend/data_export/celery_tasks.py index b81c10e4..167bf93b 100644 --- a/backend/data_export/celery_tasks.py +++ b/backend/data_export/celery_tasks.py @@ -3,9 +3,9 @@ from celery.utils.log import get_task_logger from django.conf import settings from django.shortcuts import get_object_or_404 -from projects.models import Project from .pipeline.factories import create_repository, create_writer from .pipeline.services import ExportApplicationService +from projects.models import Project logger = get_task_logger(__name__) diff --git a/backend/data_export/pipeline/catalog.py b/backend/data_export/pipeline/catalog.py index 0a5b1adc..58751145 100644 --- a/backend/data_export/pipeline/catalog.py +++ b/backend/data_export/pipeline/catalog.py @@ -4,15 +4,15 @@ from typing import Dict, List, Type from pydantic import BaseModel from typing_extensions import Literal +from . import examples from projects.models import ( DOCUMENT_CLASSIFICATION, - SEQUENCE_LABELING, - SEQ2SEQ, - SPEECH2TEXT, IMAGE_CLASSIFICATION, INTENT_DETECTION_AND_SLOT_FILLING, + SEQ2SEQ, + SEQUENCE_LABELING, + SPEECH2TEXT, ) -from . import examples class Format: diff --git a/backend/data_export/pipeline/factories.py b/backend/data_export/pipeline/factories.py index fa963ab7..9c930bca 100644 --- a/backend/data_export/pipeline/factories.py +++ b/backend/data_export/pipeline/factories.py @@ -1,14 +1,14 @@ from typing import Type +from . import catalog, repositories, writers from projects.models import ( DOCUMENT_CLASSIFICATION, - SEQUENCE_LABELING, - SEQ2SEQ, - SPEECH2TEXT, IMAGE_CLASSIFICATION, INTENT_DETECTION_AND_SLOT_FILLING, + SEQ2SEQ, + SEQUENCE_LABELING, + SPEECH2TEXT, ) -from . import catalog, repositories, writers def create_repository(project): diff --git a/backend/data_export/pipeline/repositories.py b/backend/data_export/pipeline/repositories.py index d5c924bd..10174061 100644 --- a/backend/data_export/pipeline/repositories.py +++ b/backend/data_export/pipeline/repositories.py @@ -3,9 +3,9 @@ import itertools from collections import defaultdict from typing import Dict, Iterator, List, Tuple, Union -from projects.models import Project -from examples.models import Example from .data import Record +from examples.models import Example +from projects.models import Project SpanType = Tuple[int, int, str] diff --git a/backend/data_export/tests/test_repositories.py b/backend/data_export/tests/test_repositories.py index 1b0b9f60..fa32b7ec 100644 --- a/backend/data_export/tests/test_repositories.py +++ b/backend/data_export/tests/test_repositories.py @@ -2,9 +2,9 @@ import unittest from model_mommy import mommy +from ..pipeline.repositories import IntentDetectionSlotFillingRepository from projects.models import INTENT_DETECTION_AND_SLOT_FILLING from projects.tests.utils import prepare_project -from ..pipeline.repositories import IntentDetectionSlotFillingRepository class TestCSVWriter(unittest.TestCase): diff --git a/backend/data_export/views.py b/backend/data_export/views.py index 2e19fe65..f19e0c07 100644 --- a/backend/data_export/views.py +++ b/backend/data_export/views.py @@ -6,10 +6,10 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from projects.models import Project -from projects.permissions import IsProjectAdmin from .celery_tasks import export_dataset from .pipeline.catalog import Options +from projects.models import Project +from projects.permissions import IsProjectAdmin class DatasetCatalog(APIView): diff --git a/backend/data_import/celery_tasks.py b/backend/data_import/celery_tasks.py index b922ed23..2f00732f 100644 --- a/backend/data_import/celery_tasks.py +++ b/backend/data_import/celery_tasks.py @@ -3,10 +3,10 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.shortcuts import get_object_or_404 -from projects.models import Project -from .pipeline.factories import create_parser, create_builder, create_cleaner +from .pipeline.factories import create_builder, create_cleaner, create_parser from .pipeline.readers import Reader from .pipeline.writers import BulkWriter +from projects.models import Project @shared_task diff --git a/backend/data_import/pipeline/catalog.py b/backend/data_import/pipeline/catalog.py index 5f9c63e8..c44795a8 100644 --- a/backend/data_import/pipeline/catalog.py +++ b/backend/data_import/pipeline/catalog.py @@ -4,15 +4,15 @@ from typing import Dict, List, Type from pydantic import BaseModel from typing_extensions import Literal +from . import examples from projects.models import ( DOCUMENT_CLASSIFICATION, - SEQUENCE_LABELING, - SEQ2SEQ, - SPEECH2TEXT, IMAGE_CLASSIFICATION, INTENT_DETECTION_AND_SLOT_FILLING, + SEQ2SEQ, + SEQUENCE_LABELING, + SPEECH2TEXT, ) -from . import examples encodings = Literal[ "Auto", diff --git a/backend/data_import/pipeline/cleaners.py b/backend/data_import/pipeline/cleaners.py index 93b7e48a..b6d31d96 100644 --- a/backend/data_import/pipeline/cleaners.py +++ b/backend/data_import/pipeline/cleaners.py @@ -1,7 +1,7 @@ from typing import List -from projects.models import Project from .labels import Label, SpanLabel +from projects.models import Project class Cleaner: diff --git a/backend/data_import/pipeline/data.py b/backend/data_import/pipeline/data.py index 279006bb..03fd1325 100644 --- a/backend/data_import/pipeline/data.py +++ b/backend/data_import/pipeline/data.py @@ -4,8 +4,8 @@ from typing import Any, Dict from pydantic import BaseModel, validator -from projects.models import Project from examples.models import Example +from projects.models import Project class BaseData(BaseModel, abc.ABC): diff --git a/backend/data_import/pipeline/factories.py b/backend/data_import/pipeline/factories.py index f24e3288..ee02f54e 100644 --- a/backend/data_import/pipeline/factories.py +++ b/backend/data_import/pipeline/factories.py @@ -1,12 +1,12 @@ +from . import builders, catalog, cleaners, data, labels, parsers, readers from projects.models import ( DOCUMENT_CLASSIFICATION, - SEQUENCE_LABELING, - SEQ2SEQ, - SPEECH2TEXT, IMAGE_CLASSIFICATION, INTENT_DETECTION_AND_SLOT_FILLING, + SEQ2SEQ, + SEQUENCE_LABELING, + SPEECH2TEXT, ) -from . import builders, catalog, cleaners, data, labels, parsers, readers def get_data_class(project_type: str): diff --git a/backend/data_import/pipeline/labels.py b/backend/data_import/pipeline/labels.py index 84f6b395..f94a8438 100644 --- a/backend/data_import/pipeline/labels.py +++ b/backend/data_import/pipeline/labels.py @@ -3,9 +3,10 @@ from typing import Any, Dict, Optional from pydantic import BaseModel, validator +from label_types.models import CategoryType, LabelType, SpanType +from labels.models import Category, Span +from labels.models import TextLabel as TL from projects.models import Project -from label_types.models import LabelType, CategoryType, SpanType -from labels.models import Category, Span, TextLabel as TL class Label(BaseModel, abc.ABC): diff --git a/backend/data_import/pipeline/writers.py b/backend/data_import/pipeline/writers.py index c1ea0cc5..a75889ee 100644 --- a/backend/data_import/pipeline/writers.py +++ b/backend/data_import/pipeline/writers.py @@ -5,11 +5,11 @@ from typing import Any, Dict, List, Type from django.conf import settings -from projects.models import Project -from examples.models import Example -from label_types.models import CategoryType, LabelType, SpanType from .exceptions import FileParseException from .readers import BaseReader, Record +from examples.models import Example +from label_types.models import CategoryType, LabelType, SpanType +from projects.models import Project class Writer(abc.ABC): diff --git a/backend/data_import/tests/test_builder.py b/backend/data_import/tests/test_builder.py index b75c1b16..d29d0533 100644 --- a/backend/data_import/tests/test_builder.py +++ b/backend/data_import/tests/test_builder.py @@ -1,5 +1,5 @@ import unittest -from typing import Optional, List +from typing import List, Optional from data_import.pipeline import builders from data_import.pipeline.data import TextData diff --git a/backend/data_import/tests/test_tasks.py b/backend/data_import/tests/test_tasks.py index 0283f15a..3eba3cc8 100644 --- a/backend/data_import/tests/test_tasks.py +++ b/backend/data_import/tests/test_tasks.py @@ -3,16 +3,15 @@ import pathlib from django.test import TestCase from data_import.celery_tasks import import_dataset - from examples.models import Example from label_types.models import CategoryType, SpanType from labels.models import Category, Span from projects.models import ( DOCUMENT_CLASSIFICATION, - SEQUENCE_LABELING, - SEQ2SEQ, IMAGE_CLASSIFICATION, INTENT_DETECTION_AND_SLOT_FILLING, + SEQ2SEQ, + SEQUENCE_LABELING, ) from projects.tests.utils import prepare_project diff --git a/backend/data_import/urls.py b/backend/data_import/urls.py index 9bad338f..4ab5249f 100644 --- a/backend/data_import/urls.py +++ b/backend/data_import/urls.py @@ -1,6 +1,6 @@ from django.urls import include, path -from .views import DatasetImportAPI, DatasetCatalog +from .views import DatasetCatalog, DatasetImportAPI urlpatterns = [ path("fp/", include("django_drf_filepond.urls")), diff --git a/backend/data_import/views.py b/backend/data_import/views.py index 8954909c..d3652b50 100644 --- a/backend/data_import/views.py +++ b/backend/data_import/views.py @@ -8,10 +8,10 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from projects.models import Project -from projects.permissions import IsProjectAdmin from .celery_tasks import import_dataset from .pipeline.catalog import Options +from projects.models import Project +from projects.permissions import IsProjectAdmin class DatasetCatalog(APIView): diff --git a/backend/examples/admin.py b/backend/examples/admin.py index e4b3564d..f2b56600 100644 --- a/backend/examples/admin.py +++ b/backend/examples/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Example, Comment +from .models import Comment, Example class ExampleAdmin(admin.ModelAdmin): diff --git a/backend/examples/models.py b/backend/examples/models.py index 2eee8536..ea18ea25 100644 --- a/backend/examples/models.py +++ b/backend/examples/models.py @@ -3,8 +3,8 @@ import uuid from django.contrib.auth.models import User from django.db import models -from projects.models import Project from .managers import ExampleManager, ExampleStateManager +from projects.models import Project class Example(models.Model): diff --git a/backend/examples/serializers.py b/backend/examples/serializers.py index a0a6a891..3a50c08b 100644 --- a/backend/examples/serializers.py +++ b/backend/examples/serializers.py @@ -1,6 +1,6 @@ from rest_framework import serializers -from .models import Example, ExampleState, Comment +from .models import Comment, Example, ExampleState class CommentSerializer(serializers.ModelSerializer): diff --git a/backend/examples/tests/test_comment.py b/backend/examples/tests/test_comment.py index 55877337..958d7ca0 100644 --- a/backend/examples/tests/test_comment.py +++ b/backend/examples/tests/test_comment.py @@ -1,10 +1,10 @@ from rest_framework import status from rest_framework.reverse import reverse +from .utils import make_comment, make_doc from api.tests.utils import CRUDMixin from projects.tests.utils import prepare_project from users.tests.utils import make_user -from .utils import make_comment, make_doc class TestCommentListDocAPI(CRUDMixin): diff --git a/backend/examples/tests/test_document.py b/backend/examples/tests/test_document.py index 0570a570..ccb67f49 100644 --- a/backend/examples/tests/test_document.py +++ b/backend/examples/tests/test_document.py @@ -3,11 +3,11 @@ from django.utils.http import urlencode from rest_framework import status from rest_framework.reverse import reverse +from .utils import make_doc, make_example_state from api.tests.utils import CRUDMixin -from users.tests.utils import make_user from projects.models import DOCUMENT_CLASSIFICATION from projects.tests.utils import assign_user_to_role, prepare_project -from .utils import make_doc, make_example_state +from users.tests.utils import make_user class TestExampleListAPI(CRUDMixin): diff --git a/backend/examples/tests/test_example_state.py b/backend/examples/tests/test_example_state.py index 6da201bc..4c60f122 100644 --- a/backend/examples/tests/test_example_state.py +++ b/backend/examples/tests/test_example_state.py @@ -1,10 +1,10 @@ from rest_framework import status from rest_framework.reverse import reverse +from .utils import make_doc, make_example_state from api.tests.utils import CRUDMixin from projects.tests.utils import prepare_project from users.tests.utils import make_user -from .utils import make_doc, make_example_state class TestExampleStateList(CRUDMixin): diff --git a/backend/examples/tests/test_filters.py b/backend/examples/tests/test_filters.py index 0e057e72..2d0a6df0 100644 --- a/backend/examples/tests/test_filters.py +++ b/backend/examples/tests/test_filters.py @@ -2,10 +2,10 @@ from unittest.mock import MagicMock from django.test import TestCase -from examples.models import Example +from .utils import make_doc, make_example_state from examples.filters import ExampleFilter +from examples.models import Example from projects.tests.utils import prepare_project -from .utils import make_doc, make_example_state class TestFilterMixin(TestCase): diff --git a/backend/examples/tests/test_models.py b/backend/examples/tests/test_models.py index 043a9163..96844ed0 100644 --- a/backend/examples/tests/test_models.py +++ b/backend/examples/tests/test_models.py @@ -1,9 +1,9 @@ from django.test import TestCase from model_mommy import mommy -from projects.models import SEQUENCE_LABELING, IMAGE_CLASSIFICATION -from projects.tests.utils import prepare_project from examples.models import ExampleState +from projects.models import IMAGE_CLASSIFICATION, SEQUENCE_LABELING +from projects.tests.utils import prepare_project class TestExampleState(TestCase): diff --git a/backend/examples/urls.py b/backend/examples/urls.py index 2c528247..89d50561 100644 --- a/backend/examples/urls.py +++ b/backend/examples/urls.py @@ -1,10 +1,9 @@ from django.urls import path -from .views.example import ExampleList, ExampleDetail -from .views.comment import CommentList, CommentDetail +from .views.comment import CommentDetail, CommentList +from .views.example import ExampleDetail, ExampleList from .views.example_state import ExampleStateList - urlpatterns = [ path(route="examples", view=ExampleList.as_view(), name="example_list"), path(route="examples/", view=ExampleDetail.as_view(), name="example_detail"), diff --git a/backend/examples/views/comment.py b/backend/examples/views/comment.py index b0254a97..928f3890 100644 --- a/backend/examples/views/comment.py +++ b/backend/examples/views/comment.py @@ -3,10 +3,10 @@ from rest_framework import filters, generics, status from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from projects.permissions import IsProjectMember from examples.models import Comment from examples.permissions import IsOwnComment from examples.serializers import CommentSerializer +from projects.permissions import IsProjectMember class CommentList(generics.ListCreateAPIView): diff --git a/backend/examples/views/example.py b/backend/examples/views/example.py index 4a374d86..2e2af005 100644 --- a/backend/examples/views/example.py +++ b/backend/examples/views/example.py @@ -7,10 +7,10 @@ from rest_framework import filters, generics, status from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from projects.models import Project from examples.filters import ExampleFilter from examples.models import Example from examples.serializers import ExampleSerializer +from projects.models import Project from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly diff --git a/backend/examples/views/example_state.py b/backend/examples/views/example_state.py index eb182bfd..369ae220 100644 --- a/backend/examples/views/example_state.py +++ b/backend/examples/views/example_state.py @@ -2,9 +2,9 @@ from django.shortcuts import get_object_or_404 from rest_framework import generics from rest_framework.permissions import IsAuthenticated -from projects.models import Project from examples.models import Example, ExampleState from examples.serializers import ExampleStateSerializer +from projects.models import Project from projects.permissions import IsProjectMember diff --git a/backend/label_types/serializers.py b/backend/label_types/serializers.py index f52cfe12..a1a3bd12 100644 --- a/backend/label_types/serializers.py +++ b/backend/label_types/serializers.py @@ -1,7 +1,7 @@ from rest_framework import serializers from rest_framework.exceptions import ValidationError -from .models import LabelType, CategoryType, SpanType, RelationType +from .models import CategoryType, LabelType, RelationType, SpanType class LabelSerializer(serializers.ModelSerializer): diff --git a/backend/label_types/tests/test_views.py b/backend/label_types/tests/test_views.py index 56d1759e..0b46d12a 100644 --- a/backend/label_types/tests/test_views.py +++ b/backend/label_types/tests/test_views.py @@ -5,11 +5,11 @@ from rest_framework import status from rest_framework.reverse import reverse from rest_framework.test import APITestCase +from .utils import make_label from api.tests.utils import CRUDMixin from projects.models import DOCUMENT_CLASSIFICATION from projects.tests.utils import make_project, prepare_project from users.tests.utils import make_user -from .utils import make_label DATA_DIR = os.path.join(os.path.dirname(__file__), "data") diff --git a/backend/label_types/urls.py b/backend/label_types/urls.py index a1dbd966..4c60d9c8 100644 --- a/backend/label_types/urls.py +++ b/backend/label_types/urls.py @@ -1,9 +1,16 @@ from django.urls import path -from .views import CategoryTypeList, CategoryTypeDetail, CategoryTypeUploadAPI -from .views import SpanTypeList, SpanTypeDetail, SpanTypeUploadAPI -from .views import RelationTypeList, RelationTypeDetail, RelationTypeUploadAPI - +from .views import ( + CategoryTypeDetail, + CategoryTypeList, + CategoryTypeUploadAPI, + RelationTypeDetail, + RelationTypeList, + RelationTypeUploadAPI, + SpanTypeDetail, + SpanTypeList, + SpanTypeUploadAPI, +) urlpatterns = [ path(route="category-types", view=CategoryTypeList.as_view(), name="category_types"), diff --git a/backend/label_types/views.py b/backend/label_types/views.py index 02f8f81e..d4b94bc4 100644 --- a/backend/label_types/views.py +++ b/backend/label_types/views.py @@ -10,10 +10,15 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly -from .models import LabelType, CategoryType, SpanType, RelationType from .exceptions import LabelValidationError -from .serializers import CategoryTypeSerializer, LabelSerializer, RelationTypesSerializer, SpanTypeSerializer +from .models import CategoryType, LabelType, RelationType, SpanType +from .serializers import ( + CategoryTypeSerializer, + LabelSerializer, + RelationTypesSerializer, + SpanTypeSerializer, +) +from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly def camel_to_snake(name): diff --git a/backend/labels/managers.py b/backend/labels/managers.py index 530ec7c5..111d9c94 100644 --- a/backend/labels/managers.py +++ b/backend/labels/managers.py @@ -1,4 +1,4 @@ -from django.db.models import Manager, Count +from django.db.models import Count, Manager class LabelManager(Manager): diff --git a/backend/labels/models.py b/backend/labels/models.py index 4f4632b5..cc73bf9e 100644 --- a/backend/labels/models.py +++ b/backend/labels/models.py @@ -2,10 +2,10 @@ from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.db import models -from .managers import LabelManager, CategoryManager, SpanManager, TextLabelManager -from projects.models import Project +from .managers import CategoryManager, LabelManager, SpanManager, TextLabelManager from examples.models import Example -from label_types.models import CategoryType, SpanType, RelationType +from label_types.models import CategoryType, RelationType, SpanType +from projects.models import Project class Label(models.Model): diff --git a/backend/labels/serializers.py b/backend/labels/serializers.py index cef2ba35..a1e43647 100644 --- a/backend/labels/serializers.py +++ b/backend/labels/serializers.py @@ -1,8 +1,8 @@ from rest_framework import serializers +from .models import Category, Relation, Span, TextLabel from examples.models import Example from label_types.models import CategoryType, SpanType -from .models import Category, Span, TextLabel, Relation class CategorySerializer(serializers.ModelSerializer): diff --git a/backend/labels/tests/test_views.py b/backend/labels/tests/test_views.py index 79f3e51b..78ac2a38 100644 --- a/backend/labels/tests/test_views.py +++ b/backend/labels/tests/test_views.py @@ -1,14 +1,14 @@ from rest_framework import status from rest_framework.reverse import reverse +from .utils import make_annotation from api.tests.utils import CRUDMixin from examples.tests.utils import make_doc -from labels.models import Category, Span, TextLabel from label_types.tests.utils import make_label -from projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ +from labels.models import Category, Span, TextLabel +from projects.models import DOCUMENT_CLASSIFICATION, SEQ2SEQ, SEQUENCE_LABELING from projects.tests.utils import prepare_project from users.tests.utils import make_user -from .utils import make_annotation class TestLabelList: diff --git a/backend/labels/tests/utils.py b/backend/labels/tests/utils.py index f7b1dc56..00908a6d 100644 --- a/backend/labels/tests/utils.py +++ b/backend/labels/tests/utils.py @@ -1,6 +1,11 @@ from model_mommy import mommy -from projects.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ, SPEECH2TEXT +from projects.models import ( + DOCUMENT_CLASSIFICATION, + SEQ2SEQ, + SEQUENCE_LABELING, + SPEECH2TEXT, +) def make_annotation(task, doc, user, **kwargs): diff --git a/backend/labels/urls.py b/backend/labels/urls.py index 2b221117..29a6c31b 100644 --- a/backend/labels/urls.py +++ b/backend/labels/urls.py @@ -1,10 +1,15 @@ from django.urls import path -from .views import CategoryListAPI, CategoryDetailAPI -from .views import SpanListAPI, SpanDetailAPI -from .views import TextLabelListAPI, TextLabelDetailAPI -from .views import RelationList, RelationDetail - +from .views import ( + CategoryDetailAPI, + CategoryListAPI, + RelationDetail, + RelationList, + SpanDetailAPI, + SpanListAPI, + TextLabelDetailAPI, + TextLabelListAPI, +) urlpatterns = [ path(route="annotation_relations", view=RelationList.as_view(), name="relation_list"), diff --git a/backend/labels/views.py b/backend/labels/views.py index 3f75509f..f2c4cfc3 100644 --- a/backend/labels/views.py +++ b/backend/labels/views.py @@ -7,11 +7,16 @@ from rest_framework import generics, status from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response +from .permissions import CanEditLabel +from .serializers import ( + CategorySerializer, + RelationSerializer, + SpanSerializer, + TextLabelSerializer, +) +from labels.models import Category, Label, Relation, Span, TextLabel from projects.models import Project -from labels.models import Category, Label, Span, TextLabel, Relation from projects.permissions import IsProjectMember -from .permissions import CanEditLabel -from .serializers import CategorySerializer, SpanSerializer, TextLabelSerializer, RelationSerializer class BaseListAPI(generics.ListCreateAPIView): diff --git a/backend/metrics/urls.py b/backend/metrics/urls.py index a5618ce5..99b5e18d 100644 --- a/backend/metrics/urls.py +++ b/backend/metrics/urls.py @@ -1,6 +1,11 @@ from django.urls import path -from .views import ProgressAPI, MemberProgressAPI, CategoryTypeDistribution, SpanTypeDistribution +from .views import ( + CategoryTypeDistribution, + MemberProgressAPI, + ProgressAPI, + SpanTypeDistribution, +) urlpatterns = [ path(route="progress", view=ProgressAPI.as_view(), name="progress"), diff --git a/backend/metrics/views.py b/backend/metrics/views.py index 4ed1e121..ed1a0f25 100644 --- a/backend/metrics/views.py +++ b/backend/metrics/views.py @@ -6,8 +6,8 @@ from rest_framework.response import Response from rest_framework.views import APIView from examples.models import Example, ExampleState -from label_types.models import LabelType, CategoryType, SpanType -from labels.models import Label, Category, Span +from label_types.models import CategoryType, LabelType, SpanType +from labels.models import Category, Label, Span from projects.models import Member from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly diff --git a/backend/projects/admin.py b/backend/projects/admin.py index ad1d6372..395a0ddc 100644 --- a/backend/projects/admin.py +++ b/backend/projects/admin.py @@ -1,7 +1,13 @@ from django.contrib import admin -from .models import Member -from .models import Project, TextClassificationProject, SequenceLabelingProject, Seq2seqProject, Tag +from .models import ( + Member, + Project, + Seq2seqProject, + SequenceLabelingProject, + Tag, + TextClassificationProject, +) class MemberAdmin(admin.ModelAdmin): diff --git a/backend/projects/management/commands/create_member.py b/backend/projects/management/commands/create_member.py index b8c34798..c6f88706 100644 --- a/backend/projects/management/commands/create_member.py +++ b/backend/projects/management/commands/create_member.py @@ -1,9 +1,9 @@ -from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User - +from django.core.management.base import BaseCommand, CommandError from models import Project -from roles.models import Role + from ...models import Member +from roles.models import Role class Command(BaseCommand): diff --git a/backend/projects/permissions.py b/backend/projects/permissions.py index 4e655c33..aa669151 100644 --- a/backend/projects/permissions.py +++ b/backend/projects/permissions.py @@ -1,5 +1,5 @@ from django.conf import settings -from rest_framework.permissions import BasePermission, SAFE_METHODS +from rest_framework.permissions import SAFE_METHODS, BasePermission from .models import Member diff --git a/backend/projects/serializers.py b/backend/projects/serializers.py index fe3df7c4..74d8301c 100644 --- a/backend/projects/serializers.py +++ b/backend/projects/serializers.py @@ -2,16 +2,16 @@ from rest_framework import serializers from rest_polymorphic.serializers import PolymorphicSerializer from .models import ( - Tag, + ImageClassificationProject, + IntentDetectionAndSlotFillingProject, + Member, Project, - TextClassificationProject, - SequenceLabelingProject, Seq2seqProject, - IntentDetectionAndSlotFillingProject, + SequenceLabelingProject, Speech2textProject, - ImageClassificationProject, + Tag, + TextClassificationProject, ) -from .models import Member class MemberSerializer(serializers.ModelSerializer): diff --git a/backend/projects/tests/test_member.py b/backend/projects/tests/test_member.py index baca8848..5aa47f6b 100644 --- a/backend/projects/tests/test_member.py +++ b/backend/projects/tests/test_member.py @@ -1,9 +1,9 @@ from django.conf import settings -from django.test import TestCase from django.core.exceptions import ValidationError +from django.test import TestCase +from model_mommy import mommy from rest_framework import status from rest_framework.reverse import reverse -from model_mommy import mommy from api.tests.utils import CRUDMixin from projects.models import Member diff --git a/backend/projects/tests/utils.py b/backend/projects/tests/utils.py index dcde935d..ccd201c7 100644 --- a/backend/projects/tests/utils.py +++ b/backend/projects/tests/utils.py @@ -3,14 +3,15 @@ from typing import List from django.conf import settings from model_mommy import mommy -from projects.models import Role, Member from projects.models import ( DOCUMENT_CLASSIFICATION, - SEQUENCE_LABELING, - SEQ2SEQ, - SPEECH2TEXT, IMAGE_CLASSIFICATION, INTENT_DETECTION_AND_SLOT_FILLING, + SEQ2SEQ, + SEQUENCE_LABELING, + SPEECH2TEXT, + Member, + Role, ) from roles.tests.utils import create_default_roles from users.tests.utils import make_user diff --git a/backend/projects/urls.py b/backend/projects/urls.py index e54f417d..e514298e 100644 --- a/backend/projects/urls.py +++ b/backend/projects/urls.py @@ -1,9 +1,8 @@ from django.urls import path -from .views.member import MemberList, MemberDetail -from .views.tag import TagList, TagDetail -from .views.project import ProjectList, ProjectDetail - +from .views.member import MemberDetail, MemberList +from .views.project import ProjectDetail, ProjectList +from .views.tag import TagDetail, TagList urlpatterns = [ path(route="projects", view=ProjectList.as_view(), name="project_list"), diff --git a/backend/projects/views/member.py b/backend/projects/views/member.py index 23cb17e4..36c70279 100644 --- a/backend/projects/views/member.py +++ b/backend/projects/views/member.py @@ -4,10 +4,10 @@ from rest_framework import generics, status from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from projects.permissions import IsProjectAdmin -from projects.serializers import MemberSerializer from projects.exceptions import RoleAlreadyAssignedException, RoleConstraintException from projects.models import Member +from projects.permissions import IsProjectAdmin +from projects.serializers import MemberSerializer class MemberList(generics.ListCreateAPIView): diff --git a/backend/projects/views/project.py b/backend/projects/views/project.py index 77a8c7bb..27438852 100644 --- a/backend/projects/views/project.py +++ b/backend/projects/views/project.py @@ -4,9 +4,8 @@ from rest_framework import filters, generics, status from rest_framework.permissions import IsAdminUser, IsAuthenticated from rest_framework.response import Response -from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly - from projects.models import Project +from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly from projects.serializers import ProjectPolymorphicSerializer diff --git a/backend/projects/views/tag.py b/backend/projects/views/tag.py index dcabee3e..6a0d1b81 100644 --- a/backend/projects/views/tag.py +++ b/backend/projects/views/tag.py @@ -1,9 +1,8 @@ from rest_framework import generics from rest_framework.permissions import IsAuthenticated -from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly - from projects.models import Tag +from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly from projects.serializers import TagSerializer diff --git a/backend/pyproject.toml b/backend/pyproject.toml new file mode 100644 index 00000000..6e379b11 --- /dev/null +++ b/backend/pyproject.toml @@ -0,0 +1,33 @@ +[tool.isort] +profile = "black" +include_trailing_comma = true +multi_line_output = 3 +#src_paths = ["backend/*"] +known_first_party = [ + "api", + "auto_labeling", + "config", + "data_export", + "data_import", + "examples", + "label_types", + "labels", + "metrics", + "projects", + "roles", + "users" +] +known_local_folder = [ + "api", + "auto_labeling", + "config", + "data_export", + "data_import", + "examples", + "label_types", + "labels", + "metrics", + "projects", + "roles", + "users" +] diff --git a/backend/roles/tests/test_views.py b/backend/roles/tests/test_views.py index 542623c1..0d730fa2 100644 --- a/backend/roles/tests/test_views.py +++ b/backend/roles/tests/test_views.py @@ -1,9 +1,9 @@ from rest_framework import status from rest_framework.reverse import reverse +from .utils import create_default_roles from api.tests.utils import CRUDMixin from users.tests.utils import make_user -from .utils import create_default_roles class TestRoleAPI(CRUDMixin): diff --git a/backend/users/urls.py b/backend/users/urls.py index f612a8a1..cadbc1da 100644 --- a/backend/users/urls.py +++ b/backend/users/urls.py @@ -2,7 +2,6 @@ from django.urls import include, path from .views import Me, Users - urlpatterns = [ path(route="me", view=Me.as_view(), name="me"), path(route="users", view=Users.as_view(), name="user_list"), diff --git a/backend/users/views.py b/backend/users/views.py index 0f87a55e..c21ddc54 100644 --- a/backend/users/views.py +++ b/backend/users/views.py @@ -1,12 +1,12 @@ from django.contrib.auth.models import User from django_filters.rest_framework import DjangoFilterBackend -from rest_framework import generics, filters +from rest_framework import filters, generics from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from projects.permissions import IsProjectAdmin from .serializers import UserSerializer +from projects.permissions import IsProjectAdmin class Me(APIView): diff --git a/poetry.lock b/poetry.lock index e53f3c88..7b793f1d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1307,10 +1307,14 @@ python-versions = ">=3.7" [package.extras] brotli = ["brotli"] +[extras] +mssql = [] +postgresql = [] + [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "2266cf8a3e7663746a57da39b8b1d9904080018df8af20e38abac13b06135152" +content-hash = "ba374bd631f54e82e0eaaa41cd38d6b6e71f69d3e5202a5c46575667b12f2b10" [metadata.files] amqp = [ diff --git a/pyproject.toml b/pyproject.toml index b8adc052..5339e718 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ djangorestframework-xml = "^2.0.0" model-mommy = "^2.0.0" coverage = "^6.3.1" flake8 = "^4.0.1" -isort = "^5.10.1" +isort = {extras = ["pyproject"], version = "^5.10.1"} autopep8 = "^1.6.0" mypy = "^0.931" watchdog = "^2.1.6" @@ -90,11 +90,6 @@ line-length = 120 target-version = ['py37', 'py38'] include = '\.pyi?$' -[tool.isort] -profile = "black" -include_trailing_comma = true -multi_line_output = 3 - [tool.flake8] max-line-length = 120 max-complexity = 18