From b0047bb97a52000a7d94ccd1375ab16c4508f552 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 18 Nov 2024 11:04:21 +0100 Subject: [PATCH] Changes: - lazify all imports - provide types for files, fields --- docs/release-notes.md | 6 ++++++ edgy/__init__.py | 24 ++++++++++++++---------- edgy/_monkay.py | 9 +++++++++ edgy/conf/enums.py | 4 ++-- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 19dd9b88..4b59dabe 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -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. @@ -24,6 +25,7 @@ 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 @@ -31,6 +33,10 @@ hide: - `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. diff --git a/edgy/__init__.py b/edgy/__init__.py index 37d1eb91..b32cf762 100644 --- a/edgy/__init__.py +++ b/edgy/__init__.py @@ -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 @@ -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.""" diff --git a/edgy/_monkay.py b/edgy/_monkay.py index ad0e3c66..4e223959 100644 --- a/edgy/_monkay.py +++ b/edgy/_monkay.py @@ -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", diff --git a/edgy/conf/enums.py b/edgy/conf/enums.py index 2a5fe5a9..22e664da 100644 --- a/edgy/conf/enums.py +++ b/edgy/conf/enums.py @@ -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, )