Mercurial > hg
comparison doc/docchecker @ 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 | 9bfbb9fc5871 |
children | c102b704edb5 |
comparison
equal
deleted
inserted
replaced
43690:15cccbacd5ce | 43691:47ef023d0165 |
---|---|
13 import re | 13 import re |
14 import sys | 14 import sys |
15 | 15 |
16 try: | 16 try: |
17 import msvcrt | 17 import msvcrt |
18 | |
18 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) | 19 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
19 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) | 20 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
20 except ImportError: | 21 except ImportError: |
21 pass | 22 pass |
22 | 23 |
23 stdout = getattr(sys.stdout, 'buffer', sys.stdout) | 24 stdout = getattr(sys.stdout, 'buffer', sys.stdout) |
24 | 25 |
25 leadingline = re.compile(br'(^\s*)(\S.*)$') | 26 leadingline = re.compile(br'(^\s*)(\S.*)$') |
26 | 27 |
27 checks = [ | 28 checks = [ |
28 (br""":hg:`[^`]*'[^`]*`""", | 29 ( |
29 b"""warning: please avoid nesting ' in :hg:`...`"""), | 30 br""":hg:`[^`]*'[^`]*`""", |
30 (br'\w:hg:`', | 31 b"""warning: please avoid nesting ' in :hg:`...`""", |
31 b'warning: please have a space before :hg:'), | 32 ), |
32 (br"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""", | 33 (br'\w:hg:`', b'warning: please have a space before :hg:'), |
33 b'''warning: please use " instead of ' for hg ... "..."'''), | 34 ( |
35 br"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""", | |
36 b'''warning: please use " instead of ' for hg ... "..."''', | |
37 ), | |
34 ] | 38 ] |
39 | |
35 | 40 |
36 def check(line): | 41 def check(line): |
37 messages = [] | 42 messages = [] |
38 for match, msg in checks: | 43 for match, msg in checks: |
39 if re.search(match, line): | 44 if re.search(match, line): |
40 messages.append(msg) | 45 messages.append(msg) |
41 if messages: | 46 if messages: |
42 stdout.write(b'%s\n' % line) | 47 stdout.write(b'%s\n' % line) |
43 for msg in messages: | 48 for msg in messages: |
44 stdout.write(b'%s\n' % msg) | 49 stdout.write(b'%s\n' % msg) |
50 | |
45 | 51 |
46 def work(file): | 52 def work(file): |
47 (llead, lline) = (b'', b'') | 53 (llead, lline) = (b'', b'') |
48 | 54 |
49 for line in file: | 55 for line in file: |
53 check(lline) | 59 check(lline) |
54 (llead, lline) = (b'', b'') | 60 (llead, lline) = (b'', b'') |
55 continue | 61 continue |
56 | 62 |
57 lead, line = match.group(1), match.group(2) | 63 lead, line = match.group(1), match.group(2) |
58 if (lead == llead): | 64 if lead == llead: |
59 if (lline != b''): | 65 if lline != b'': |
60 lline += b' ' + line | 66 lline += b' ' + line |
61 else: | 67 else: |
62 lline = line | 68 lline = line |
63 else: | 69 else: |
64 check(lline) | 70 check(lline) |
65 (llead, lline) = (lead, line) | 71 (llead, lline) = (lead, line) |
66 check(lline) | 72 check(lline) |
73 | |
67 | 74 |
68 def main(): | 75 def main(): |
69 for f in sys.argv[1:]: | 76 for f in sys.argv[1:]: |
70 try: | 77 try: |
71 with open(f, 'rb') as file: | 78 with open(f, 'rb') as file: |
72 work(file) | 79 work(file) |
73 except BaseException as e: | 80 except BaseException as e: |
74 sys.stdout.write(r"failed to process %s: %s\n" % (f, e)) | 81 sys.stdout.write(r"failed to process %s: %s\n" % (f, e)) |
75 | 82 |
83 | |
76 main() | 84 main() |