File tree Expand file tree Collapse file tree 6 files changed +48
-8
lines changed Expand file tree Collapse file tree 6 files changed +48
-8
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,14 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
1818
1919## [ Unreleased]
2020
21+ ### Added
22+
23+ - Added new plugin hook ` ready ` for handling application initialization during Django's application ready phase.
24+
25+ ### Changed
26+
27+ - ** Internal** : Refactored application initialization to use internal plugin instead of direct calls in ` AppConfig.ready() ` .
28+
2129## [ 0.16.0]
2230
2331🚨 This release contains some breaking changes. See the Changed section for more information. 🚨
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ django-bird uses a plugin system based on [pluggy](https://pluggy.readthedocs.io
2020```
2121````
2222
23+ ```` {py:function} ready(app_settings: django_bird.conf.AppSettings) -> None
24+ :canonical: django_bird.plugins.hookspecs.ready
25+
26+ ```{autodoc2-docstring} django_bird.plugins.hookspecs.ready
27+ :parser: myst
28+ ```
29+ ````
30+
2331```` {py:function} register_asset_types(register_type: collections.abc.Callable[[django_bird.staticfiles.AssetType], None]) -> None
2432:canonical: django_bird.plugins.hookspecs.register_asset_types
2533
Original file line number Diff line number Diff line change @@ -15,11 +15,8 @@ class DjangoBirdAppConfig(AppConfig):
1515
1616 @override
1717 def ready (self ):
18- from django_bird .components import components
1918 from django_bird .conf import app_settings
2019 from django_bird .plugins import pm
21- from django_bird .staticfiles import asset_types
2220
23- app_settings .autoconfigure ()
24- pm .hook .register_asset_types (register_type = asset_types .register_type )
25- components .discover_components ()
21+ for init_handler in pm .hook .ready (app_settings = app_settings ):
22+ init_handler ()
Original file line number Diff line number Diff line change 1010import django .template
1111from django .conf import settings
1212
13+ from django_bird import hookimpl
14+
1315from ._typing import override
1416from .utils import unique_ordered
1517
16- DJANGO_BIRD_SETTINGS_NAME = "DJANGO_BIRD"
1718
18- DJANGO_BIRD_BUILTINS = "django_bird.templatetags.django_bird"
19- DJANGO_BIRD_FINDER = "django_bird.staticfiles.BirdAssetFinder"
19+ @hookimpl
20+ def ready (app_settings : AppSettings ):
21+ from .components import components
22+ from .plugins import pm
23+ from .staticfiles import asset_types
24+
25+ app_settings .autoconfigure ()
26+ pm .hook .register_asset_types (register_type = asset_types .register_type )
27+ components .discover_components ()
28+
29+
30+ DJANGO_BIRD_SETTINGS_NAME = "DJANGO_BIRD"
2031
2132
2233@dataclass
@@ -44,6 +55,10 @@ def get_component_directory_names(self):
4455 return unique_ordered ([* self .COMPONENT_DIRS , "bird" ])
4556
4657
58+ DJANGO_BIRD_BUILTINS = "django_bird.templatetags.django_bird"
59+ DJANGO_BIRD_FINDER = "django_bird.staticfiles.BirdAssetFinder"
60+
61+
4762@final
4863class AutoConfigurator :
4964 def __init__ (self , app_settings : AppSettings ) -> None :
Original file line number Diff line number Diff line change 88from pluggy import HookspecMarker
99
1010if TYPE_CHECKING :
11+ from django_bird .conf import AppSettings
1112 from django_bird .staticfiles import Asset
1213 from django_bird .staticfiles import AssetType
1314
@@ -37,6 +38,16 @@ def get_template_directories() -> list[Path]:
3738 """
3839
3940
41+ @hookspec
42+ def ready (app_settings : AppSettings ) -> None :
43+ """Called when the django-bird application is ready.
44+
45+ This hook is called during Django's application ready phase,
46+ allowing plugins to perform necessary setup like configuring
47+ settings, registering features, or any other initialization tasks.
48+ """
49+
50+
4051@hookspec
4152def register_asset_types (register_type : Callable [[AssetType ], None ]) -> None :
4253 """Register a new type of asset.
Original file line number Diff line number Diff line change 1212pm .load_setuptools_entrypoints ("django_bird" )
1313
1414DEFAULT_PLUGINS : list [str ] = [
15+ "django_bird.conf" ,
1516 "django_bird.staticfiles" ,
1617 "django_bird.templates" ,
1718]
You can’t perform that action at this time.
0 commit comments