From a96e45e0399f816982e4a873717d5da796576afd Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Wed, 25 Dec 2024 20:36:56 +1300 Subject: [PATCH] refine reformat_yaml Changes: * keep line ending in description value when it ends in `. ! : ; ,' * add comments on offending regexps * remove multiple whitespaces from offending whitespaces * do not check offenders in EXAMPLES --- andeboxlib/actions/reformat_yaml.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/andeboxlib/actions/reformat_yaml.py b/andeboxlib/actions/reformat_yaml.py index 465176b..2ec3aa4 100644 --- a/andeboxlib/actions/reformat_yaml.py +++ b/andeboxlib/actions/reformat_yaml.py @@ -24,7 +24,7 @@ def fix_desc_value(line: str) -> str: line = line[0].upper() + line[1:] if line.endswith(".)"): return f"{line[:-2]})." - if line.endswith("."): + if line.endswith((".", "!", ":", ";", ",")): return line return f"{line}." @@ -86,14 +86,13 @@ def get_processor(variable, in_doc_fragments=False): re.compile(exp) for exp in [ r"`", - r"\bi\.e\b", - r"\be\.g\.?\b", - r"[^/]etc\b", - r"\bvia\b", + r"\bi\.e\b", # i.e + r"\be\.g\.?\b", # e.g. + r"[^/]etc\b", # etc, but not /etc + r"\bvia\b", # via r"\bversus\b", r"\bvs\.?\b", r"\bversa\b", - r"\S\s\s+\S", ] ] @@ -206,7 +205,7 @@ def reformat_yaml_in_python_file(self, file_path, offenders, dry_run): outbound_content = self.process_yaml_block( quoted_content, get_processor(in_variable), dry_run ) - if offenders: + if offenders and in_variable != "EXAMPLES": report_offenders(outbound_content, first_line_no) updated_lines.extend(outbound_content) updated_lines.append('"""')