Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- lazify all imports
- provide types for files, fields
  • Loading branch information
devkral committed Nov 18, 2024
1 parent 799f8a3 commit b0047bb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
6 changes: 6 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ hide:
### Changed

- Rework edgy to use Monkay.
- Imports are now lazy.
- Rework the migrate and shell system to simply use Monkay instance.
- Replace `get_registry_copy` by `get_migration_prepared_registry`.
- Breaking: migration configuration takes place in settings.
Expand All @@ -24,13 +25,18 @@ hide:
- Breaking:
An automatic registration is assumed. See [Connection](connection.md) for examples.
- Breaking: `--app` or `EDGY_DEFAULT_APP` must point to a module which does the self-registration not an app instance anymore.
- Deprecate `edgy.conf.enums.EnvironmentType`. Esmeralds `EnvironmentType` or an own definition should be used instead.

### Fixed

- Migrations with ManyToMany fields are broken.
- `get_engine_url_and_metadata` was broken for some operations (thanks @kokoserver).
- IPAddressField was not exposed as edgy.IPAddressField.

### Removed

- `edgy.conf.functional`. It was only used for configuration and is now superseeded by Monkay.

### Contributors

Thanks a lot to @kokoserver. He provided a *lot* of valuable bug reports and PRs.
Expand Down
24 changes: 14 additions & 10 deletions edgy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
from typing import TYPE_CHECKING

from ._monkay import Instance, create_monkay
from .core.connection import Database, DatabaseURL, Registry
from .core.db.models import (
Manager,
Model,
ModelRef,
RedirectManager,
ReflectModel,
StrictModel,
)
from .core.db.querysets import Prefetch, Q, QuerySet, and_, not_, or_
from .core.utils.sync import run_sync

if TYPE_CHECKING:
from .conf.global_settings import EdgySettings
from .core import files
from .core.connection import Database, DatabaseURL, Registry
from .core.db import fields
from .core.db.datastructures import Index, UniqueConstraint
from .core.db.models import (
Manager,
Model,
ModelRef,
RedirectManager,
ReflectModel,
StrictModel,
)
from .core.db.querysets import Prefetch, Q, QuerySet, and_, not_, or_
from .core.signals import Signal
from .exceptions import MultipleObjectsReturned, ObjectNotFound

Expand Down Expand Up @@ -102,6 +104,8 @@
]
monkay = create_monkay(globals(), __all__)

del create_monkay


def get_migration_prepared_registry() -> Registry:
"""Get registry with applied restrictions, usable for migrations."""
Expand Down
9 changes: 9 additions & 0 deletions edgy/_monkay.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ def create_monkay(global_dict: dict, all_var: list[str]) -> Monkay[Instance, Edg
]:
monkay.add_lazy_import(name, f"edgy.core.db.constants.{name}")

for name in ["Database", "DatabaseURL", "Registry"]:
monkay.add_lazy_import(name, f"edgy.core.connection.{name}")

for name in ["Prefetch", "Q", "QuerySet", "and_", "not_", "or_"]:
monkay.add_lazy_import(name, f"edgy.core.db.querysets.{name}")

for name in ["Manager", "Model", "ModelRef", "RedirectManager", "ReflectModel", "StrictModel"]:
monkay.add_lazy_import(name, f"edgy.core.db.models.{name}")

for name in all_var:
if name.endswith("Field") or name in {
"OneToOne",
Expand Down
4 changes: 2 additions & 2 deletions edgy/conf/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from warnings import warn

warn(
"This module is deprecated. Use `esmerald.conf.EnvironmentType` instead when using Esmerald. "
"Otherwise define your own EnvironmentType.",
"This module is deprecated. Use `esmerald.conf.EnvironmentType` instead when using Esmerald "
"or define otherwise your own EnvironmentType.",
DeprecationWarning,
stacklevel=2,
)
Expand Down

0 comments on commit b0047bb

Please sign in to comment.