Improve ansible-test env display. (#61339)
* Improve ansible-test env display. * Fix PyCharm warnings. * Fix ansible-test ansible-doc sanity test with -e.
This commit is contained in:
parent
749662d776
commit
e258ba703e
7 changed files with 47 additions and 38 deletions
|
@ -22,8 +22,8 @@ from .util import (
|
||||||
find_executable,
|
find_executable,
|
||||||
SubprocessError,
|
SubprocessError,
|
||||||
ApplicationError,
|
ApplicationError,
|
||||||
load_module,
|
get_ansible_version,
|
||||||
ANSIBLE_LIB_ROOT,
|
get_available_python_versions,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .git import (
|
from .git import (
|
||||||
|
@ -51,6 +51,10 @@ from .data import (
|
||||||
data_context,
|
data_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from .executor import (
|
||||||
|
SUPPORTED_PYTHON_VERSIONS,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EnvConfig(CommonConfig):
|
class EnvConfig(CommonConfig):
|
||||||
"""Configuration for the tools command."""
|
"""Configuration for the tools command."""
|
||||||
|
@ -64,6 +68,10 @@ class EnvConfig(CommonConfig):
|
||||||
self.dump = args.dump
|
self.dump = args.dump
|
||||||
self.timeout = args.timeout
|
self.timeout = args.timeout
|
||||||
|
|
||||||
|
if not self.show and not self.dump and self.timeout is None:
|
||||||
|
# default to --show if no options were given
|
||||||
|
self.show = True
|
||||||
|
|
||||||
|
|
||||||
def command_env(args):
|
def command_env(args):
|
||||||
"""
|
"""
|
||||||
|
@ -86,6 +94,10 @@ def show_dump_env(args):
|
||||||
),
|
),
|
||||||
docker=get_docker_details(args),
|
docker=get_docker_details(args),
|
||||||
environ=os.environ.copy(),
|
environ=os.environ.copy(),
|
||||||
|
location=dict(
|
||||||
|
pwd=os.environ.get('PWD', None),
|
||||||
|
cwd=os.getcwd(),
|
||||||
|
),
|
||||||
git=get_git_details(args),
|
git=get_git_details(args),
|
||||||
platform=dict(
|
platform=dict(
|
||||||
datetime=datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
|
datetime=datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
|
||||||
|
@ -96,6 +108,7 @@ def show_dump_env(args):
|
||||||
executable=sys.executable,
|
executable=sys.executable,
|
||||||
version=platform.python_version(),
|
version=platform.python_version(),
|
||||||
),
|
),
|
||||||
|
interpreters=get_available_python_versions(SUPPORTED_PYTHON_VERSIONS),
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.show:
|
if args.show:
|
||||||
|
@ -239,25 +252,6 @@ def show_dict(data, verbose, root_verbosity=0, path=None):
|
||||||
display.info(indent + '%s: %s' % (key, value), verbosity=verbosity)
|
display.info(indent + '%s: %s' % (key, value), verbosity=verbosity)
|
||||||
|
|
||||||
|
|
||||||
def get_ansible_version(): # type: () -> str
|
|
||||||
"""Return the Ansible version."""
|
|
||||||
try:
|
|
||||||
return get_ansible_version.version
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# ansible may not be in our sys.path
|
|
||||||
# avoids a symlink to release.py since ansible placement relative to ansible-test may change during delegation
|
|
||||||
load_module(os.path.join(ANSIBLE_LIB_ROOT, 'release.py'), 'ansible_release')
|
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
|
||||||
from ansible_release import __version__ as ansible_version # pylint: disable=import-error
|
|
||||||
|
|
||||||
get_ansible_version.version = ansible_version
|
|
||||||
|
|
||||||
return ansible_version
|
|
||||||
|
|
||||||
|
|
||||||
def get_docker_details(args):
|
def get_docker_details(args):
|
||||||
"""
|
"""
|
||||||
:type args: CommonConfig
|
:type args: CommonConfig
|
||||||
|
@ -299,7 +293,6 @@ def get_git_details(args):
|
||||||
base_commit=base_commit,
|
base_commit=base_commit,
|
||||||
commit=commit,
|
commit=commit,
|
||||||
merged_commit=get_merged_commit(args, commit),
|
merged_commit=get_merged_commit(args, commit),
|
||||||
root=os.getcwd(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return git_details
|
return git_details
|
||||||
|
|
|
@ -61,6 +61,7 @@ from .util import (
|
||||||
ANSIBLE_LIB_ROOT,
|
ANSIBLE_LIB_ROOT,
|
||||||
ANSIBLE_TEST_DATA_ROOT,
|
ANSIBLE_TEST_DATA_ROOT,
|
||||||
ANSIBLE_TEST_CONFIG_ROOT,
|
ANSIBLE_TEST_CONFIG_ROOT,
|
||||||
|
get_ansible_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .util_common import (
|
from .util_common import (
|
||||||
|
@ -84,10 +85,6 @@ from .ansible_util import (
|
||||||
check_pyyaml,
|
check_pyyaml,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .env import (
|
|
||||||
get_ansible_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .target import (
|
from .target import (
|
||||||
IntegrationTarget,
|
IntegrationTarget,
|
||||||
walk_internal_targets,
|
walk_internal_targets,
|
||||||
|
|
|
@ -26,6 +26,7 @@ from ..util import (
|
||||||
find_python,
|
find_python,
|
||||||
is_subdir,
|
is_subdir,
|
||||||
paths_to_dirs,
|
paths_to_dirs,
|
||||||
|
get_ansible_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
from ..util_common import (
|
from ..util_common import (
|
||||||
|
@ -67,10 +68,6 @@ from ..data import (
|
||||||
data_context,
|
data_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
from ..env import (
|
|
||||||
get_ansible_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
COMMAND = 'sanity'
|
COMMAND = 'sanity'
|
||||||
SANITY_ROOT = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'sanity')
|
SANITY_ROOT = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'sanity')
|
||||||
|
|
||||||
|
@ -113,7 +110,7 @@ def command_sanity(args):
|
||||||
display.info(test.name)
|
display.info(test.name)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
available_versions = get_available_python_versions(SUPPORTED_PYTHON_VERSIONS)
|
available_versions = sorted(get_available_python_versions(SUPPORTED_PYTHON_VERSIONS).keys())
|
||||||
|
|
||||||
if args.python:
|
if args.python:
|
||||||
# specific version selected
|
# specific version selected
|
||||||
|
|
|
@ -135,6 +135,9 @@ class AnsibleDocTest(SanitySingleVersion):
|
||||||
summary = u'Output on stderr from ansible-doc is considered an error.\n\n%s' % SubprocessError(cmd, stderr=stderr)
|
summary = u'Output on stderr from ansible-doc is considered an error.\n\n%s' % SubprocessError(cmd, stderr=stderr)
|
||||||
return SanityFailure(self.name, summary=summary)
|
return SanityFailure(self.name, summary=summary)
|
||||||
|
|
||||||
|
if args.explain:
|
||||||
|
return SanitySuccess(self.name)
|
||||||
|
|
||||||
error_messages = settings.process_errors(error_messages, paths)
|
error_messages = settings.process_errors(error_messages, paths)
|
||||||
|
|
||||||
if error_messages:
|
if error_messages:
|
||||||
|
|
|
@ -87,17 +87,17 @@ def walk_internal_targets(targets, includes=None, excludes=None, requires=None):
|
||||||
"""
|
"""
|
||||||
targets = tuple(targets)
|
targets = tuple(targets)
|
||||||
|
|
||||||
include_targets = sorted(filter_targets(targets, includes, errors=True, directories=False), key=lambda target: target.name)
|
include_targets = sorted(filter_targets(targets, includes, errors=True, directories=False), key=lambda include_target: include_target.name)
|
||||||
|
|
||||||
if requires:
|
if requires:
|
||||||
require_targets = set(filter_targets(targets, requires, errors=True, directories=False))
|
require_targets = set(filter_targets(targets, requires, errors=True, directories=False))
|
||||||
include_targets = [target for target in include_targets if target in require_targets]
|
include_targets = [require_target for require_target in include_targets if require_target in require_targets]
|
||||||
|
|
||||||
if excludes:
|
if excludes:
|
||||||
list(filter_targets(targets, excludes, errors=True, include=False, directories=False))
|
list(filter_targets(targets, excludes, errors=True, include=False, directories=False))
|
||||||
|
|
||||||
internal_targets = set(filter_targets(include_targets, excludes, errors=False, include=False, directories=False))
|
internal_targets = set(filter_targets(include_targets, excludes, errors=False, include=False, directories=False))
|
||||||
return tuple(sorted(internal_targets, key=lambda target: target.name))
|
return tuple(sorted(internal_targets, key=lambda sort_target: sort_target.name))
|
||||||
|
|
||||||
|
|
||||||
def filter_targets(targets, # type: t.Iterable[TCompletionTarget]
|
def filter_targets(targets, # type: t.Iterable[TCompletionTarget]
|
||||||
|
|
|
@ -73,7 +73,7 @@ def command_units(args):
|
||||||
|
|
||||||
version_commands = []
|
version_commands = []
|
||||||
|
|
||||||
available_versions = get_available_python_versions(list(SUPPORTED_PYTHON_VERSIONS))
|
available_versions = sorted(get_available_python_versions(list(SUPPORTED_PYTHON_VERSIONS)).keys())
|
||||||
|
|
||||||
for version in SUPPORTED_PYTHON_VERSIONS:
|
for version in SUPPORTED_PYTHON_VERSIONS:
|
||||||
# run all versions unless version given, in which case run only that version
|
# run all versions unless version given, in which case run only that version
|
||||||
|
|
|
@ -282,9 +282,28 @@ def find_python(version, path=None, required=True):
|
||||||
return python_bin
|
return python_bin
|
||||||
|
|
||||||
|
|
||||||
def get_available_python_versions(versions): # type: (t.List[str]) -> t.Tuple[str, ...]
|
def get_ansible_version(): # type: () -> str
|
||||||
"""Return a tuple indicating which of the requested Python versions are available."""
|
"""Return the Ansible version."""
|
||||||
return tuple(python_version for python_version in versions if find_python(python_version, required=False))
|
try:
|
||||||
|
return get_ansible_version.version
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ansible may not be in our sys.path
|
||||||
|
# avoids a symlink to release.py since ansible placement relative to ansible-test may change during delegation
|
||||||
|
load_module(os.path.join(ANSIBLE_LIB_ROOT, 'release.py'), 'ansible_release')
|
||||||
|
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
|
from ansible_release import __version__ as ansible_version # pylint: disable=import-error
|
||||||
|
|
||||||
|
get_ansible_version.version = ansible_version
|
||||||
|
|
||||||
|
return ansible_version
|
||||||
|
|
||||||
|
|
||||||
|
def get_available_python_versions(versions): # type: (t.List[str]) -> t.Dict[str, str]
|
||||||
|
"""Return a dictionary indicating which of the requested Python versions are available."""
|
||||||
|
return dict((version, path) for version, path in ((version, find_python(version, required=False)) for version in versions) if path)
|
||||||
|
|
||||||
|
|
||||||
def generate_pip_command(python):
|
def generate_pip_command(python):
|
||||||
|
|
Loading…
Reference in a new issue