Debian Codegraph @

bin/ansible-test

raw symbols SCIP
1 #!/usr/bin/env python3
2 # PYTHON_ARGCOMPLETE_OK
3 """Command line entry point for ansible-test."""
4
5 # NOTE: This file resides in the _util/target directory to ensure compatibility with all supported Python versions.
6
7 from __future__ import annotations
8
9 import importlib
10 import os
11 import sys
12
13
14 def main(args=None):
15 """Main program entry point."""
16 ansible_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 source_root = os.path.join(ansible_root, 'test', 'lib')
18
19 if os.path.exists(os.path.join(source_root, 'ansible_test', '_internal', '__init__.py')):
20 # running from source, use that version of ansible-test instead of any version that may already be installed
21 sys.path.insert(0, source_root)
22
23 # noinspection PyProtectedMember
24 from ansible_test._util.target.common.constants import CONTROLLER_PYTHON_VERSIONS
25
26 if version_to_str(sys.version_info[:2]) not in CONTROLLER_PYTHON_VERSIONS:
27 raise SystemExit('This version of ansible-test cannot be executed with Python version %s. Supported Python versions are: %s' % (
28 version_to_str(sys.version_info[:3]), ', '.join(CONTROLLER_PYTHON_VERSIONS)))
29
30 if any(not os.get_blocking(handle.fileno()) for handle in (sys.stdin, sys.stdout, sys.stderr)):
31 raise SystemExit('Standard input, output and error file handles must be blocking to run ansible-test.')
32
33 # avoid using import to hide it from mypy
34 internal = importlib.import_module('ansible_test._internal')
35 cli_main = getattr(internal, 'main')
36
37 cli_main(args)
38
39
40 def version_to_str(version):
41 """Return a version string from a version tuple."""
42 return '.'.join(str(n) for n in version)
43
44
45 if __name__ == '__main__':
46 main()