Improve ansible-test python interpreter selection. (#54445)

This commit is contained in:
Matt Clay 2019-03-27 16:40:27 -07:00 committed by GitHub
commit 785afc7a53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 203 additions and 99 deletions

View file

@ -38,7 +38,8 @@ except ImportError:
# noinspection PyCompatibility
from configparser import ConfigParser
DOCKER_COMPLETION = {}
DOCKER_COMPLETION = {} # type: dict[str, dict[str, str]]
REMOTE_COMPLETION = {} # type: dict[str, dict[str, str]]
PYTHON_PATHS = {} # type: dict[str, str]
try:
@ -66,17 +67,33 @@ MODE_DIRECTORY_WRITE = MODE_DIRECTORY | stat.S_IWGRP | stat.S_IWOTH
def get_docker_completion():
"""
:rtype: dict[str, str]
:rtype: dict[str, dict[str, str]]
"""
if not DOCKER_COMPLETION:
images = read_lines_without_comments('test/runner/completion/docker.txt', remove_blank_lines=True)
DOCKER_COMPLETION.update(dict(kvp for kvp in [parse_docker_completion(i) for i in images] if kvp))
return DOCKER_COMPLETION
return get_parameterized_completion(DOCKER_COMPLETION, 'docker')
def parse_docker_completion(value):
def get_remote_completion():
"""
:rtype: dict[str, dict[str, str]]
"""
return get_parameterized_completion(REMOTE_COMPLETION, 'remote')
def get_parameterized_completion(cache, name):
"""
:type cache: dict[str, dict[str, str]]
:type name: str
:rtype: dict[str, dict[str, str]]
"""
if not cache:
images = read_lines_without_comments('test/runner/completion/%s.txt' % name, remove_blank_lines=True)
cache.update(dict(kvp for kvp in [parse_parameterized_completion(i) for i in images] if kvp))
return cache
def parse_parameterized_completion(value):
"""
:type value: str
:rtype: tuple[str, dict[str, str]]