| c2e3fba1 | 03-May-2022 |
Patrick Sanan <patrick.sanan@gmail.com> |
Docs: Fix man page .seealso entries missing spaces after commas
```python
import os import re import fileinput
START_PATTERN = re.compile(r"^( *\.seealso:? )(.*$)") FIX_PATTERN = re.compile(r",([^
Docs: Fix man page .seealso entries missing spaces after commas
```python
import os import re import fileinput
START_PATTERN = re.compile(r"^( *\.seealso:? )(.*$)") FIX_PATTERN = re.compile(r",([^ $\n])")
def _fix_comma(matchobj): return "`, `%s" % matchobj.group(1)
def process_file(filename_full): """ Find/fix commas w/o trailing spaces or newlines in .seealso blocks """ with fileinput.FileInput(filename_full, inplace=True) as the_file: in_block = False for line in the_file: line_stripped = line.strip() # end ".seealso blocks" on a blank line or C-style comment close if not line_stripped: in_block = False elif line_stripped.endswith("*/"): in_block = False else: match = re.match(START_PATTERN, line) # not stripped line if match: in_block = True if in_block: if re.search(FIX_PATTERN, line): line_fixed = re.sub(FIX_PATTERN, _fix_comma, line) print(line_fixed, end="") # prints to file else: print(line, end="") # prints to file else: print(line, end="") # prints to file
BASE_DIRS = ["src", "include"] EXT = [".c", ".cxx", ".cpp", ".cu", ".h", ".hpp", ".hxx"] EXCLUDE_DIRS = ["tests", "tutorials", "ftn-auto", "ftn-custom", "benchmarks"]
def main(): """ Process files in local tree(s) """ for base in BASE_DIRS: for root, dirs, files in os.walk(base): for filename in files: if os.path.splitext(filename)[1] in EXT: filename_full = os.path.join(root, filename) process_file(filename_full) for exclude_dir in EXCLUDE_DIRS: if exclude_dir in dirs: dirs.remove(exclude_dir)
if __name__ == "__main__": main() ```
show more ...
|