Skip to content

Commit 9accefc

Browse files
move get_component_directory_names to templates module (#227)
1 parent a93166c commit 9accefc

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

src/django_bird/conf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from django.conf import settings
88

99
from ._typing import override
10-
from .utils import unique_ordered
1110

1211
DJANGO_BIRD_SETTINGS_NAME = "DJANGO_BIRD"
1312

@@ -26,8 +25,5 @@ def __getattribute__(self, __name: str) -> object:
2625
user_settings = getattr(settings, DJANGO_BIRD_SETTINGS_NAME, {})
2726
return user_settings.get(__name, super().__getattribute__(__name))
2827

29-
def get_component_directory_names(self):
30-
return unique_ordered([*self.COMPONENT_DIRS, "bird"])
31-
3228

3329
app_settings = AppSettings()

src/django_bird/staticfiles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .apps import DjangoBirdAppConfig
2626
from .conf import app_settings
2727
from .templates import get_component_directories
28+
from .templates import get_component_directory_names
2829
from .templatetags.tags.asset import AssetTag
2930
from .utils import get_files_from_dirs
3031

@@ -125,7 +126,7 @@ def storage(self):
125126
@property
126127
def template_dir(self):
127128
template_dir = self.path.parent
128-
component_dirs = app_settings.get_component_directory_names()
129+
component_dirs = get_component_directory_names()
129130
while (
130131
len(template_dir.parts) > 1 and template_dir.parts[-1] not in component_dirs
131132
):

src/django_bird/templates.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_template_names(name: str) -> list[str]:
6868
list[str]: A list of potential template names in resolution order.
6969
"""
7070
template_names: list[str] = []
71-
component_dirs = app_settings.get_component_directory_names()
71+
component_dirs = get_component_directory_names()
7272

7373
name_parts = name.split(".")
7474
path_name = "/".join(name_parts)
@@ -103,6 +103,10 @@ def get_template_directories() -> Generator[Path, Any, None]:
103103
yield from hook_result
104104

105105

106+
def get_component_directory_names() -> list[Path | str]:
107+
return unique_ordered([*app_settings.COMPONENT_DIRS, "bird"])
108+
109+
106110
def get_component_directories(
107111
template_dirs: Iterator[Path] | None = None,
108112
) -> list[Path]:
@@ -112,7 +116,7 @@ def get_component_directories(
112116
return [
113117
Path(template_dir) / component_dir
114118
for template_dir in template_dirs
115-
for component_dir in app_settings.get_component_directory_names()
119+
for component_dir in get_component_directory_names()
116120
]
117121

118122

tests/test_conf.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import pytest
4-
from django.test import override_settings
54

65
from django_bird.conf import app_settings
76

@@ -10,10 +9,3 @@
109
def test_app_settings():
1110
assert app_settings.COMPONENT_DIRS == []
1211
assert app_settings.ENABLE_BIRD_ATTRS is True
13-
14-
15-
def test_component_directory_names():
16-
assert app_settings.get_component_directory_names() == ["bird"]
17-
18-
with override_settings(DJANGO_BIRD={"COMPONENT_DIRS": ["components"]}):
19-
assert app_settings.get_component_directory_names() == ["components", "bird"]

tests/test_templates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from django_bird.templates import find_components_in_template
77
from django_bird.templates import gather_bird_tag_template_usage
8+
from django_bird.templates import get_component_directory_names
89
from django_bird.templates import get_template_names
910

1011

@@ -60,8 +61,8 @@ def test_get_template_names_invalid():
6061
assert "bird/input/label/invalid.html" not in template_names
6162

6263

63-
def test_get_template_names_duplicates():
64-
with override_settings(DJANGO_BIRD={"COMPONENT_DIRS": ["bird"]}):
64+
def test_get_template_names_duplicates(override_app_settings):
65+
with override_app_settings(COMPONENT_DIRS=["bird"]):
6566
template_names = get_template_names("button")
6667

6768
template_counts = {}
@@ -72,6 +73,13 @@ def test_get_template_names_duplicates():
7273
assert count == 1
7374

7475

76+
def test_component_directory_names(override_app_settings):
77+
assert get_component_directory_names() == ["bird"]
78+
79+
with override_app_settings(COMPONENT_DIRS=["components"]):
80+
assert get_component_directory_names() == ["components", "bird"]
81+
82+
7583
def test_find_components_handles_errors():
7684
result = find_components_in_template("non_existent_template.html")
7785
assert result == set()

0 commit comments

Comments
 (0)