Resolve media and template files relative to component class dir (#395), thanks @JuroOravec

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Emil Stenström <emil@emilstenstrom.se>
This commit is contained in:
Juro Oravec 2024-03-23 19:01:39 +01:00 committed by GitHub
parent 1de859bd34
commit 37fd901908
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 477 additions and 43 deletions

View file

@ -1,14 +1,12 @@
import glob
import importlib
import importlib.util
import sys
from pathlib import Path
import django
from django.template.engine import Engine
from django.utils.module_loading import autodiscover_modules
from django_components.template_loader import Loader
from django_components.utils.autodiscover import search
if django.VERSION < (3, 2):
default_app_config = "django_components.apps.ComponentsConfig"
@ -22,12 +20,9 @@ def autodiscover():
autodiscover_modules("components")
# Autodetect a <component>.py file in a components dir
current_engine = Engine.get_default()
loader = Loader(current_engine)
dirs = loader.get_dirs()
for directory in dirs:
for path in glob.iglob(str(directory / "**/*.py"), recursive=True):
import_file(path)
component_filepaths = search(search_glob="**/*.py")
for path in component_filepaths:
import_file(path)
for path in app_settings.LIBRARIES:
importlib.import_module(path)