mirror of
https://github.com/django-components/django-components.git
synced 2025-09-21 05:09:44 +00:00
Deployed 912d8e8
to 0.139.1 with MkDocs 1.6.1 and mike 2.1.3
This commit is contained in:
parent
2ade72c41a
commit
fa0fa32ca6
252 changed files with 20895 additions and 3 deletions
0
0.139.1/scripts/__init__.py
Normal file
0
0.139.1/scripts/__init__.py
Normal file
61
0.139.1/scripts/extensions.py
Normal file
61
0.139.1/scripts/extensions.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
from pathlib import Path
|
||||
from typing import List, Optional, Type
|
||||
|
||||
import griffe
|
||||
from mkdocs_util import get_mkdocstrings_plugin_handler_options, import_object, load_config
|
||||
|
||||
from django_components.util.misc import get_import_path
|
||||
|
||||
SOURCE_CODE_GIT_BRANCH = "master"
|
||||
|
||||
|
||||
mkdocstrings_config = get_mkdocstrings_plugin_handler_options() or {}
|
||||
is_skip_docstring: bool = mkdocstrings_config.get("show_if_no_docstring", "false") != "true"
|
||||
|
||||
|
||||
# Replacement for `show_bases: true`. Our implementation takes base names from the runtime
|
||||
# objects, effectively resolving aliases / reassignments.
|
||||
class RuntimeBasesExtension(griffe.Extension):
|
||||
"""Griffe extension that lists class bases."""
|
||||
|
||||
def on_class_instance(self, cls: griffe.Class, **kwargs) -> None:
|
||||
if is_skip_docstring and cls.docstring is None:
|
||||
return
|
||||
|
||||
runtime_cls: Type = import_object(cls)
|
||||
|
||||
bases_formatted: List[str] = []
|
||||
for base in runtime_cls.__bases__:
|
||||
bases_formatted.append(f"<code>{get_import_path(base)}</code>")
|
||||
|
||||
html = f'<p class="doc doc-class-bases">Bases: {", ".join(bases_formatted) or "-"}</p>'
|
||||
|
||||
cls.docstring = cls.docstring or griffe.Docstring("", parent=cls)
|
||||
cls.docstring.value = html + "\n\n" + cls.docstring.value
|
||||
|
||||
|
||||
class SourceCodeExtension(griffe.Extension):
|
||||
"""Griffe extension that adds link to the source code at the end of the docstring."""
|
||||
|
||||
def on_instance(self, obj: griffe.Object, **kwargs) -> None:
|
||||
if is_skip_docstring and obj.docstring is None:
|
||||
return
|
||||
|
||||
html = _format_source_code_html(obj.relative_filepath, obj.lineno)
|
||||
obj.docstring = obj.docstring or griffe.Docstring("", parent=obj)
|
||||
obj.docstring.value = html + obj.docstring.value
|
||||
|
||||
|
||||
def _format_source_code_html(relative_filepath: Path, lineno: Optional[int]):
|
||||
# Remove trailing slash and whitespace
|
||||
repo_url = load_config()["repo_url"].strip("/ ")
|
||||
branch_path = f"tree/{SOURCE_CODE_GIT_BRANCH}"
|
||||
lineno_hash = f"#L{lineno}" if lineno is not None else ""
|
||||
# Generate URL pointing to the source file like
|
||||
# https://github.com/django-components/django-components/blob/master/src/django_components/components/dynamic.py#L8
|
||||
url = f"{repo_url}/{branch_path}/{relative_filepath}{lineno_hash}"
|
||||
|
||||
# Open in new tab
|
||||
html = f'\n\n<a href="{url}" target="_blank">See source code</a>\n\n'
|
||||
|
||||
return html
|
49
0.139.1/scripts/mkdocs_util.py
Normal file
49
0.139.1/scripts/mkdocs_util.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
"""Utilities for interacting with MkDocs configuration."""
|
||||
|
||||
from functools import lru_cache
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Union
|
||||
|
||||
import griffe
|
||||
import yaml # type: ignore[import-untyped]
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def load_config() -> Dict:
|
||||
mkdocs_config_str = Path("mkdocs.yml").read_text()
|
||||
# NOTE: Use BaseLoader to avoid resolving tags like `!ENV`
|
||||
# See https://stackoverflow.com/questions/45966633/yaml-error-could-not-determine-a-constructor-for-the-tag
|
||||
mkdocs_config = yaml.load(mkdocs_config_str, yaml.BaseLoader)
|
||||
return mkdocs_config
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def find_plugin(name: str) -> Optional[Dict]:
|
||||
config = load_config()
|
||||
plugins: List[Union[str, Dict[str, Dict]]] = config.get("plugins", [])
|
||||
if not plugins:
|
||||
return None
|
||||
|
||||
for plugin in plugins:
|
||||
if isinstance(plugin, str):
|
||||
plugin = {plugin: {}}
|
||||
plugin_name, plugin_conf = list(plugin.items())[0]
|
||||
if plugin_name == name:
|
||||
return plugin_conf
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_mkdocstrings_plugin_handler_options() -> Optional[Dict]:
|
||||
plugin = find_plugin("mkdocstrings")
|
||||
if plugin is None:
|
||||
return None
|
||||
|
||||
return plugin.get("handlers", {}).get("python", {}).get("options", {})
|
||||
|
||||
|
||||
def import_object(obj: griffe.Object):
|
||||
module = import_module(obj.module.path)
|
||||
runtime_obj = getattr(module, obj.name)
|
||||
return runtime_obj
|
1160
0.139.1/scripts/reference.py
Normal file
1160
0.139.1/scripts/reference.py
Normal file
File diff suppressed because it is too large
Load diff
3
0.139.1/scripts/setup.py
Normal file
3
0.139.1/scripts/setup.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Allow us to use `djc_py` / `djc_python` code blocks.
|
||||
# Importing this package automatically registers the `djc_py` lexer onto Pygments.
|
||||
import pygments_djc # noqa: F401
|
Loading…
Add table
Add a link
Reference in a new issue