Debian Codegraph @

test/integration/targets/ansible-test/venv-pythons.py

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/env python3
2 """Return target Python options for use with ansible-test."""
3 from __future__ import annotations
4
5 import argparse
6 import os
7 import shutil
8 import subprocess
9 import sys
10
11 from ansible import release
12
13
14 def main():
15 parser = argparse.ArgumentParser()
16 parser.add_argument('--only-versions', action='store_true')
17
18 options = parser.parse_args()
19
20 ansible_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(release.__file__))))
21 source_root = os.path.join(ansible_root, 'test', 'lib')
22
23 sys.path.insert(0, source_root)
24
25 from ansible_test._internal import constants
26
27 args = []
28
29 for python_version in constants.SUPPORTED_PYTHON_VERSIONS:
30 executable = shutil.which(f'python{python_version}')
31
32 if executable:
33 if python_version.startswith('2.'):
34 cmd = [executable, '-m', 'virtualenv', '--version']
35 else:
36 cmd = [executable, '-m', 'venv', '--help']
37
38 process = subprocess.run(cmd, capture_output=True, check=False)
39
40 print(f'{executable} - {"fail" if process.returncode else "pass"}', file=sys.stderr)
41
42 if not process.returncode:
43 if options.only_versions:
44 args.append(python_version)
45 continue
46
47 args.extend(['--target-python', f'venv/{python_version}'])
48
49 print(' '.join(args))
50
51
52 if __name__ == '__main__':
53 main()