Debian Codegraph @

test/integration/targets/collection/update-ignore.py

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/env python3
2 """Rewrite a sanity ignore file to expand Python versions for import ignores and write the file out with the correct Ansible version in the name."""
3 from __future__ import annotations
4
5 import os
6 import sys
7
8 from ansible import release
9
10
11 def main():
12 ansible_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(release.__file__))))
13 source_root = os.path.join(ansible_root, 'test', 'lib')
14
15 sys.path.insert(0, source_root)
16
17 from ansible_test._internal import constants
18
19 src_path = 'tests/sanity/ignore.txt'
20
21 if not os.path.exists(src_path):
22 print(f'Skipping updates on non-existent ignore file: {src_path}')
23 return
24
25 directory = os.path.dirname(src_path)
26 name, ext = os.path.splitext(os.path.basename(src_path))
27 major_minor = '.'.join(release.__version__.split('.')[:2])
28 dst_path = os.path.join(directory, f'{name}-{major_minor}{ext}')
29
30 with open(src_path) as src_file:
31 src_lines = src_file.read().splitlines()
32
33 dst_lines = []
34
35 for line in src_lines:
36 path, rule = line.split(' ')
37
38 if rule != 'import':
39 dst_lines.append(line)
40 continue
41
42 if path.startswith('plugins/module'):
43 python_versions = constants.SUPPORTED_PYTHON_VERSIONS
44 else:
45 python_versions = constants.CONTROLLER_PYTHON_VERSIONS
46
47 for python_version in python_versions:
48 dst_lines.append(f'{line}-{python_version}')
49
50 ignores = '\n'.join(dst_lines) + '\n'
51
52 with open(dst_path, 'w') as dst_file:
53 dst_file.write(ignores)
54
55
56 if __name__ == '__main__':
57 main()