Added poetry integration.

Description:
* Fixed github actions;
* Removed requirements.txt;
* Fixed CONTRIBUTING.md;
* Fixed black and flake8.

Signed-off-by: Pavel <win10@list.ru>
This commit is contained in:
Pavel
2021-10-08 15:57:22 +04:00
parent 80c6ff38a1
commit b2541bed1e
52 changed files with 2685 additions and 377 deletions

View File

@ -29,7 +29,7 @@ def is_field_an_forward_ref(field: "BaseField") -> bool:
)
def populate_default_options_values(
def populate_default_options_values( # noqa: CCR001
new_model: Type["Model"], model_fields: Dict
) -> None:
"""

View File

@ -280,7 +280,7 @@ def copy_and_replace_m2m_through_model( # noqa: CFQ002
field.create_default_through_model()
through_class = field.through
new_meta: ormar.ModelMeta = type( # type: ignore
"Meta", (), dict(through_class.Meta.__dict__),
"Meta", (), dict(through_class.Meta.__dict__)
)
copy_name = through_class.__name__ + attrs.get("__name__", "")
copy_through = type(copy_name, (ormar.Model,), {"Meta": new_meta})
@ -566,9 +566,7 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
attrs, model_fields = extract_from_parents_definition(
base_class=base, curr_class=mcs, attrs=attrs, model_fields=model_fields
)
new_model = super().__new__( # type: ignore
mcs, name, bases, attrs
)
new_model = super().__new__(mcs, name, bases, attrs) # type: ignore
add_cached_properties(new_model)
@ -647,6 +645,6 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
access_chain=item,
)
return FieldAccessor(
source_model=cast(Type["Model"], self), field=field, access_chain=item,
source_model=cast(Type["Model"], self), field=field, access_chain=item
)
return object.__getattribute__(self, item)

View File

@ -141,7 +141,7 @@ class ExcludableMixin(RelationMixin):
return columns
@classmethod
def _update_excluded_with_related(cls, exclude: Union[Set, Dict, None],) -> Set:
def _update_excluded_with_related(cls, exclude: Union[Set, Dict, None]) -> Set:
"""
Used during generation of the dict().
To avoid cyclical references and max recurrence limit nested models have to

View File

@ -51,7 +51,7 @@ class PrefetchQueryMixin(RelationMixin):
@staticmethod
def get_column_name_for_id_extraction(
parent_model: Type["Model"], reverse: bool, related: str, use_raw: bool,
parent_model: Type["Model"], reverse: bool, related: str, use_raw: bool
) -> str:
"""
Returns name of the column that should be used to extract ids from model.

View File

@ -28,7 +28,7 @@ class PydanticMixin(RelationMixin):
@classmethod
def get_pydantic(
cls, *, include: Union[Set, Dict] = None, exclude: Union[Set, Dict] = None,
cls, *, include: Union[Set, Dict] = None, exclude: Union[Set, Dict] = None
) -> Type[pydantic.BaseModel]:
"""
Returns a pydantic model out of ormar model.

View File

@ -1,12 +1,4 @@
from typing import (
Callable,
Dict,
List,
Optional,
Set,
TYPE_CHECKING,
cast,
)
from typing import Callable, Dict, List, Optional, Set, TYPE_CHECKING, cast
from ormar import BaseField, ForeignKeyField
from ormar.models.traversible import NodeList

View File

@ -222,7 +222,7 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
@staticmethod
async def _upsert_through_model(
instance: "Model", previous_model: "Model", relation_field: "ForeignKeyField",
instance: "Model", previous_model: "Model", relation_field: "ForeignKeyField"
) -> None:
"""
Upsert through model for m2m relation.

View File

@ -1,13 +1,4 @@
from typing import (
Any,
Dict,
List,
Optional,
Set,
TYPE_CHECKING,
TypeVar,
Union,
)
from typing import Any, Dict, List, Optional, Set, TYPE_CHECKING, TypeVar, Union
import ormar.queryset # noqa I100
from ormar.exceptions import ModelPersistenceError, NoMatch

View File

@ -1,14 +1,4 @@
from typing import (
Any,
Dict,
List,
Optional,
TYPE_CHECKING,
Tuple,
Type,
Union,
cast,
)
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Tuple, Type, Union, cast
try:
from sqlalchemy.engine.result import ResultProxy
@ -293,7 +283,7 @@ class ModelRow(NewBaseModel):
"""
through_name = cls.Meta.model_fields[related].through.get_name()
through_child = cls._create_through_instance(
row=row, related=related, through_name=through_name, excludable=excludable,
row=row, related=related, through_name=through_name, excludable=excludable
)
if child.__class__ != proxy_source_model:
@ -378,7 +368,7 @@ class ModelRow(NewBaseModel):
:rtype: Dict
"""
selected_columns = cls.own_table_columns(
model=cls, excludable=excludable, alias=table_prefix, use_alias=False,
model=cls, excludable=excludable, alias=table_prefix, use_alias=False
)
column_prefix = table_prefix + "_" if table_prefix else ""

View File

@ -18,17 +18,17 @@ from typing import (
cast,
)
import databases
import pydantic
import sqlalchemy
from ormar.models.utils import Extra
from pydantic import BaseModel
try:
import orjson as json
except ImportError: # pragma: no cover
import json # type: ignore
import databases
import pydantic
import sqlalchemy
from pydantic import BaseModel
import ormar # noqa I100
from ormar.exceptions import ModelError, ModelPersistenceError
@ -154,7 +154,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
# register the columns models after initialization
for related in self.extract_related_names().union(self.extract_through_names()):
model_fields[related].expand_relationship(
new_kwargs.get(related), self, to_register=True,
new_kwargs.get(related), self, to_register=True
)
if hasattr(self, "_init_private_attributes"):
@ -218,7 +218,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
f"need to call update_forward_refs()."
)
def _process_kwargs(self, kwargs: Dict) -> Tuple[Dict, Dict]:
def _process_kwargs(self, kwargs: Dict) -> Tuple[Dict, Dict]: # noqa: CCR001
"""
Initializes nested models.
@ -261,7 +261,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
k,
self._convert_json(
k,
model_fields[k].expand_relationship(v, self, to_register=False,)
model_fields[k].expand_relationship(v, self, to_register=False)
if k in model_fields
else (v if k in pydantic_fields else model_fields[k]),
),
@ -315,7 +315,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
self,
"_orm",
RelationsManager(
related_fields=self.extract_related_fields(), owner=cast("Model", self),
related_fields=self.extract_related_fields(), owner=cast("Model", self)
),
)
@ -488,7 +488,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
@staticmethod
def _get_not_excluded_fields(
fields: Union[List, Set], include: Optional[Dict], exclude: Optional[Dict],
fields: Union[List, Set], include: Optional[Dict], exclude: Optional[Dict]
) -> List:
"""
Returns related field names applying on them include and exclude set.