Skip to content

Commit

Permalink
chore: update pydantic dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Panos Vagenas <[email protected]>
  • Loading branch information
vagenas committed Dec 1, 2023
1 parent 67f053c commit e48a769
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 97 deletions.
2 changes: 1 addition & 1 deletion deepsearch/chemistry/queries/molecules.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from typing import List, Union

from pydantic import BaseModel
from pydantic.v1 import BaseModel

from deepsearch.cps.client.queries import Query

Expand Down
2 changes: 1 addition & 1 deletion deepsearch/core/cli/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def add_profile(
profile_settings = ProfileSettings(
host=host,
username=username,
api_key=api_key,
api_key=api_key, # type: ignore[arg-type]
verify_ssl=verify_ssl,
)

Expand Down
2 changes: 1 addition & 1 deletion deepsearch/core/client/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union

from pydantic import BaseModel
from pydantic.v1 import BaseModel


class DeepSearchBearerTokenAuth(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions deepsearch/core/client/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Dict, Optional, Union

from pydantic import BaseSettings, SecretStr
from pydantic.v1 import BaseSettings, SecretStr


class DumpableSettings(BaseSettings):
Expand Down Expand Up @@ -47,8 +47,8 @@ def from_cli_prompt(cls) -> ProfileSettings:
return cls(
host=input("Host: "),
username=input("Username: "),
api_key=getpass("API key: "),
verify_ssl=input("SSL verification [y/n]: "),
api_key=getpass("API key: "), # type: ignore[arg-type]
verify_ssl=input("SSL verification [y/n]: "), # type: ignore[arg-type]
)


Expand Down
6 changes: 3 additions & 3 deletions deepsearch/core/client/settings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Dict, List, Optional

import platformdirs
from pydantic import ValidationError
from pydantic.v1 import ValidationError

from deepsearch.core.cli.profile_utils import (
MSG_AMBIGUOUS_SUCCESSOR,
Expand Down Expand Up @@ -116,7 +116,7 @@ def _migrate_legacy_config(self) -> None:
new_cfg = ProfileSettings(
host=legacy_cfg.host,
username=legacy_cfg.auth.username,
api_key=legacy_cfg.auth.api_key,
api_key=legacy_cfg.auth.api_key, # type: ignore[arg-type]
verify_ssl=legacy_cfg.verify_ssl,
)
self.save_settings(
Expand Down Expand Up @@ -144,7 +144,7 @@ def get_profile_settings(
prfl_name = profile_name or self.get_active_profile()
if prfl_name is None:
try: # try to instantiate from environment alone
return ProfileSettings()
return ProfileSettings() # type: ignore[call-arg]
except ValidationError:
if len(self._profile_cache) == 0:
raise RuntimeError(MSG_NO_PROFILES_DEFINED)
Expand Down
4 changes: 2 additions & 2 deletions deepsearch/cps/client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Optional

import requests
from pydantic import ValidationError
from pydantic.v1 import ValidationError

import deepsearch.cps.apis.user
from deepsearch.core.client import (
Expand Down Expand Up @@ -165,7 +165,7 @@ def from_env(cls, profile_name: Optional[str] = None) -> CpsApi:
CpsApi: the created API object
"""
try:
settings = ProfileSettings()
settings = ProfileSettings() # type: ignore[call-arg]
except ValidationError:
settings_mgr = SettingsManager()
settings = settings_mgr.get_profile_settings(profile_name=profile_name)
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/cps/client/components/data_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from urllib.parse import urlparse

import requests
from pydantic import BaseModel
from pydantic.v1 import BaseModel

from deepsearch.cps.apis import public as sw_client
from deepsearch.cps.apis.public.models.attachment_upload_data import (
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/cps/client/components/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
from typing import TYPE_CHECKING, Any, Dict, List, Union

from pydantic import BaseModel
from pydantic.v1 import BaseModel

from deepsearch.cps.apis import public as sw_client
from deepsearch.cps.client.components.data_indices import (
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/cps/client/components/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import Enum
from typing import TYPE_CHECKING, List, Optional, Union

from pydantic import BaseModel
from pydantic.v1 import BaseModel

import deepsearch.cps.apis.user
from deepsearch.cps.apis.user.models.token_response import TokenResponse
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/cps/client/components/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, Union

import requests
from pydantic import BaseModel
from pydantic.v1 import BaseModel

from deepsearch.cps.apis import public as sw_client
from deepsearch.cps.apis.public.models.temporary_upload_file_result import (
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/documents/core/lookup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List

from pydantic import BaseModel
from pydantic.v1 import BaseModel


def _resolve_item(item, doc):
Expand Down
36 changes: 18 additions & 18 deletions deepsearch/documents/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from textwrap import dedent
from typing import ClassVar, Dict, List, Literal, Optional, Set, Union, get_args

from pydantic import BaseModel, Field, ValidationError, conlist, parse_obj_as
from pydantic.v1 import BaseModel, Field, ValidationError, conlist, parse_obj_as

from deepsearch import CpsApi
from deepsearch.core.util.ccs_utils import get_ccs_project_key
Expand Down Expand Up @@ -31,13 +31,13 @@ class S3Coordinates(BaseModel):
"",
description=dedent(
"""
Control the infix of the object keys that are saved on the document's `_s3_data`, after `key_prefix`,
Control the infix of the object keys that are saved on the document's `_s3_data`, after `key_prefix`,
and before `PDFDocuments/{document_hash}.pdf` or `PDFPages/{page_hash}.pdf`.
By default, the infix is empty.
For using the name of the index in the coordinates, you can use `key_infix_format = "{index_name}"`.
For example, if:
For example, if:
```
key_prefix = "my_prefix/"
Expand Down Expand Up @@ -577,8 +577,6 @@ class ConversionSettings(BaseModel):

@classmethod
def from_project(cls, api: CpsApi, proj_key: str) -> "ConversionSettings":
conv_settings = cls()

proj_key, _ = get_ccs_project_key(api, proj_key)

request_conv_settings = api.client.session.get(
Expand All @@ -587,34 +585,36 @@ def from_project(cls, api: CpsApi, proj_key: str) -> "ConversionSettings":
request_conv_settings.raise_for_status()
settings_dict = request_conv_settings.json()

conv_settings.pipeline = ConversionPipelineSettings.from_ccs_spec(
pipeline = ConversionPipelineSettings.from_ccs_spec(
settings_dict.get("model_pipeline")
)
conv_settings.ocr = OCRSettings.from_ccs_spec(settings_dict.get("ocr"))
conv_settings.metadata = ConversionMetadata.from_ccs_spec(
settings_dict.get("metadata")
ocr = OCRSettings.from_ccs_spec(settings_dict.get("ocr"))
metadata = ConversionMetadata.from_ccs_spec(settings_dict.get("metadata"))
return cls(
pipeline=pipeline,
ocr=ocr,
metadata=metadata,
)
return conv_settings

@classmethod
def from_defaults(cls, api: CpsApi) -> "ConversionSettings":
conv_settings = cls()

request_conv_settings = api.client.session.get(
url=URLNavigator(api).url_conversion_defaults()
)
request_conv_settings.raise_for_status()
settings_dict = request_conv_settings.json()

conv_settings.pipeline = ConversionPipelineSettings.from_ccs_spec(
pipeline = ConversionPipelineSettings.from_ccs_spec(
settings_dict.get("model_pipeline")
)
conv_settings.ocr = OCRSettings.from_ccs_spec(settings_dict.get("ocr"))
conv_settings.metadata = ConversionMetadata.from_ccs_spec(
settings_dict.get("metadata")
)
ocr = OCRSettings.from_ccs_spec(settings_dict.get("ocr"))
metadata = ConversionMetadata.from_ccs_spec(settings_dict.get("metadata"))

return conv_settings
return cls(
pipeline=pipeline,
ocr=ocr,
metadata=metadata,
)

def to_ccs_spec(self):
obj = {}
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/documents/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any, Dict, Iterator, List

import requests
from pydantic import BaseModel
from pydantic.v1 import BaseModel
from tqdm import tqdm

from deepsearch.cps.client.api import CpsApi
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/model/base/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from typing import Any, Dict, Optional

from pydantic import BaseModel, Extra, Field, PositiveFloat
from pydantic.v1 import BaseModel, Extra, Field, PositiveFloat


class StrictModel(BaseModel, extra=Extra.forbid):
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/model/examples/dummy_nlp_annotator/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self) -> None:
kind=Kind.NLPModel,
name="DummyNLPAnnotator",
version="0.1.0",
supported_types=["text"],
supported_types=["text"], # type: ignore[list-item]
labels=self._generate_labels(),
)

Expand Down
6 changes: 3 additions & 3 deletions deepsearch/model/kinds/nlp/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ def __init__(self, model: BaseNLPModel):
def get_info(self) -> NLPInfoOutput:
cfg = self._model.get_nlp_config()
metadata = NLPModelMetadata(
supported_object_types=cfg.supported_types,
supported_object_types=cfg.supported_types, # type: ignore[arg-type]
**self._get_metadata().dict(), # passing parent metadata dict as kwargs
)
spec = NLPInfoOutputDefinitionsSpec(
definition=cfg.labels,
definition=cfg.labels.dict(),
metadata=metadata,
)
definitions = NLPInfoOutputDefinitions(
apiVersion=self._get_api_version(),
kind=self.get_kind(),
kind=self.get_kind(), # type: ignore[arg-type]
spec=spec,
)
return NLPInfoOutput(definitions=definitions)
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/model/kinds/qagen/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_info(self) -> QAGenInfoOutput:
)
definitions = QAGenInfoOutputDefinitions(
apiVersion=super()._get_api_version(),
kind=self.get_kind(),
kind=self.get_kind(), # type: ignore[arg-type]
spec=spec,
)
return QAGenInfoOutput(definitions=definitions)
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/model/kinds/qagen/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List, Literal, Optional

from pydantic import root_validator
from pydantic.v1 import root_validator

from deepsearch.model.base.types import (
BaseAppPredInput,
Expand Down
2 changes: 1 addition & 1 deletion deepsearch/model/server/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseSettings, SecretStr
from pydantic.v1 import BaseSettings, SecretStr


class Settings(BaseSettings):
Expand Down
Loading

0 comments on commit e48a769

Please sign in to comment.