Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update precommit hooks & CI #673

Merged
merged 5 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 0 additions & 19 deletions .github/workflows/github-actions-lint.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/github-actions-mypy.yml

This file was deleted.

16 changes: 13 additions & 3 deletions .github/workflows/github-actions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: Tests
on: [ pull_request ]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: pre-commit/action@v3.0.0
run-tests:
strategy:
fail-fast: false
Expand All @@ -12,11 +20,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: pyproject.toml
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.3.0
uses: supercharge/mongodb-github-action@1.8.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-replica-set: test-rs
Expand All @@ -25,4 +35,4 @@ jobs:
- name: install pydantic
run: pip install pydantic==${{ matrix.pydantic-version }}
- name: run tests
run: pytest
run: pytest -v
7 changes: 3 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 23.7.0
hooks:
- id: black
language_version: python3.10
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.220
rev: v0.0.285
hooks:
- id: ruff
args: [ "--force-exclude" ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies:
Expand Down
26 changes: 13 additions & 13 deletions beanie/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
from beanie.migrations.controllers.free_fall import free_fall_migration
from beanie.migrations.controllers.iterative import iterative_migration
from beanie.odm.actions import (
before_event,
after_event,
After,
Before,
Delete,
Insert,
Replace,
Save,
SaveChanges,
ValidateOnSave,
Before,
After,
Delete,
Update,
ValidateOnSave,
after_event,
before_event,
)
from beanie.odm.bulk import BulkWriter
from beanie.odm.custom_types import DecimalAnnotation
from beanie.odm.custom_types.bson.binary import BsonBinary
from beanie.odm.documents import Document
from beanie.odm.fields import (
PydanticObjectId,
BackLink,
DeleteRules,
Indexed,
Link,
BackLink,
PydanticObjectId,
WriteRules,
DeleteRules,
)
from beanie.odm.queries.update import UpdateResponse
from beanie.odm.settings.timeseries import TimeSeriesConfig, Granularity
from beanie.odm.settings.timeseries import Granularity, TimeSeriesConfig
from beanie.odm.union_doc import UnionDoc
from beanie.odm.utils.init import init_beanie
from beanie.odm.documents import Document
from beanie.odm.views import View
from beanie.odm.union_doc import UnionDoc

__version__ = "1.22.5"
__version__ = "1.22.6"
__all__ = [
# ODM
"Document",
Expand Down
2 changes: 1 addition & 1 deletion beanie/executors/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from beanie.migrations import template
from beanie.migrations.database import DBHandler
from beanie.migrations.models import RunningMode, RunningDirections
from beanie.migrations.models import RunningDirections, RunningMode
from beanie.migrations.runner import MigrationNode

logging.basicConfig(format="%(message)s", level=logging.INFO)
Expand Down
4 changes: 2 additions & 2 deletions beanie/migrations/controllers/free_fall.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from inspect import signature
from typing import Type, List
from typing import List, Type

from beanie.odm.documents import Document
from beanie.migrations.controllers.base import BaseMigrationController
from beanie.odm.documents import Document


def free_fall_migration(document_models: List[Type[Document]]):
Expand Down
9 changes: 4 additions & 5 deletions beanie/migrations/controllers/iterative.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from inspect import signature, isclass
from typing import Type, Optional, Union, List
import asyncio
from inspect import isclass, signature
from typing import List, Optional, Type, Union

from beanie.migrations.utils import update_dict
from beanie.migrations.controllers.base import BaseMigrationController
from beanie.migrations.utils import update_dict
from beanie.odm.documents import Document
import asyncio

from beanie.odm.utils.pydantic import parse_model


Expand Down
8 changes: 4 additions & 4 deletions beanie/migrations/runner.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import logging
from importlib.machinery import SourceFileLoader
from pathlib import Path
from typing import Type, Optional
from typing import Optional, Type

from beanie.odm.documents import Document
from beanie.odm.utils.init import init_beanie
from beanie.migrations.controllers.iterative import BaseMigrationController
from beanie.migrations.database import DBHandler
from beanie.migrations.models import (
MigrationLog,
RunningMode,
RunningDirections,
RunningMode,
)
from beanie.odm.documents import Document
from beanie.odm.utils.init import init_beanie

logger = logging.getLogger(__name__)

Expand Down
10 changes: 5 additions & 5 deletions beanie/odm/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from enum import Enum
from functools import wraps
from typing import (
TYPE_CHECKING,
Any,
Callable,
List,
Union,
Dict,
TYPE_CHECKING,
Type,
List,
Optional,
Tuple,
Any,
Type,
Union,
)

if TYPE_CHECKING:
Expand Down
13 changes: 7 additions & 6 deletions beanie/odm/bulk.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from typing import Dict, Any, List, Optional, Union, Type, Mapping
from typing import Any, Dict, List, Mapping, Optional, Type, Union

from beanie.odm.utils.pydantic import IS_PYDANTIC_V2
from pydantic import BaseModel, Field
from pymongo import (
InsertOne,
DeleteOne,
DeleteMany,
DeleteOne,
InsertOne,
ReplaceOne,
UpdateOne,
UpdateMany,
UpdateOne,
)
from pymongo.results import BulkWriteResult
from pymongo.client_session import ClientSession
from pymongo.results import BulkWriteResult

from beanie.odm.utils.pydantic import IS_PYDANTIC_V2

if IS_PYDANTIC_V2:
from pydantic import ConfigDict
Expand Down
1 change: 1 addition & 0 deletions beanie/odm/custom_types/bson/binary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Callable

import bson

from beanie.odm.utils.pydantic import IS_PYDANTIC_V2

if IS_PYDANTIC_V2:
Expand Down
52 changes: 28 additions & 24 deletions beanie/odm/documents.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import asyncio
from typing import ClassVar, AbstractSet, Iterable
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
ClassVar,
Dict,
Optional,
Iterable,
List,
Type,
Union,
Mapping,
TypeVar,
Any,
Optional,
Set,
Type,
TypeVar,
Union,
)
from typing import TYPE_CHECKING
from uuid import UUID, uuid4

from bson import DBRef, ObjectId
from lazy_model import LazyModel
from pydantic import (
ValidationError,
PrivateAttr,
Field,
ConfigDict,
Field,
PrivateAttr,
ValidationError,
)
from pydantic.class_validators import root_validator
from pydantic.main import BaseModel
Expand All @@ -35,27 +37,27 @@
from beanie.exceptions import (
CollectionWasNotInitialized,
DocumentNotFound,
RevisionIdWasChanged,
DocumentWasNotSaved,
NotSupported,
ReplaceError,
RevisionIdWasChanged,
)
from beanie.odm.actions import (
ActionDirections,
EventTypes,
wrap_with_actions,
ActionDirections,
)
from beanie.odm.bulk import BulkWriter, Operation
from beanie.odm.cache import LRUCache
from beanie.odm.fields import (
PydanticObjectId,
BackLink,
DeleteRules,
ExpressionField,
Link,
LinkInfo,
LinkTypes,
PydanticObjectId,
WriteRules,
DeleteRules,
BackLink,
)
from beanie.odm.interfaces.aggregate import AggregateInterface
from beanie.odm.interfaces.detector import ModelType
Expand All @@ -64,36 +66,38 @@
from beanie.odm.interfaces.inheritance import InheritanceInterface
from beanie.odm.interfaces.setters import SettersInterface
from beanie.odm.models import (
InspectionError,
InspectionResult,
InspectionStatuses,
InspectionError,
)
from beanie.odm.operators.find.comparison import In
from beanie.odm.operators.update.general import (
CurrentDate,
Inc,
Set as SetOperator,
Unset,
SetRevisionId,
Unset,
)
from beanie.odm.operators.update.general import (
Set as SetOperator,
)
from beanie.odm.queries.update import UpdateMany, UpdateResponse
from beanie.odm.settings.document import DocumentSettings
from beanie.odm.utils.dump import get_dict, get_top_level_nones
from beanie.odm.utils.parsing import merge_models
from beanie.odm.utils.pydantic import (
parse_object_as,
IS_PYDANTIC_V2,
get_extra_field_info,
get_field_type,
get_model_dump,
get_model_fields,
get_extra_field_info,
IS_PYDANTIC_V2,
parse_model,
get_model_dump,
parse_object_as,
)
from beanie.odm.utils.self_validation import validate_self_before
from beanie.odm.utils.state import (
saved_state_needed,
previous_saved_state_needed,
save_state_after,
saved_state_needed,
swap_revision_after,
)
from beanie.odm.utils.typing import extract_id_class
Expand All @@ -102,7 +106,7 @@
from pydantic import model_validator

if TYPE_CHECKING:
from pydantic.typing import AbstractSetIntStr, MappingIntStrAny, DictStrAny
from pydantic.typing import AbstractSetIntStr, DictStrAny, MappingIntStrAny

DocType = TypeVar("DocType", bound="Document")
DocumentProjectionType = TypeVar("DocumentProjectionType", bound=BaseModel)
Expand Down