File: venv-pythons.py

package info (click to toggle)
ansible-core 2.19.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 32,944 kB
  • sloc: python: 181,408; cs: 4,929; sh: 4,661; xml: 34; makefile: 21
file content (53 lines) | stat: -rwxr-xr-x 1,457 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
"""Return target Python options for use with ansible-test."""
from __future__ import annotations

import argparse
import os
import shutil
import subprocess
import sys

from ansible import release


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--only-versions', action='store_true')

    options = parser.parse_args()

    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

    args = []

    for python_version in constants.SUPPORTED_PYTHON_VERSIONS:
        executable = shutil.which(f'python{python_version}')

        if executable:
            if python_version.startswith('2.'):
                cmd = [executable, '-m', 'virtualenv', '--version']
            else:
                cmd = [executable, '-m', 'venv', '--help']

            process = subprocess.run(cmd, capture_output=True, check=False)

            print(f'{executable} - {"fail" if process.returncode else "pass"}', file=sys.stderr)

            if not process.returncode:
                if options.only_versions:
                    args.append(python_version)
                    continue

                args.extend(['--target-python', f'venv/{python_version}'])

    print(' '.join(args))


if __name__ == '__main__':
    main()