Skip to content

Commit

Permalink
Nest globals under utils module
Browse files Browse the repository at this point in the history
Expose globals directly under the `protean` namespace. This is part of
changes to homogenize and expose (almost) all protean modules under
the protean namespace.
  • Loading branch information
subhashb committed Jul 25, 2024
1 parent 7ab79a1 commit 525fe45
Show file tree
Hide file tree
Showing 53 changed files with 62 additions and 52 deletions.
2 changes: 1 addition & 1 deletion docs_src/guides/change-state/007.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from protean import Domain, handle
from protean.fields import DateTime, Identifier, String
from protean.globals import current_domain
from protean.utils.globals import current_domain

publishing = Domain(__file__, "Publishing", load_toml=False)

Expand Down
2 changes: 1 addition & 1 deletion docs_src/guides/composing-a-domain/012.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from protean import Domain
from protean.fields import Integer, String
from protean.globals import current_domain
from protean.utils.globals import current_domain

domain = Domain(__file__, load_toml=False)

Expand Down
2 changes: 1 addition & 1 deletion docs_src/guides/composing-a-domain/018.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from protean import Domain
from protean.fields import Integer, String
from protean.globals import current_domain
from protean.utils.globals import current_domain

domain = Domain(__file__, load_toml=False)

Expand Down
4 changes: 4 additions & 0 deletions src/protean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .domain import Domain
from .server import Engine
from .utils import get_version
from .utils.globals import current_domain, current_uow, g
from .utils.mixins import handle

__all__ = [
Expand Down Expand Up @@ -48,4 +49,7 @@
"handle",
"invariant",
"atomic_change",
"current_domain",
"current_uow",
"g",
]
2 changes: 1 addition & 1 deletion src/protean/adapters/broker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from protean.core.event import BaseEvent
from protean.exceptions import ConfigurationError
from protean.globals import current_uow
from protean.utils.globals import current_uow
from protean.utils.mixins import Message

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/protean/adapters/event_store/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from protean.core.aggregate import BaseAggregate
from protean.core.repository import BaseRepository
from protean.globals import current_domain
from protean.port.event_store import BaseEventStore
from protean.utils.globals import current_domain
from protean.utils.mixins import MessageRecord


Expand Down
2 changes: 1 addition & 1 deletion src/protean/adapters/repository/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
from protean.core.queryset import ResultSet
from protean.exceptions import ObjectNotFoundError
from protean.fields import Reference
from protean.globals import current_domain
from protean.port.dao import BaseDAO, BaseLookup
from protean.port.provider import BaseProvider
from protean.reflection import attributes, id_field
from protean.utils import IdentityStrategy, IdentityType
from protean.utils.globals import current_domain
from protean.utils.query import Q

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/protean/adapters/repository/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from protean.core.queryset import ResultSet
from protean.exceptions import ObjectNotFoundError, ValidationError
from protean.fields.basic import Auto
from protean.globals import current_uow
from protean.port.dao import BaseDAO, BaseLookup
from protean.port.provider import BaseProvider
from protean.reflection import attributes, fields, id_field
from protean.utils.globals import current_uow
from protean.utils.query import Q


Expand Down
2 changes: 1 addition & 1 deletion src/protean/adapters/repository/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
)
from protean.fields.association import Reference, _ReferenceField
from protean.fields.embedded import _ShadowField
from protean.globals import current_domain, current_uow
from protean.port.dao import BaseDAO, BaseLookup
from protean.port.provider import BaseProvider
from protean.reflection import attributes, id_field
from protean.utils import IdentityType
from protean.utils.globals import current_domain, current_uow
from protean.utils.query import Q

logging.getLogger("sqlalchemy").setLevel(logging.ERROR)
Expand Down
2 changes: 1 addition & 1 deletion src/protean/core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
NotSupportedError,
ValidationError,
)
from protean.globals import g
from protean.utils import DomainObjects, derive_element_class, fqn
from protean.utils.eventing import BaseMessageType, Metadata
from protean.utils.globals import g


class BaseCommand(BaseMessageType):
Expand Down
2 changes: 1 addition & 1 deletion src/protean/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
IncorrectUsageError,
NotSupportedError,
)
from protean.globals import g
from protean.utils import DomainObjects, derive_element_class, fqn
from protean.utils.eventing import BaseMessageType, Metadata
from protean.utils.globals import g

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/protean/core/event_sourced_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
ObjectNotFoundError,
)
from protean.fields import Identifier
from protean.globals import current_uow
from protean.utils import DomainObjects, derive_element_class
from protean.utils.globals import current_uow

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/protean/core/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import logging
from typing import TYPE_CHECKING, Any, Union

from protean.globals import current_uow
from protean.utils import DomainObjects
from protean.utils.globals import current_uow
from protean.utils.query import Q

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion src/protean/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from protean.core.view import BaseView
from protean.exceptions import IncorrectUsageError, NotSupportedError
from protean.fields import HasMany, HasOne
from protean.globals import current_domain, current_uow
from protean.port.dao import BaseDAO
from protean.port.provider import BaseProvider
from protean.reflection import association_fields, has_association_fields
Expand All @@ -20,6 +19,7 @@
derive_element_class,
fully_qualified_name,
)
from protean.utils.globals import current_domain, current_uow

if TYPE_CHECKING:
from protean.domain import Domain
Expand Down
2 changes: 1 addition & 1 deletion src/protean/core/unit_of_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
InvalidOperationError,
ValidationError,
)
from protean.globals import _uow_context_stack, current_domain
from protean.reflection import id_field
from protean.utils import EventProcessing
from protean.utils.globals import _uow_context_stack, current_domain

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/protean/domain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
)
from protean.fields import HasMany, HasOne, Reference, ValueObject
from protean.fields import List as ProteanList
from protean.globals import g
from protean.reflection import declared_fields, has_fields, id_field
from protean.utils import (
CommandProcessing,
DomainObjects,
EventProcessing,
fqn,
)
from protean.utils.globals import g

from .config import Config2, ConfigAttribute
from .context import DomainContext, _DomainContextGlobals
Expand Down
2 changes: 1 addition & 1 deletion src/protean/domain/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import sys

from protean.globals import _domain_context_stack
from protean.utils.globals import _domain_context_stack

# a singleton sentinel value for parameter defaults
_sentinel = object()
Expand Down
2 changes: 1 addition & 1 deletion src/protean/fields/association.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from protean import exceptions, utils
from protean.exceptions import ValidationError
from protean.globals import current_domain
from protean.reflection import association_fields, has_association_fields, id_field
from protean.utils.globals import current_domain

from .base import Field, FieldBase
from .mixins import FieldCacheMixin, FieldDescriptorMixin
Expand Down
2 changes: 1 addition & 1 deletion src/protean/fields/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from protean.exceptions import InvalidOperationError, ValidationError
from protean.fields import Field, validators
from protean.fields.embedded import ValueObject
from protean.globals import current_domain
from protean.utils import IdentityType
from protean.utils.globals import current_domain


class String(Field):
Expand Down
2 changes: 1 addition & 1 deletion src/protean/port/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
ValidationError,
)
from protean.fields import Auto, Field
from protean.globals import current_uow
from protean.port.provider import BaseProvider
from protean.reflection import declared_fields, id_field, unique_fields
from protean.utils import DomainObjects
from protean.utils.globals import current_uow
from protean.utils.query import Q

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion src/protean/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from protean.core.command_handler import BaseCommandHandler
from protean.core.event_handler import BaseEventHandler
from protean.globals import g
from protean.utils.globals import g
from protean.utils.mixins import Message

from .subscription import Subscription
Expand Down
2 changes: 1 addition & 1 deletion src/protean/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from uuid import uuid4

from protean.exceptions import ConfigurationError
from protean.globals import current_domain
from protean.utils.globals import current_domain

logger = logging.getLogger(__name__)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/protean/utils/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from protean.core.event import BaseEvent
from protean.core.unit_of_work import UnitOfWork
from protean.exceptions import ConfigurationError, InvalidDataError
from protean.globals import current_domain
from protean.utils.eventing import Metadata
from protean.utils.globals import current_domain

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/broker/celery_broker/elements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from protean import BaseAggregate, BaseEvent, BaseSubscriber
from protean.fields import Auto, Integer, String
from protean.globals import current_domain
from protean.utils.globals import current_domain


class Person(BaseAggregate):
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/broker/redis_broker/elements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from protean import BaseAggregate, BaseEvent, BaseSubscriber
from protean.fields import Auto, Integer, String
from protean.globals import current_domain
from protean.utils.globals import current_domain


class Person(BaseAggregate):
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/broker/redis_broker/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import redis

from protean.adapters.broker.redis import RedisBroker
from protean.globals import current_domain
from protean.utils.globals import current_domain

from .elements import Person, PersonAdded

Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/email/sendgrid_email/elements.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from protean import BaseAggregate, BaseEmail, BaseEvent, BaseSubscriber
from protean.exceptions import InsufficientDataError, InvalidDataError
from protean.fields import Integer, String
from protean.globals import current_domain
from protean.utils.globals import current_domain


class Person(BaseAggregate):
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/model/dict_model/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from protean import BaseAggregate, BaseModel, BaseRepository, BaseValueObject, invariant
from protean.exceptions import ValidationError
from protean.fields import Integer, String, Text, ValueObject
from protean.globals import current_domain
from protean.utils.globals import current_domain


class Person(BaseAggregate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
List,
String,
)
from protean.globals import current_domain
from protean.utils.globals import current_domain


class ArrayUser(BaseAggregate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from protean import BaseAggregate
from protean.fields import DateTime, Dict, String
from protean.globals import current_domain
from protean.utils import utcnow_func
from protean.utils.globals import current_domain


class Event(BaseAggregate):
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/repository/memory/test_any_operator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from protean import BaseAggregate
from protean.fields import List
from protean.globals import current_domain
from protean.utils.globals import current_domain


class User(BaseAggregate):
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/repository/memory/test_in_operator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from protean import BaseAggregate
from protean.fields.basic import String
from protean.globals import current_domain
from protean.utils.globals import current_domain


class User(BaseAggregate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from protean import BaseAggregate
from protean.fields import Date, Integer, String
from protean.globals import current_domain
from protean.utils.globals import current_domain


class User(BaseAggregate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from protean import UnitOfWork
from protean.globals import current_uow
from protean.utils.globals import current_uow

from .elements import Person, PersonRepository

Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/repository/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from protean.exceptions import ExpectedVersionError, ValidationError
from protean.fields import Integer, String, ValueObject
from protean.globals import current_domain
from protean.utils.globals import current_domain


class Person(BaseAggregate):
Expand Down
2 changes: 1 addition & 1 deletion tests/aggregate/events/test_raising_aggregate_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from protean import BaseAggregate, BaseEntity, BaseEvent
from protean.core.unit_of_work import UnitOfWork
from protean.fields import HasOne, Identifier, String
from protean.globals import current_domain
from protean.utils.globals import current_domain


class UserStatus(Enum):
Expand Down
2 changes: 1 addition & 1 deletion tests/context/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from protean.globals import current_domain, g
from protean.utils.globals import current_domain, g


class TestDomainContext:
Expand Down
2 changes: 1 addition & 1 deletion tests/domain/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class Comment(BaseEntity):
)

# Remove domain context manually, as we lost it when the exception was raised
from protean.globals import _domain_context_stack
from protean.utils.globals import _domain_context_stack

_domain_context_stack.pop()

Expand Down
2 changes: 1 addition & 1 deletion tests/email_provider/elements.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from protean import BaseAggregate, BaseEmail, BaseEvent, BaseSubscriber
from protean.exceptions import InsufficientDataError, InvalidDataError
from protean.fields import Identifier, Integer, String
from protean.globals import current_domain
from protean.utils.globals import current_domain


class Person(BaseAggregate):
Expand Down
Loading

0 comments on commit 525fe45

Please sign in to comment.