refactor: fix wrongly initiated settings (#1250)

* refactor: fix wrongly initiated settings

* refacttor: remove `_load_settings()` from apps.py

* refactor: fix building of docs + update titles in API reference

* refactor: fix docs build error

* refactor: use EXTENSIONS_DEFAULTS

* refactor: update titles
This commit is contained in:
Juro Oravec 2025-06-10 10:12:48 +02:00 committed by GitHub
parent 2350a6b6c4
commit 458e1894db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 65 additions and 41 deletions

View file

@ -44,6 +44,7 @@ from pathlib import Path
from textwrap import dedent
from typing import Any, Dict, List, NamedTuple, Optional, Sequence, Tuple, Type, Union
from django.conf import settings
from django.core.management.base import BaseCommand
from django.urls import URLPattern, URLResolver
@ -465,7 +466,13 @@ def gen_reference_commands():
# Add link to source code
module_abs_path = import_module(cmd_def_cls.__module__).__file__
module_rel_path = Path(module_abs_path).relative_to(Path.cwd()).as_posix() # type: ignore[arg-type]
obj_lineno = inspect.findsource(cmd_def_cls)[1]
# NOTE: Raises `OSError` if the file is not found.
try:
obj_lineno = inspect.findsource(cmd_def_cls)[1]
except Exception:
obj_lineno = None
source_code_link = _format_source_code_html(module_rel_path, obj_lineno)
# NOTE: For the commands we have to generate the markdown entries ourselves,
@ -524,7 +531,7 @@ def gen_reference_commands():
)
def gen_reference_templatetags():
def gen_reference_template_tags():
"""
Generate documentation for all Django template tags defined by django-components,
like `{% slot %}`, `{% component %}`, etc.
@ -537,7 +544,7 @@ def gen_reference_templatetags():
]
preface = "<!-- Autogenerated by reference.py -->\n\n"
preface += (root / "docs/templates/reference_templatetags.md").read_text()
preface += (root / "docs/templates/reference_template_tags.md").read_text()
out_file = root / "docs/reference/template_tags.md"
out_file.parent.mkdir(parents=True, exist_ok=True)
@ -585,14 +592,14 @@ def gen_reference_templatetags():
)
def gen_reference_templatevars():
def gen_reference_template_variables():
"""
Generate documentation for all variables that are available inside the component templates
under the `{{ component_vars }}` variable, as defined by `ComponentVars`.
"""
preface = "<!-- Autogenerated by reference.py -->\n\n"
preface += (root / "docs/templates/reference_templatevars.md").read_text()
out_file = root / "docs/reference/template_vars.md"
preface += (root / "docs/templates/reference_template_variables.md").read_text()
out_file = root / "docs/reference/template_variables.md"
out_file.parent.mkdir(parents=True, exist_ok=True)
with out_file.open("w", encoding="utf-8") as f:
@ -1099,6 +1106,13 @@ def _is_extension_url_api(obj: Any) -> bool:
def gen_reference():
"""The entrypoint to generate all the reference documentation."""
# Set up Django settings so we can import `extensions`
if not settings.configured:
settings.configure(
BASE_DIR=Path(__file__).parent.parent.parent,
)
gen_reference_api()
gen_reference_exceptions()
gen_reference_components()
@ -1106,8 +1120,8 @@ def gen_reference():
gen_reference_tagformatters()
gen_reference_urls()
gen_reference_commands()
gen_reference_templatetags()
gen_reference_templatevars()
gen_reference_template_tags()
gen_reference_template_variables()
gen_reference_signals()
gen_reference_testing_api()
gen_reference_extension_hooks()