mirror of
https://github.com/django-components/django-components.git
synced 2025-08-11 09:48:00 +00:00
refactor: change utils dir to file to fix missing import
This commit is contained in:
parent
ceb74b289d
commit
d4244578ed
3 changed files with 2 additions and 2 deletions
32
django_components/utils.py
Normal file
32
django_components/utils.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import glob
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from django.template.engine import Engine
|
||||
|
||||
from django_components.template_loader import Loader
|
||||
|
||||
|
||||
def search(search_glob: Optional[str] = None, engine: Optional[Engine] = None):
|
||||
"""
|
||||
Search for directories that may contain components.
|
||||
|
||||
If `search_glob` is given, the directories are searched for said glob pattern,
|
||||
and glob search results are returned as a flattened list.
|
||||
"""
|
||||
current_engine = engine
|
||||
if current_engine is None:
|
||||
current_engine = Engine.get_default()
|
||||
|
||||
loader = Loader(current_engine)
|
||||
dirs = loader.get_dirs()
|
||||
|
||||
if search_glob is None:
|
||||
return dirs
|
||||
|
||||
component_filenames: List[str] = []
|
||||
for directory in dirs:
|
||||
for path in glob.iglob(str(Path(directory) / search_glob), recursive=True):
|
||||
component_filenames.append(path)
|
||||
|
||||
return component_filenames
|
Loading…
Add table
Add a link
Reference in a new issue