mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 07:29:09 +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
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.utils.module_loading import autodiscover_modules
|
||||
|
||||
from django_components.logger import logger
|
||||
|
@ -45,8 +46,11 @@ def _filepath_to_python_module(file_path: Path) -> str:
|
|||
- Then the path relative to project root is `app/components/mycomp.py`
|
||||
- Which we then turn into python import path `app.components.mycomp`
|
||||
"""
|
||||
# Get the root dir, see https://stackoverflow.com/a/16413955/9788634
|
||||
project_root = os.path.abspath(os.path.dirname(__name__))
|
||||
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__))
|
||||
|
||||
rel_path = os.path.relpath(file_path, start=project_root)
|
||||
rel_path_without_suffix = str(Path(rel_path).with_suffix(""))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue