X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/37a0020e073555ffe0921ec1356a27610aadcca4..e4b4fb02b91e0f5a60a9678604653aecedff513b:/docs/conf.py?ds=sidebyside diff --git a/docs/conf.py b/docs/conf.py index 575a140..9e03d05 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,7 +15,7 @@ from pathlib import Path import re import string -from typing import Callable, List, Optional, Pattern, Tuple, Set +from typing import Callable, Dict, List, Optional, Pattern, Tuple, Set from dataclasses import dataclass import logging @@ -99,7 +99,13 @@ def get_contents(section: DocSection) -> str: for lineno, line in enumerate(f, start=1): if lineno >= start_line and lineno < end_line: contents.append(line) - return "".join(contents) + result = "".join(contents) + # Let's make Prettier happy with the amount of trailing newlines in the sections. + if result.endswith("\n\n"): + result = result[:-1] + if not result.endswith("\n"): + result = result + "\n" + return result def get_sections_from_readme() -> List[DocSection]: @@ -159,18 +165,19 @@ def process_sections( It processes custom sections before the README generated sections so sections in the README can be overwritten with custom options. """ - processed_sections: Set[str] = set() + processed_sections: Dict[str, DocSection] = {} modified_files: Set[Path] = set() sections: List[DocSection] = custom_sections sections.extend(readme_sections) for section in sections: - LOG.info(f"Processing '{section.name}' from {section.src}") if section.name in processed_sections: - LOG.info( + LOG.warning( f"Skipping '{section.name}' from '{section.src}' as it is a duplicate" + f" of a custom section from '{processed_sections[section.name].src}'" ) continue + LOG.info(f"Processing '{section.name}' from '{section.src}'") target_path: Path = CURRENT_DIR / section.get_out_filename() if target_path in modified_files: LOG.warning( @@ -184,13 +191,11 @@ def process_sections( contents = fix_headers(contents) with open(target_path, "w", encoding="utf-8") as f: - if section.src.suffix == ".md": - f.write( - "[//]: # (NOTE: THIS FILE WAS AUTOGENERATED FROM" - f" {section.src})\n\n" - ) + if section.src.suffix == ".md" and section.src != target_path: + rel = section.src.resolve().relative_to(CURRENT_DIR.parent) + f.write(f'[//]: # "NOTE: THIS FILE WAS AUTOGENERATED FROM {rel}"\n\n') f.write(contents) - processed_sections.add(section.name) + processed_sections[section.name] = section modified_files.add(target_path) @@ -209,12 +214,11 @@ for sp in "abcfr": version = version.split(sp)[0] custom_sections = [ - DocSection("the_black_code_style", CURRENT_DIR / "the_black_code_style.md",), + DocSection("the_black_code_style", CURRENT_DIR / "the_black_code_style.md"), DocSection("editor_integration", CURRENT_DIR / "editor_integration.md"), DocSection("blackd", CURRENT_DIR / "blackd.md"), DocSection("black_primer", CURRENT_DIR / "black_primer.md"), DocSection("contributing_to_black", CURRENT_DIR / ".." / "CONTRIBUTING.md"), - DocSection("change_log", CURRENT_DIR / ".." / "CHANGES.md"), ] # Sphinx complains when there is a source file that isn't referenced in any of the docs. @@ -226,6 +230,7 @@ blocklisted_sections_from_readme = { "pragmatism", "testimonials", "used_by", + "change_log", } make_pypi_svg(release) @@ -309,7 +314,6 @@ html_theme_options = { "show_powered_by": True, "fixed_sidebar": True, "logo": "logo2.png", - "travis_button": True, }