From 10c1831aad1c5b6d4815534e93a4f398af4d3378 Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 16 Jun 2020 15:31:15 +0200 Subject: [PATCH] Start adding fmtwidth helper --- docs/pylib/fmtwidth.py | 38 ++++++++++++++++++++++++++++++++++++++ docs/requirements.txt | 1 - 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 docs/pylib/fmtwidth.py diff --git a/docs/pylib/fmtwidth.py b/docs/pylib/fmtwidth.py new file mode 100644 index 0000000000..b5a0714fb1 --- /dev/null +++ b/docs/pylib/fmtwidth.py @@ -0,0 +1,38 @@ +#!/usr/bin python +# -*- coding: utf-8 -*- + +""" +Format given files to a max width. + +""" +import glob +import textwrap +import argparse + +if __name__ == "__main__": + + parser = argparse.ArgumentParser() + + parser.add_argument("files") + parser.add_argument("-w", '--width', dest="width", type=int, default=79) + + args = parser.parse_args() + + filepaths = glob.glob(args.files) + + wrapper = textwrap.TextWrapper( + width=args.width, + break_long_words=False, + expand_tabs=True, + ) + + count = 0 + for filepath in filepaths: + with open(filepath, 'r') as fil: + txt = fil.read() + txt = "\n".join(wrapper.wrap(txt)) + with open(filepath, 'w') as fil: + fil.write(txt) + count += 1 + + print(f"Wrapped {count} files.") diff --git a/docs/requirements.txt b/docs/requirements.txt index 1d25af7679..1195df76d3 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,7 +2,6 @@ sphinx==2.4.4 sphinx-multiversion==0.1.1 -lunr==0.5.8 # recommonmark custom branch with evennia-specific fixes git+https://github.com/evennia/recommonmark.git@evennia-mods#egg=recommonmark