changeset 43691:47ef023d0165

black: blacken scripts These scripts weren't blackened. I found these as part of adding script checking to test-check-format.t. # skip-blame black Differential Revision: https://phab.mercurial-scm.org/D7446
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 16 Nov 2019 11:53:47 -0800
parents 15cccbacd5ce
children 2d8d4e08c493
files doc/docchecker doc/runrst hgweb.cgi i18n/hggettext i18n/posplit tests/f tests/hghave
diffstat 7 files changed, 159 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/doc/docchecker	Sat Nov 16 11:59:22 2019 -0800
+++ b/doc/docchecker	Sat Nov 16 11:53:47 2019 -0800
@@ -15,6 +15,7 @@
 
 try:
     import msvcrt
+
     msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
     msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
 except ImportError:
@@ -25,14 +26,18 @@
 leadingline = re.compile(br'(^\s*)(\S.*)$')
 
 checks = [
-  (br""":hg:`[^`]*'[^`]*`""",
-   b"""warning: please avoid nesting ' in :hg:`...`"""),
-  (br'\w:hg:`',
-   b'warning: please have a space before :hg:'),
-  (br"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
-   b'''warning: please use " instead of ' for hg ... "..."'''),
+    (
+        br""":hg:`[^`]*'[^`]*`""",
+        b"""warning: please avoid nesting ' in :hg:`...`""",
+    ),
+    (br'\w:hg:`', b'warning: please have a space before :hg:'),
+    (
+        br"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
+        b'''warning: please use " instead of ' for hg ... "..."''',
+    ),
 ]
 
+
 def check(line):
     messages = []
     for match, msg in checks:
@@ -43,6 +48,7 @@
         for msg in messages:
             stdout.write(b'%s\n' % msg)
 
+
 def work(file):
     (llead, lline) = (b'', b'')
 
@@ -55,8 +61,8 @@
             continue
 
         lead, line = match.group(1), match.group(2)
-        if (lead == llead):
-            if (lline != b''):
+        if lead == llead:
+            if lline != b'':
                 lline += b' ' + line
             else:
                 lline = line
@@ -65,6 +71,7 @@
             (llead, lline) = (lead, line)
     check(lline)
 
+
 def main():
     for f in sys.argv[1:]:
         try:
@@ -73,4 +80,5 @@
         except BaseException as e:
             sys.stdout.write(r"failed to process %s: %s\n" % (f, e))
 
+
 main()
--- a/doc/runrst	Sat Nov 16 11:59:22 2019 -0800
+++ b/doc/runrst	Sat Nov 16 11:53:47 2019 -0800
@@ -15,18 +15,24 @@
 from __future__ import absolute_import
 
 import sys
+
 try:
     import docutils.core as core
     import docutils.nodes as nodes
     import docutils.utils as utils
     import docutils.parsers.rst.roles as roles
 except ImportError:
-    sys.stderr.write("abort: couldn't generate documentation: docutils "
-                     "module is missing\n")
-    sys.stderr.write("please install python-docutils or see "
-                     "http://docutils.sourceforge.net/\n")
+    sys.stderr.write(
+        "abort: couldn't generate documentation: docutils "
+        "module is missing\n"
+    )
+    sys.stderr.write(
+        "please install python-docutils or see "
+        "http://docutils.sourceforge.net/\n"
+    )
     sys.exit(-1)
 
+
 def role_hg(name, rawtext, text, lineno, inliner, options=None, content=None):
     text = "hg " + utils.unescape(text)
     linktext = nodes.literal(rawtext, text)
@@ -46,10 +52,10 @@
             refuri = "hg.1.html#%s" % args[1]
         else:
             refuri = "hg.1.html#%s" % args[0]
-    node = nodes.reference(rawtext, '', linktext,
-                           refuri=refuri)
+    node = nodes.reference(rawtext, '', linktext, refuri=refuri)
     return [node], []
 
+
 roles.register_local_role("hg", role_hg)
 
 if __name__ == "__main__":
--- a/hgweb.cgi	Sat Nov 16 11:59:22 2019 -0800
+++ b/hgweb.cgi	Sat Nov 16 11:53:47 2019 -0800
@@ -8,12 +8,15 @@
 
 # Uncomment and adjust if Mercurial is not installed system-wide
 # (consult "installed modules" path from 'hg debuginstall'):
-#import sys; sys.path.insert(0, "/path/to/python/lib")
+# import sys; sys.path.insert(0, "/path/to/python/lib")
 
 # Uncomment to send python tracebacks to the browser if an error occurs:
-#import cgitb; cgitb.enable()
+# import cgitb; cgitb.enable()
+
+from mercurial import demandimport
 
-from mercurial import demandimport; demandimport.enable()
+demandimport.enable()
 from mercurial.hgweb import hgweb, wsgicgi
+
 application = hgweb(config)
 wsgicgi.launch(application)
--- a/i18n/hggettext	Sat Nov 16 11:59:22 2019 -0800
+++ b/i18n/hggettext	Sat Nov 16 11:53:47 2019 -0800
@@ -57,18 +57,22 @@
 
 
 def poentry(path, lineno, s):
-    return ('#: %s:%d\n' % (path, lineno) +
-            'msgid %s\n' % normalize(s) +
-            'msgstr ""\n')
+    return (
+        '#: %s:%d\n' % (path, lineno)
+        + 'msgid %s\n' % normalize(s)
+        + 'msgstr ""\n'
+    )
+
 
 doctestre = re.compile(r'^ +>>> ', re.MULTILINE)
 
+
 def offset(src, doc, name, lineno, default):
     """Compute offset or issue a warning on stdout."""
     # remove doctest part, in order to avoid backslash mismatching
     m = doctestre.search(doc)
     if m:
-        doc = doc[:m.start()]
+        doc = doc[: m.start()]
 
     # Backslashes in doc appear doubled in src.
     end = src.find(doc.replace('\\', '\\\\'))
@@ -76,9 +80,11 @@
         # This can happen if the docstring contains unnecessary escape
         # sequences such as \" in a triple-quoted string. The problem
         # is that \" is turned into " and so doc wont appear in src.
-        sys.stderr.write("%s:%d:warning:"
-                         " unknown docstr offset, assuming %d lines\n"
-                         % (name, lineno, default))
+        sys.stderr.write(
+            "%s:%d:warning:"
+            " unknown docstr offset, assuming %d lines\n"
+            % (name, lineno, default)
+        )
         return default
     else:
         return src.count('\n', 0, end)
@@ -121,7 +127,7 @@
 
     for func, rstrip in functions:
         if func.__doc__:
-            docobj = func # this might be a proxy to provide formatted doc
+            docobj = func  # this might be a proxy to provide formatted doc
             func = getattr(func, '_origfunc', func)
             funcmod = inspect.getmodule(func)
             extra = ''
@@ -155,7 +161,9 @@
     # accidentally import and extract strings from a Mercurial
     # installation mentioned in PYTHONPATH.
     sys.path.insert(0, os.getcwd())
-    from mercurial import demandimport; demandimport.enable()
+    from mercurial import demandimport
+
+    demandimport.enable()
     for path in sys.argv[1:]:
         if path.endswith('.txt'):
             rawtext(path)
--- a/i18n/posplit	Sat Nov 16 11:59:22 2019 -0800
+++ b/i18n/posplit	Sat Nov 16 11:53:47 2019 -0800
@@ -11,6 +11,7 @@
 import re
 import sys
 
+
 def addentry(po, entry, cache):
     e = cache.get(entry.msgid)
     if e:
@@ -27,6 +28,7 @@
         po.append(entry)
         cache[entry.msgid] = entry
 
+
 def mkentry(orig, delta, msgid, msgstr):
     entry = polib.POEntry()
     entry.merge(orig)
@@ -35,13 +37,14 @@
     entry.occurrences = [(p, int(l) + delta) for (p, l) in orig.occurrences]
     return entry
 
+
 if __name__ == "__main__":
     po = polib.pofile(sys.argv[1])
 
     cache = {}
     entries = po[:]
     po[:] = []
-    findd = re.compile(r' *\.\. (\w+)::') # for finding directives
+    findd = re.compile(r' *\.\. (\w+)::')  # for finding directives
     for entry in entries:
         msgids = entry.msgid.split(u'\n\n')
         if entry.msgstr:
@@ -65,7 +68,7 @@
                 newentry = mkentry(entry, delta, msgid, msgstr)
                 mdirective = findd.match(msgid)
                 if mdirective:
-                    if not msgid[mdirective.end():].rstrip():
+                    if not msgid[mdirective.end() :].rstrip():
                         # only directive, nothing to translate here
                         delta += 2
                         continue
@@ -77,8 +80,10 @@
                             continue
                         else:
                             # lines following directly, unexpected
-                            print('Warning: text follows line with directive'
-                                  ' %s' % directive)
+                            print(
+                                'Warning: text follows line with directive'
+                                ' %s' % directive
+                            )
                     comment = 'do not translate: .. %s::' % directive
                     if not newentry.comment:
                         newentry.comment = comment
--- a/tests/f	Sat Nov 16 11:59:22 2019 -0800
+++ b/tests/f	Sat Nov 16 11:53:47 2019 -0800
@@ -34,14 +34,18 @@
 import sys
 
 # Python 3 adapters
-ispy3 = (sys.version_info[0] >= 3)
+ispy3 = sys.version_info[0] >= 3
 if ispy3:
+
     def iterbytes(s):
         for i in range(len(s)):
-            yield s[i:i + 1]
+            yield s[i : i + 1]
+
+
 else:
     iterbytes = iter
 
+
 def visit(opts, filenames, outfile):
     """Process filenames in the way specified in opts, writing output to
     outfile."""
@@ -88,21 +92,26 @@
             if opts.newer:
                 # mtime might be in whole seconds so newer file might be same
                 if stat.st_mtime >= os.stat(opts.newer).st_mtime:
-                    facts.append(b'newer than %s' % opts.newer.encode(
-                        'utf8', 'replace'))
+                    facts.append(
+                        b'newer than %s' % opts.newer.encode('utf8', 'replace')
+                    )
                 else:
-                    facts.append(b'older than %s' % opts.newer.encode(
-                        'utf8', 'replace'))
+                    facts.append(
+                        b'older than %s' % opts.newer.encode('utf8', 'replace')
+                    )
         if opts.md5 and content is not None:
             h = hashlib.md5(content)
-            facts.append(b'md5=%s' % binascii.hexlify(h.digest())[:opts.bytes])
+            facts.append(b'md5=%s' % binascii.hexlify(h.digest())[: opts.bytes])
         if opts.sha1 and content is not None:
             h = hashlib.sha1(content)
-            facts.append(b'sha1=%s' % binascii.hexlify(h.digest())[:opts.bytes])
+            facts.append(
+                b'sha1=%s' % binascii.hexlify(h.digest())[: opts.bytes]
+            )
         if opts.sha256 and content is not None:
             h = hashlib.sha256(content)
-            facts.append(b'sha256=%s' %
-                         binascii.hexlify(h.digest())[:opts.bytes])
+            facts.append(
+                b'sha256=%s' % binascii.hexlify(h.digest())[: opts.bytes]
+            )
         if isstdin:
             outfile.write(b', '.join(facts) + b'\n')
         elif facts:
@@ -114,21 +123,25 @@
             if not islink:
                 if opts.lines:
                     if opts.lines >= 0:
-                        chunk = b''.join(chunk.splitlines(True)[:opts.lines])
+                        chunk = b''.join(chunk.splitlines(True)[: opts.lines])
                     else:
-                        chunk = b''.join(chunk.splitlines(True)[opts.lines:])
+                        chunk = b''.join(chunk.splitlines(True)[opts.lines :])
                 if opts.bytes:
                     if opts.bytes >= 0:
-                        chunk = chunk[:opts.bytes]
+                        chunk = chunk[: opts.bytes]
                     else:
-                        chunk = chunk[opts.bytes:]
+                        chunk = chunk[opts.bytes :]
             if opts.hexdump:
                 for i in range(0, len(chunk), 16):
-                    s = chunk[i:i + 16]
-                    outfile.write(b'%04x: %-47s |%s|\n' %
-                                  (i, b' '.join(
-                                      b'%02x' % ord(c) for c in iterbytes(s)),
-                                   re.sub(b'[^ -~]', b'.', s)))
+                    s = chunk[i : i + 16]
+                    outfile.write(
+                        b'%04x: %-47s |%s|\n'
+                        % (
+                            i,
+                            b' '.join(b'%02x' % ord(c) for c in iterbytes(s)),
+                            re.sub(b'[^ -~]', b'.', s),
+                        )
+                    )
             if opts.dump:
                 if not quiet:
                     outfile.write(b'>>>\n')
@@ -142,36 +155,60 @@
             assert not isstdin
             visit(opts, dirfiles, outfile)
 
+
 if __name__ == "__main__":
     parser = optparse.OptionParser("%prog [options] [filenames]")
-    parser.add_option("-t", "--type", action="store_true",
-                      help="show file type (file or directory)")
-    parser.add_option("-m", "--mode", action="store_true",
-                      help="show file mode")
-    parser.add_option("-l", "--links", action="store_true",
-                      help="show number of links")
-    parser.add_option("-s", "--size", action="store_true",
-                      help="show size of file")
-    parser.add_option("-n", "--newer", action="store",
-                      help="check if file is newer (or same)")
-    parser.add_option("-r", "--recurse", action="store_true",
-                      help="recurse into directories")
-    parser.add_option("-S", "--sha1", action="store_true",
-                      help="show sha1 hash of the content")
-    parser.add_option("", "--sha256", action="store_true",
-                      help="show sha256 hash of the content")
-    parser.add_option("-M", "--md5", action="store_true",
-                      help="show md5 hash of the content")
-    parser.add_option("-D", "--dump", action="store_true",
-                      help="dump file content")
-    parser.add_option("-H", "--hexdump", action="store_true",
-                      help="hexdump file content")
-    parser.add_option("-B", "--bytes", type="int",
-                      help="number of characters to dump")
-    parser.add_option("-L", "--lines", type="int",
-                      help="number of lines to dump")
-    parser.add_option("-q", "--quiet", action="store_true",
-                      help="no default output")
+    parser.add_option(
+        "-t",
+        "--type",
+        action="store_true",
+        help="show file type (file or directory)",
+    )
+    parser.add_option(
+        "-m", "--mode", action="store_true", help="show file mode"
+    )
+    parser.add_option(
+        "-l", "--links", action="store_true", help="show number of links"
+    )
+    parser.add_option(
+        "-s", "--size", action="store_true", help="show size of file"
+    )
+    parser.add_option(
+        "-n", "--newer", action="store", help="check if file is newer (or same)"
+    )
+    parser.add_option(
+        "-r", "--recurse", action="store_true", help="recurse into directories"
+    )
+    parser.add_option(
+        "-S",
+        "--sha1",
+        action="store_true",
+        help="show sha1 hash of the content",
+    )
+    parser.add_option(
+        "",
+        "--sha256",
+        action="store_true",
+        help="show sha256 hash of the content",
+    )
+    parser.add_option(
+        "-M", "--md5", action="store_true", help="show md5 hash of the content"
+    )
+    parser.add_option(
+        "-D", "--dump", action="store_true", help="dump file content"
+    )
+    parser.add_option(
+        "-H", "--hexdump", action="store_true", help="hexdump file content"
+    )
+    parser.add_option(
+        "-B", "--bytes", type="int", help="number of characters to dump"
+    )
+    parser.add_option(
+        "-L", "--lines", type="int", help="number of lines to dump"
+    )
+    parser.add_option(
+        "-q", "--quiet", action="store_true", help="no default output"
+    )
     (opts, filenames) = parser.parse_args(sys.argv[1:])
     if not filenames:
         filenames = ['-']
--- a/tests/hghave	Sat Nov 16 11:59:22 2019 -0800
+++ b/tests/hghave	Sat Nov 16 11:53:47 2019 -0800
@@ -13,11 +13,13 @@
 
 checks = hghave.checks
 
+
 def list_features():
     for name, feature in sorted(checks.items()):
         desc = feature[1]
         print(name + ':', desc)
 
+
 def test_features():
     failed = 0
     for name, feature in checks.items():
@@ -29,11 +31,15 @@
             failed += 1
     return failed
 
+
 parser = optparse.OptionParser("%prog [options] [features]")
-parser.add_option("--test-features", action="store_true",
-                  help="test available features")
-parser.add_option("--list-features", action="store_true",
-                  help="list available features")
+parser.add_option(
+    "--test-features", action="store_true", help="test available features"
+)
+parser.add_option(
+    "--list-features", action="store_true", help="list available features"
+)
+
 
 def _loadaddon():
     if 'TESTDIR' in os.environ:
@@ -49,13 +55,16 @@
     sys.path.insert(0, path)
     try:
         import hghaveaddon
+
         assert hghaveaddon  # silence pyflakes
     except BaseException as inst:
-        sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
-                         % (path, inst))
+        sys.stderr.write(
+            'failed to import hghaveaddon.py from %r: %s\n' % (path, inst)
+        )
         sys.exit(2)
     sys.path.pop(0)
 
+
 if __name__ == '__main__':
     options, args = parser.parse_args()
     _loadaddon()