Document the black shim a touch

This commit is contained in:
Reid 'arrdem' McKenzie 2021-09-02 22:24:50 -06:00
parent c20fdde98c
commit 4ce35091eb

View file

@ -1,10 +1,9 @@
"""A shim to black which knows how to tee output.""" """A shim to black which knows how to tee output for --output-file."""
import argparse import argparse
from contextlib import contextmanager
import sys import sys
from black import patched_main from black import patched_main, nullcontext
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -12,7 +11,7 @@ parser.add_argument("--output-file", default=None)
class Tee(object): class Tee(object):
"""Tee all I/O to a file and stdout.""" """Something that looks like a File/Writeable but does teed writes."""
def __init__(self, name, mode): def __init__(self, name, mode):
self._file = open(name, mode) self._file = open(name, mode)
@ -38,11 +37,6 @@ class Tee(object):
self._file.close() self._file.close()
@contextmanager
def nullctx():
yield
if __name__ == "__main__": if __name__ == "__main__":
opts, args = parser.parse_known_args() opts, args = parser.parse_known_args()
@ -50,7 +44,7 @@ if __name__ == "__main__":
print("Teeig output....") print("Teeig output....")
ctx = Tee(opts.output_file, "w") ctx = Tee(opts.output_file, "w")
else: else:
ctx = nullctx() ctx = nullcontext()
with ctx: with ctx:
sys.argv = [sys.argv[0]] + args sys.argv = [sys.argv[0]] + args