mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 15:39:08 +00:00
refactor: use BASE_DIR for project_root
This commit is contained in:
parent
752567bf7c
commit
9104a43944
1 changed files with 6 additions and 2 deletions
|
@ -4,6 +4,7 @@ import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import django
|
import django
|
||||||
|
from django.conf import settings
|
||||||
from django.utils.module_loading import autodiscover_modules
|
from django.utils.module_loading import autodiscover_modules
|
||||||
|
|
||||||
from django_components.logger import logger
|
from django_components.logger import logger
|
||||||
|
@ -45,7 +46,10 @@ def _filepath_to_python_module(file_path: Path) -> str:
|
||||||
- Then the path relative to project root is `app/components/mycomp.py`
|
- Then the path relative to project root is `app/components/mycomp.py`
|
||||||
- Which we then turn into python import path `app.components.mycomp`
|
- Which we then turn into python import path `app.components.mycomp`
|
||||||
"""
|
"""
|
||||||
# Get the root dir, see https://stackoverflow.com/a/16413955/9788634
|
if hasattr(settings, "BASE_DIR"):
|
||||||
|
project_root = str(settings.BASE_DIR)
|
||||||
|
else:
|
||||||
|
# Fallback for getting the root dir, see https://stackoverflow.com/a/16413955/9788634
|
||||||
project_root = os.path.abspath(os.path.dirname(__name__))
|
project_root = os.path.abspath(os.path.dirname(__name__))
|
||||||
|
|
||||||
rel_path = os.path.relpath(file_path, start=project_root)
|
rel_path = os.path.relpath(file_path, start=project_root)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue