-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: - Update release notes - Note explicit that app must be a module - move monkay to _monkay.py file - deprecate EnvironmentType - remove edgy.conf.functional. Its only use was the settings. - lazify all imports - provide types for files, fields modules
- Loading branch information
Showing
7 changed files
with
125 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from importlib import import_module | ||
from typing import TYPE_CHECKING, Any, NamedTuple, Optional | ||
|
||
from monkay import Monkay | ||
|
||
if TYPE_CHECKING: | ||
from edgy.conf.global_settings import EdgySettings | ||
from edgy.core.connection import Registry | ||
|
||
|
||
class Instance(NamedTuple): | ||
registry: Registry | ||
app: Optional[Any] = None | ||
|
||
|
||
def create_monkay(global_dict: dict, all_var: list[str]) -> Monkay[Instance, EdgySettings]: | ||
monkay: Monkay[Instance, EdgySettings] = Monkay( | ||
global_dict, | ||
with_extensions=True, | ||
with_instance=True, | ||
# must be at least an empty string to initialize the settings | ||
settings_path=os.environ.get( | ||
"EDGY_SETTINGS_MODULE", "edgy.conf.global_settings.EdgySettings" | ||
), | ||
settings_extensions_name="extensions", | ||
settings_preloads_name="preloads", | ||
uncached_imports={"settings"}, | ||
lazy_imports={ | ||
"settings": lambda: monkay.settings, | ||
"EdgySettings": "edgy.conf.global_settings:EdgySettings", | ||
"fields": lambda: import_module("edgy.core.db.fields"), | ||
"files": lambda: import_module("edgy.core.files"), | ||
"Signal": "edgy.core.signals:Signal", | ||
"MultipleObjectsReturned": "edgy.exceptions:MultipleObjectsReturned", | ||
"ObjectNotFound": "edgy.exceptions:ObjectNotFound", | ||
"UniqueConstraint": "edgy.core.db.datastructures:UniqueConstraint", | ||
"Index": "edgy.core.db.datastructures:Index", | ||
}, | ||
deprecated_lazy_imports={ | ||
"Migrate": { | ||
"path": "edgy.cli.base:Migrate", | ||
"reason": "Use the monkay based system instead.", | ||
"new_attribute": "Instance", | ||
}, | ||
"EdgyExtra": { | ||
"path": "edgy.cli.base:Migrate", | ||
"reason": "Use the monkay based system instead.", | ||
"new_attribute": "Instance", | ||
}, | ||
}, | ||
skip_all_update=True, | ||
) | ||
for name in [ | ||
"CASCADE", | ||
"RESTRICT", | ||
"DO_NOTHING", | ||
"SET_NULL", | ||
"SET_DEFAULT", | ||
"PROTECT", | ||
"ConditionalRedirect", | ||
]: | ||
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", | ||
"ManyToMany", | ||
"ForeignKey", | ||
"RefForeignKey", | ||
}: | ||
monkay.add_lazy_import(name, f"edgy.core.db.fields.{name}") | ||
|
||
return monkay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.