Make doc generation a little smarter, update doc sections

This commit is contained in:
Łukasz Langa 2020-08-24 14:33:16 +02:00
parent fd5928c589
commit 5faabb5616
No known key found for this signature in database
GPG Key ID: B26995E310250568
3 changed files with 48 additions and 11 deletions

View File

@ -181,3 +181,4 @@ Multiple contributions by:
- Yazdan - Yazdan
- [Yngve Høiseth](mailto:yngve@hoiseth.net) - [Yngve Høiseth](mailto:yngve@hoiseth.net)
- [Yurii Karabas](mailto:1998uriyyo@gmail.com) - [Yurii Karabas](mailto:1998uriyyo@gmail.com)
- [Zac Hatfield-Dodds](mailto:zac@zhd.dev)

View File

@ -9,15 +9,44 @@
- re-implemented support for explicit trailing commas: now it works consistently within - re-implemented support for explicit trailing commas: now it works consistently within
any bracket pair, including nested structures (#1288 and duplicates) any bracket pair, including nested structures (#1288 and duplicates)
- reindent docstrings when reindenting code around it (#1053) - `Black` now reindents docstrings when reindenting code around it (#1053)
- show colored diffs (#1266) - `Black` now shows colored diffs (#1266)
- move to 'py3' tagged wheels (#1388) - `Black` is now packaged using 'py3' tagged wheels (#1388)
- remove deprecated `--py36` option (#1236) - `Black` now supports Python 3.8 code, e.g. star expressions in return statements
(#1121)
- add `--force-exclude` argument (#1032) - `Black` no longer normalizes capital R-string prefixes as those have a
community-accepted meaning (#1244)
- `Black` now uses exit code 2 when specified configuration file doesn't exit (#1361)
- `Black` now works on AWS Lambda (#1141)
- added `--force-exclude` argument (#1032)
- removed deprecated `--py36` option (#1236)
- fixed `--diff` output when EOF is encountered (#526)
- fixed `# fmt: off` handling around decorators (#560)
- fixed unstable formatting with some `# type: ignore` comments (#1113)
- fixed invalid removal on organizing brackets followed by indexing (#1575)
- introduced `black-primer`, a CI tool that allows us to run regression tests against
existing open source users of Black (#1402)
- introduced property-based fuzzing to our test suite based on Hypothesis and
Hypothersmith (#1566)
- implemented experimental and disabled by default long string rewrapping (#1132),
hidden under a `--experimental-string-processing` flag while it's being worked on;
this is an undocumented and unsupported feature, you lose Internet points for
depending on it (#1609)
#### Vim plugin #### Vim plugin

View File

@ -15,7 +15,7 @@
from pathlib import Path from pathlib import Path
import re import re
import string 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 from dataclasses import dataclass
import logging import logging
@ -99,7 +99,13 @@ def get_contents(section: DocSection) -> str:
for lineno, line in enumerate(f, start=1): for lineno, line in enumerate(f, start=1):
if lineno >= start_line and lineno < end_line: if lineno >= start_line and lineno < end_line:
contents.append(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]: 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 It processes custom sections before the README generated sections so sections in the
README can be overwritten with custom options. README can be overwritten with custom options.
""" """
processed_sections: Set[str] = set() processed_sections: Dict[str, DocSection] = {}
modified_files: Set[Path] = set() modified_files: Set[Path] = set()
sections: List[DocSection] = custom_sections sections: List[DocSection] = custom_sections
sections.extend(readme_sections) sections.extend(readme_sections)
for section in sections: for section in sections:
LOG.info(f"Processing '{section.name}' from {section.src}")
if section.name in processed_sections: if section.name in processed_sections:
LOG.info( LOG.warning(
f"Skipping '{section.name}' from '{section.src}' as it is a duplicate" f"Skipping '{section.name}' from '{section.src}' as it is a duplicate"
f" of a custom section from '{processed_sections[section.name].src}'"
) )
continue continue
LOG.info(f"Processing '{section.name}' from '{section.src}'")
target_path: Path = CURRENT_DIR / section.get_out_filename() target_path: Path = CURRENT_DIR / section.get_out_filename()
if target_path in modified_files: if target_path in modified_files:
LOG.warning( LOG.warning(
@ -188,7 +195,7 @@ def process_sections(
rel = section.src.resolve().relative_to(CURRENT_DIR.parent) rel = section.src.resolve().relative_to(CURRENT_DIR.parent)
f.write(f'[//]: # "NOTE: THIS FILE WAS AUTOGENERATED FROM {rel}"\n\n') f.write(f'[//]: # "NOTE: THIS FILE WAS AUTOGENERATED FROM {rel}"\n\n')
f.write(contents) f.write(contents)
processed_sections.add(section.name) processed_sections[section.name] = section
modified_files.add(target_path) modified_files.add(target_path)