Skip to content

Commit

Permalink
refactor: move API handlers folder structure (#4955)
Browse files Browse the repository at this point in the history
# Description

This PR include changes moving API handlers to follow this structure:
```
/api
  /handlers
    /v1
      records.py
      questions.py
      ...
```

The behavior has not been changed.

Refs #4868

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

(Please describe the tests that you ran to verify your changes. And
ideally, reference `tests`)

- [x] Test should be passing as before.

**Checklist**

- [ ] I added relevant documentation
- [ ] follows the style guidelines of this project
- [ ] I did a self-review of my code
- [ ] I made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK)
(see text above)
- [ ] I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
  • Loading branch information
jfcalvo authored Jun 7, 2024
1 parent bb1b41b commit 82b6811
Show file tree
Hide file tree
Showing 91 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion argilla-server/src/argilla_server/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from argilla_server import helpers
from argilla_server._version import __version__ as argilla_version
from argilla_server.apis.routes import api_v1
from argilla_server.api.routes import api_v1
from argilla_server.constants import DEFAULT_API_KEY, DEFAULT_PASSWORD, DEFAULT_USERNAME
from argilla_server.contexts import accounts
from argilla_server.database import get_async_db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

from fastapi import APIRouter

from argilla_server.apis.v1.handlers.datasets.datasets import router as datasets_router
from argilla_server.apis.v1.handlers.datasets.questions import router as questions_router
from argilla_server.apis.v1.handlers.datasets.records import router as records_router
from argilla_server.apis.v1.handlers.datasets.records_bulk import router as records_bulk_router
from argilla_server.api.handlers.v1.datasets.datasets import router as datasets_router
from argilla_server.api.handlers.v1.datasets.questions import router as questions_router
from argilla_server.api.handlers.v1.datasets.records import router as records_router
from argilla_server.api.handlers.v1.datasets.records_bulk import router as records_bulk_router

router = APIRouter(tags=["datasets"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@
from fastapi import FastAPI

from argilla_server._version import __version__ as argilla_version
from argilla_server.apis.errors.v1.exception_handlers import add_exception_handlers as add_exception_handlers_v1
from argilla_server.apis.v1.handlers import authentication as authentication_v1
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import authentication as authentication_v1
from argilla_server.api.handlers.v1 import (
datasets as datasets_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
fields as fields_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
info as info_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
metadata_properties as metadata_properties_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
oauth2 as oauth2_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
questions as questions_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
records as records_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
responses as responses_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
settings as settings_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
suggestions as suggestions_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
users as users_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
vectors_settings as vectors_settings_v1,
)
from argilla_server.apis.v1.handlers import (
from argilla_server.api.handlers.v1 import (
workspaces as workspaces_v1,
)
from argilla_server.errors import APIErrorHandler
from argilla_server.apis.errors.v1.exception_handlers import add_exception_handlers as add_exception_handlers_v1
from argilla_server.errors.base_errors import __ALL__
from argilla_server.errors.error_handler import APIErrorHandler


def create_api_v1():
Expand Down
1 change: 0 additions & 1 deletion argilla-server/src/argilla_server/api/schemas/v1/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from argilla_server.enums import FieldType
from argilla_server.pydantic_v1 import BaseModel, constr
from argilla_server.pydantic_v1 import Field as PydanticField
from typing_extensions import Annotated

FIELD_CREATE_NAME_REGEX = r"^(?=.*[a-z0-9])[a-z0-9_-]+$"
FIELD_CREATE_NAME_MIN_LENGTH = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from argilla_server.enums import MetadataPropertyType
from argilla_server.pydantic_v1 import BaseModel, Field, constr, root_validator, validator
from argilla_server.pydantic_v1.generics import GenericModel
from typing_extensions import Annotated

FLOAT_METADATA_METRICS_PRECISION = 5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

from argilla_server.api.schemas.v1.commons import UpdateSchema
from argilla_server.api.schemas.v1.fields import FieldName
from argilla_server.enums import OptionsOrder
from argilla_server.models import QuestionType
from argilla_server.enums import OptionsOrder, QuestionType
from argilla_server.pydantic_v1 import BaseModel, Field, conlist, constr, root_validator, validator
from argilla_server.settings import settings

Expand Down
4 changes: 2 additions & 2 deletions argilla-server/src/argilla_server/api/schemas/v1/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
# limitations under the License.

from datetime import datetime
from typing import Any, Dict, List, Literal, Optional, Union
from typing import Annotated, Any, Dict, List, Literal, Optional, Union
from uuid import UUID

import fastapi

from argilla_server.api.schemas.v1.commons import UpdateSchema
from argilla_server.api.schemas.v1.metadata_properties import MetadataPropertyName
from argilla_server.api.schemas.v1.responses import Response, ResponseFilterScope, UserResponseCreate
Expand All @@ -25,7 +26,6 @@
from argilla_server.pydantic_v1 import BaseModel, Field, StrictStr, root_validator, validator
from argilla_server.pydantic_v1.utils import GetterDict
from argilla_server.search_engine import TextQuery
from typing_extensions import Annotated

RECORDS_CREATE_MIN_ITEMS = 1
RECORDS_CREATE_MAX_ITEMS = 1000
Expand Down
11 changes: 3 additions & 8 deletions argilla-server/src/argilla_server/api/schemas/v1/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@
from typing import Annotated, Any, Dict, List, Literal, Optional, Union
from uuid import UUID

from argilla_server.api.schemas.v1.questions import QuestionName
from argilla_server.models import ResponseStatus
from argilla_server.pydantic_v1 import BaseModel, Field, StrictInt, StrictStr, root_validator
from fastapi import Body
from typing_extensions import Annotated

try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated
from argilla_server.api.schemas.v1.questions import QuestionName
from argilla_server.enums import ResponseStatus
from argilla_server.pydantic_v1 import BaseModel, Field, StrictInt, StrictStr, root_validator

RESPONSES_BULK_CREATE_MIN_ITEMS = 1
RESPONSES_BULK_CREATE_MAX_ITEMS = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SpanQuestionResponseValue,
TextAndLabelSelectionQuestionResponseValue,
)
from argilla_server.models import SuggestionType
from argilla_server.enums import SuggestionType
from argilla_server.pydantic_v1 import BaseModel, Field

AGENT_REGEX = r"^(?=.*[a-zA-Z0-9])[a-zA-Z0-9-_:\.\/\s]+$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from argilla_server.api.schemas.v1.commons import UpdateSchema
from argilla_server.errors.future import UnprocessableEntityError
from argilla_server.pydantic_v1 import BaseModel, Field, PositiveInt, constr
from typing_extensions import Annotated

VECTOR_SETTINGS_CREATE_NAME_REGEX = r"^(?=.*[a-z0-9])[a-z0-9_-]+$"
VECTOR_SETTINGS_CREATE_NAME_MIN_LENGTH = 1
Expand Down
1 change: 0 additions & 1 deletion argilla-server/src/argilla_server/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# limitations under the License.

from .base_errors import *
from .error_handler import *
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from uuid import UUID, uuid4

import pytest
from argilla_server.apis.v1.handlers.datasets.records import LIST_DATASET_RECORDS_LIMIT_LE
from argilla_server.api.handlers.v1.datasets.records import LIST_DATASET_RECORDS_LIMIT_LE
from argilla_server.constants import API_KEY_HEADER_NAME
from argilla_server.enums import RecordInclude, SortOrder
from argilla_server.search_engine import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
from uuid import UUID, uuid4

import pytest
from argilla_server.api.schemas.v1.datasets import (
DATASET_GUIDELINES_MAX_LENGTH,
DATASET_NAME_MAX_LENGTH,
)
from argilla_server.api.handlers.v1.datasets.records import LIST_DATASET_RECORDS_LIMIT_DEFAULT
from argilla_server.api.schemas.v1.datasets import DATASET_GUIDELINES_MAX_LENGTH, DATASET_NAME_MAX_LENGTH
from argilla_server.api.schemas.v1.fields import FIELD_CREATE_NAME_MAX_LENGTH, FIELD_CREATE_TITLE_MAX_LENGTH
from argilla_server.api.schemas.v1.metadata_properties import (
METADATA_PROPERTY_CREATE_NAME_MAX_LENGTH,
Expand All @@ -34,7 +32,6 @@
VECTOR_SETTINGS_CREATE_NAME_MAX_LENGTH,
VECTOR_SETTINGS_CREATE_TITLE_MAX_LENGTH,
)
from argilla_server.apis.v1.handlers.datasets.records import LIST_DATASET_RECORDS_LIMIT_DEFAULT
from argilla_server.constants import API_KEY_HEADER_NAME
from argilla_server.enums import (
DatasetStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from uuid import uuid4

import pytest
from argilla_server.apis.v1.handlers.datasets.records import LIST_DATASET_RECORDS_LIMIT_DEFAULT
from argilla_server.api.handlers.v1.datasets.records import LIST_DATASET_RECORDS_LIMIT_DEFAULT
from argilla_server.constants import API_KEY_HEADER_NAME
from argilla_server.enums import RecordInclude, RecordSortField, ResponseStatus, UserRole
from argilla_server.models import Dataset, Question, Record, Response, Suggestion, User, Workspace
Expand Down
13 changes: 13 additions & 0 deletions argilla-server/tests/unit/api/handlers/v1/workspaces/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2021-present, the Recognai S.L. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2 changes: 1 addition & 1 deletion argilla-server/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import pytest
import pytest_asyncio
from argilla_server import telemetry
from argilla_server.apis.routes import api_v1
from argilla_server.api.routes import api_v1
from argilla_server.constants import API_KEY_HEADER_NAME, DEFAULT_API_KEY
from argilla_server.database import get_async_db
from argilla_server.models import User, UserRole, Workspace
Expand Down
2 changes: 1 addition & 1 deletion argilla-server/tests/unit/errors/test_api_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

import pytest
from argilla_server.api.schemas.v1.datasets import Dataset
from argilla_server.errors import APIErrorHandler
from argilla_server.errors.base_errors import (
EntityAlreadyExistsError,
EntityNotFoundError,
GenericServerError,
ServerError,
)
from argilla_server.errors.error_handler import APIErrorHandler
from fastapi import Request

mock_request = Request(scope={"type": "http", "headers": {}})
Expand Down

0 comments on commit 82b6811

Please sign in to comment.