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