Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- port nearly completely to Monkay
- make EdgyExtra and Migrate stubs
  • Loading branch information
devkral committed Nov 13, 2024
1 parent 3ca4125 commit 002c116
Show file tree
Hide file tree
Showing 42 changed files with 266 additions and 879 deletions.
59 changes: 0 additions & 59 deletions docs/extras.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs_src/commands/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from esmerald import Esmerald, Include
from my_project.utils import get_db_connection

from edgy import Migrate
from edgy import Instance, monkay


def build_path():
Expand Down Expand Up @@ -34,7 +34,7 @@ def get_application():
)
)

Migrate(app=app, registry=registry)
monkay.set_instance(Instance(app=app, registry=registry))
return app


Expand Down
4 changes: 2 additions & 2 deletions docs_src/connections/asgi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from esmerald import Esmerald

from edgy import Registry, Migrate
from edgy import Registry, Instance, monkay

models = Registry(database="sqlite:///db.sqlite", echo=True)

Expand All @@ -11,4 +11,4 @@
)
)
# monkey-patch app so you can use edgy shell
Migrate(app, models)
monkay.set_instance(Instance(app=app, registry=registry))
2 changes: 1 addition & 1 deletion docs_src/connections/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
application = models.asgi(handle_lifespan=True)(get_asgi_application())

# monkey-patch app so you can use edgy shell
Migrate(application, models)
monkay.set_instance(Instance(app=app, registry=registry))
4 changes: 2 additions & 2 deletions docs_src/connections/simple.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextlib import asynccontextmanager
from esmerald import Esmerald

from edgy import Registry, Migrate
from edgy import Registry, Instance, monkay

models = Registry(database="sqlite:///db.sqlite", echo=True)

Expand All @@ -17,4 +17,4 @@ async def lifespan(app: Esmerald):
lifespan=lifespan,
)
# monkey-patch app so you can use edgy shell
Migrate(application, models)
monkay.set_instance(Instance(app=app, registry=registry))
52 changes: 0 additions & 52 deletions docs_src/extras/app.py

This file was deleted.

4 changes: 2 additions & 2 deletions docs_src/migrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi import FastAPI
from my_project.utils import get_db_connection

from edgy import Migrate
from edgy import Instance, monkay


def build_path():
Expand All @@ -30,7 +30,7 @@ def get_application():

app = registry.asgi(FastAPI(__name__))

Migrate(app=app, registry=registry)
monkay.set_instance(Instance(app=app, registry=registry))
return app


Expand Down
4 changes: 2 additions & 2 deletions docs_src/migrations/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from my_project.utils import get_db_connection

from edgy import Migrate
from edgy import Instance, monkay
from esmerald import Esmerald, Include


Expand Down Expand Up @@ -34,7 +34,7 @@ def get_application():
)
)

Migrate(app=app, registry=registry)
monkay.set_instance(Instance(app=app, registry=registry))
return app


Expand Down
4 changes: 2 additions & 2 deletions docs_src/migrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lilya.apps import Lilya
from my_project.utils import get_db_connection

from edgy import Migrate
from edgy import monkay, Instance


def build_path():
Expand All @@ -30,7 +30,7 @@ def get_application():

app = registry.asgi(Lilya(__name__))

Migrate(app=app, registry=registry)
monkay.set_instance(Instance(app=app, registry=registry))
return app


Expand Down
4 changes: 2 additions & 2 deletions docs_src/tips/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from esmerald import Esmerald, Include
from my_project.utils import get_db_connection

from edgy.migrations import Migrate
from edgy import Instance, monkay


def build_path():
Expand Down Expand Up @@ -38,7 +38,7 @@ def get_application():
)
)

Migrate(app=app, registry=registry)
monkay.set_instance(Instance(app=app, registry=registry))
return app


Expand Down
51 changes: 27 additions & 24 deletions edgy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@
__version__ = "0.22.0"
import os
from importlib import import_module
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any, NamedTuple, Optional

from monkay import Monkay

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

if TYPE_CHECKING:
from .conf.global_settings import EdgySettings
from .core.connection import Database, DatabaseURL, Registry
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


class Instance(NamedTuple):
registry: Registry
app: Optional[Any] = None


__all__ = [
"Instance",
"monkay",
"and_",
"not_",
Expand Down Expand Up @@ -101,22 +108,23 @@
"Registry",
]

monkay: Monkay[Registry, EdgySettings] = Monkay(
monkay: Monkay[Instance, EdgySettings] = Monkay(
globals(),
with_extensions=True,
with_instance=True,
settings_path=os.environ.get("EDGY_SETTINGS_MODULE", "edgy.conf.global_settings.EdgySettings"),
settings_extensions_name="extensions",
settings_preloads_name="preloads",
# 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": {
Expand All @@ -130,13 +138,6 @@
},
skip_all_update=True,
)

for name in ["Manager", "Model", "ModelRef", "RedirectManager", "ReflectModel", "StrictModel"]:
monkay.add_lazy_import(name, f"edgy.core.db.models.{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 [
"CASCADE",
"RESTRICT",
Expand All @@ -156,3 +157,5 @@
"RefForeignKey",
}:
monkay.add_lazy_import(name, f"edgy.core.db.fields.{name}")

del name
Loading

0 comments on commit 002c116

Please sign in to comment.