Skip to content

Commit 6a83168

Browse files
Mark BirdLoader as deprecated (#153)
1 parent 39bcceb commit 6a83168

File tree

7 files changed

+24
-335
lines changed

7 files changed

+24
-335
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
3232
### Deprecated
3333

3434
- The built-in asset serving view (`asset_view`) is deprecated and will be removed in the next minor version (v0.14.0). Use `BirdAssetFinder` with Django's staticfiles app.
35+
- The `BirdLoader` template loader is deprecated and will be removed in a future version. If you have enabled manual configuration by setting `ENABLE_AUTO_CONFIG=False`, please remove `django_bird.loader.BirdLoader` from your `TEMPLATES` setting.
3536

3637
### Removed
3738

docs/configuration.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ If you would like to disable this behavior and perform the setup manually, setti
7070
When `ENABLE_AUTO_CONFIG` is set to `False`, you need to manually configure the following:
7171

7272
1. Add django-bird's template tags to Django's built-ins.
73-
2. Include django-bird's loader in your template loaders, ensuring it comes before Django's default filesystem and app directories loaders.
7473

7574
The complete setup in your settings file should look like this:
7675

@@ -95,22 +94,12 @@ TEMPLATES = [
9594
"builtins": [
9695
"django_bird.templatetags.django_bird",
9796
],
98-
"loaders": [
99-
(
100-
"django.template.loaders.cached.Loader",
101-
[
102-
"django_bird.loader.BirdLoader",
103-
"django.template.loaders.filesystem.Loader",
104-
"django.template.loaders.app_directories.Loader",
105-
],
106-
),
107-
],
10897
},
10998
}
11099
]
111100
```
112101

113-
This configuration ensures that django-bird's templatetags are available globally and that its loader is used to compile bird component templates before the standard Django loaders.
102+
This configuration ensures that django-bird's templatetags are available globally.
114103

115104
## `ENABLE_BIRD_ATTRS`
116105

src/django_bird/conf.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
DJANGO_BIRD_BUILTINS = "django_bird.templatetags.django_bird"
1919
DJANGO_BIRD_FINDER = "django_bird.staticfiles.BirdAssetFinder"
20-
DJANGO_BIRD_LOADER = "django_bird.loader.BirdLoader"
2120

2221

2322
@dataclass
@@ -70,33 +69,13 @@ def configure_templates(self) -> None:
7069

7170
options = template_config.setdefault("OPTIONS", {})
7271

73-
self.configure_loaders(options)
7472
self.configure_builtins(options)
7573

7674
# Force re-evaluation of settings.TEMPLATES because EngineHandler caches it.
7775
with suppress(AttributeError):
7876
del django.template.engines.templates
7977
django.template.engines._engines = {} # type: ignore[attr-defined]
8078

81-
def configure_loaders(self, options: dict[str, Any]) -> None:
82-
loaders = options.setdefault("loaders", [])
83-
84-
# find the inner-most loaders, which is an iterable of only strings
85-
while not all(isinstance(loader, str) for loader in loaders):
86-
for loader in loaders:
87-
# if we've found a list or tuple, we aren't yet in the inner-most loaders
88-
if isinstance(loader, list | tuple):
89-
# reassign `loaders` variable to force the while loop restart
90-
loaders = loader
91-
92-
# if django-bird's loader is the first, we good
93-
loaders_already_configured = (
94-
len(loaders) > 0 and DJANGO_BIRD_LOADER == loaders[0]
95-
)
96-
97-
if not loaders_already_configured:
98-
loaders.insert(0, DJANGO_BIRD_LOADER)
99-
10079
def configure_builtins(self, options: dict[str, Any]) -> None:
10180
builtins = options.setdefault("builtins", [])
10281

src/django_bird/loader.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from __future__ import annotations
22

3-
from django.template.base import Origin
3+
import warnings
4+
45
from django.template.engine import Engine
56
from django.template.loaders.filesystem import Loader as FileSystemLoader
67

7-
from ._typing import override
8-
98

109
class BirdLoader(FileSystemLoader):
1110
def __init__(self, engine: Engine):
11+
warnings.warn(
12+
"BirdLoader is deprecated and will be removed in a future version. "
13+
"Please remove 'django_bird.loader.BirdLoader' from your TEMPLATES setting "
14+
"in settings.py and use Django's built-in 'django.template.loaders.filesystem.Loader' instead.",
15+
DeprecationWarning,
16+
stacklevel=2,
17+
)
1218
super().__init__(engine)
13-
14-
@override
15-
def get_contents(self, origin: Origin) -> str:
16-
return super().get_contents(origin)

tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def pytest_configure(config):
4848
"django_bird.templatetags.django_bird",
4949
],
5050
"loaders": [
51-
"django_bird.loader.BirdLoader",
5251
"django.template.loaders.filesystem.Loader",
5352
"django.template.loaders.app_directories.Loader",
5453
],
@@ -127,7 +126,6 @@ def _create_template(template_file: Path) -> DjangoTemplate:
127126
engine = Engine(
128127
builtins=["django_bird.templatetags.django_bird"],
129128
dirs=[str(template_file.parent)],
130-
loaders=["django_bird.loader.BirdLoader"],
131129
)
132130
template = engine.get_template(template_file.name)
133131
backend = DjangoTemplates(

0 commit comments

Comments
 (0)