Mercurial > hg
comparison contrib/genosxversion.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 197e7326b8b8 |
children | 148d177a4f2d |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
5 import os | 5 import os |
6 import subprocess | 6 import subprocess |
7 import sys | 7 import sys |
8 | 8 |
9 # Always load hg libraries from the hg we can find on $PATH. | 9 # Always load hg libraries from the hg we can find on $PATH. |
10 hglib = subprocess.check_output( | 10 hglib = subprocess.check_output(['hg', 'debuginstall', '-T', '{hgmodules}']) |
11 ['hg', 'debuginstall', '-T', '{hgmodules}']) | |
12 sys.path.insert(0, os.path.dirname(hglib)) | 11 sys.path.insert(0, os.path.dirname(hglib)) |
13 | 12 |
14 from mercurial import util | 13 from mercurial import util |
15 | 14 |
16 ap = argparse.ArgumentParser() | 15 ap = argparse.ArgumentParser() |
17 ap.add_argument('--paranoid', | 16 ap.add_argument( |
18 action='store_true', | 17 '--paranoid', |
19 help=("Be paranoid about how version numbers compare and " | 18 action='store_true', |
20 "produce something that's more likely to sort " | 19 help=( |
21 "reasonably.")) | 20 "Be paranoid about how version numbers compare and " |
21 "produce something that's more likely to sort " | |
22 "reasonably." | |
23 ), | |
24 ) | |
22 ap.add_argument('--selftest', action='store_true', help='Run self-tests.') | 25 ap.add_argument('--selftest', action='store_true', help='Run self-tests.') |
23 ap.add_argument('versionfile', help='Path to a valid mercurial __version__.py') | 26 ap.add_argument('versionfile', help='Path to a valid mercurial __version__.py') |
27 | |
24 | 28 |
25 def paranoidver(ver): | 29 def paranoidver(ver): |
26 """Given an hg version produce something that distutils can sort. | 30 """Given an hg version produce something that distutils can sort. |
27 | 31 |
28 Some Mac package management systems use distutils code in order to | 32 Some Mac package management systems use distutils code in order to |
106 extra = '+' + extra | 110 extra = '+' + extra |
107 else: | 111 else: |
108 extra = '' | 112 extra = '' |
109 return '%d.%d.%d%s' % (major, minor, micro, extra) | 113 return '%d.%d.%d%s' % (major, minor, micro, extra) |
110 | 114 |
115 | |
111 def main(argv): | 116 def main(argv): |
112 opts = ap.parse_args(argv[1:]) | 117 opts = ap.parse_args(argv[1:]) |
113 if opts.selftest: | 118 if opts.selftest: |
114 import doctest | 119 import doctest |
120 | |
115 doctest.testmod() | 121 doctest.testmod() |
116 return | 122 return |
117 with open(opts.versionfile) as f: | 123 with open(opts.versionfile) as f: |
118 for l in f: | 124 for l in f: |
119 if l.startswith('version = b'): | 125 if l.startswith('version = b'): |
120 # version number is entire line minus the quotes | 126 # version number is entire line minus the quotes |
121 ver = l[len('version = b') + 1:-2] | 127 ver = l[len('version = b') + 1 : -2] |
122 break | 128 break |
123 if opts.paranoid: | 129 if opts.paranoid: |
124 print(paranoidver(ver)) | 130 print(paranoidver(ver)) |
125 else: | 131 else: |
126 print(ver) | 132 print(ver) |
127 | 133 |
134 | |
128 if __name__ == '__main__': | 135 if __name__ == '__main__': |
129 main(sys.argv) | 136 main(sys.argv) |