Skip to content

Commit dab1675

Browse files
add new pre_ready hook (#204)
oops! autoconf can't work unless it sets up the builtins before component discovery
1 parent 70073b5 commit dab1675

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
1818

1919
## [Unreleased]
2020

21+
### Added
22+
23+
- Added new plugin hook `pre_ready` for handling initialization of library, but run before any internal setup. Needed for django-bird-autoconf to autoconfigure projects, e.g, add to template builtins.
24+
2125
## [0.16.1]
2226

2327
### Added

src/django_bird/apps.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ def ready(self):
1919
from django_bird.plugins import pm
2020
from django_bird.staticfiles import asset_types
2121

22+
for pre_ready in pm.hook.pre_ready():
23+
pre_ready()
24+
2225
pm.hook.register_asset_types(register_type=asset_types.register_type)
2326
components.discover_components()
27+
2428
for ready in pm.hook.ready():
2529
ready()

src/django_bird/plugins/hookspecs.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,30 @@ def get_template_directories() -> list[Path]:
3737
"""
3838

3939

40+
@hookspec
41+
def pre_ready() -> None:
42+
"""Called before django-bird begins its internal setup.
43+
44+
This hook runs at the start of django-bird's initialization, before any internal
45+
components are configured or discovered. Plugins can use this hook to perform early
46+
configuration of:
47+
48+
- Django settings
49+
- Template directories
50+
- Template builtins
51+
"""
52+
53+
4054
@hookspec
4155
def ready() -> None:
42-
"""Called when the django-bird application is ready.
56+
"""Called after django-bird application has completed its internal setup and is ready.
57+
58+
This hook is called during Django's application ready phase, after django-bird's own
59+
initialization is complete. Plugins can:
4360
44-
This hook is called during Django's application ready phase, allowing plugins to perform
45-
necessary setup like configuring settings, registering features, or any other
46-
initialization tasks.
61+
- Access fully configured components
62+
- Register additional features that depend on django-bird being ready
63+
- Perform cleanup or post-initialization tasks
4764
"""
4865

4966

0 commit comments

Comments
 (0)