annotate tests/testlib/check-compat-strings.py @ 6931:237f99ee3d64 stable

tests: remove leading spaces in `hg help` output, run only on Mercurial 6.9+ Core decided to remove a lot of leading spaces in docstrings to support Python 3.13, see 51057ab0dffa for details.
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 11 Nov 2024 10:39:57 +0400
parents 73cd416a1653
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5350
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
1 #!/usr/bin/env python
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
2 """
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
3 This script finds compatibility-related comments with a node hash specified
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
4 in all files in a given directory (. by default) and looks up the hash in a
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
5 repo (~/hg by default) to determine if each of the comments is correct and,
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
6 if not, it suggests the correct release. This can prevent accidentally
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
7 removing a piece of code that was misattributed to a different (earlier)
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
8 release of core hg.
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
9
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
10 Usage: $0 WDIR HGREPO where WDIR is usually evolve/hgext3rd/ and HGREPO is
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
11 the place with core Mercurial repo (not just checkout). Said repo has to be
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
12 sufficiently up-to-date, otherwise this script may not work correctly.
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
13 """
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
14
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
15 from __future__ import print_function
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
16
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
17 import argparse
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
18 import os
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
19 import re
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
20 from subprocess import check_output
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
21
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
22 def grepall(workdir, linere):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
23 for root, dirs, files in os.walk(workdir):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
24 for fname in files:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
25 if not fname.endswith('.py'):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
26 continue
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
27 path = os.path.join(root, fname)
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
28 with open(path, 'r') as src:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
29 for lineno, line in enumerate(src, 1):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
30 for groups in linere.findall(line):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
31 yield path, lineno, line, groups
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
32
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
33 def main():
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
34 ap = argparse.ArgumentParser()
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
35 ap.add_argument('workdir', nargs='?', default='.')
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
36 ap.add_argument('hgdir', nargs='?', default=os.path.expanduser('~/hg'))
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
37
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
38 opts = ap.parse_args()
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
39
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
40 linere = re.compile(r'hg <= ([0-9.]+) \(([0-9a-f+]+)\)')
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
41 basecmd = ['hg', '--cwd', opts.hgdir, 'log', '-T', '{tags}']
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
42 hgenv = {'HGPLAIN': '1', 'HGENCODING': 'UTF-8'}
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
43 relcache = {}
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
44
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
45 for path, lineno, line, match in grepall(opts.workdir, linere):
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
46 expected, revset = match
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
47
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
48 if revset not in relcache:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
49 tagrevset = 'max(tag("re:^[0-9]\\.[0-9]$") - (%s)::)' % revset
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
50 cmd = basecmd + ['-r', tagrevset]
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
51 relcache[revset] = check_output(cmd, env=hgenv).decode('UTF-8')
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
52
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
53 lastrel = relcache[revset]
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
54
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
55 if lastrel != expected:
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
56 print('%s:%d:%s' % (path, lineno, line.rstrip('\r\n')))
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
57 print('\\ actual last major release without %s is %s'
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
58 % (revset, lastrel))
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
59 print()
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
60
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
61 if __name__ == '__main__':
73cd416a1653 tests: replace check-compat-strings.sh with a Python script
Anton Shestakov <av6@dwimlabs.net>
parents:
diff changeset
62 main()