Improve ansible-test env display. (#61339)

* Improve ansible-test env display.
* Fix PyCharm warnings.
* Fix ansible-test ansible-doc sanity test with -e.
pull/55523/head
Matt Clay 5 years ago committed by GitHub
parent 749662d776
commit e258ba703e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,8 +22,8 @@ from .util import (
find_executable,
SubprocessError,
ApplicationError,
load_module,
ANSIBLE_LIB_ROOT,
get_ansible_version,
get_available_python_versions,
)
from .git import (
@ -51,6 +51,10 @@ from .data import (
data_context,
)
from .executor import (
SUPPORTED_PYTHON_VERSIONS,
)
class EnvConfig(CommonConfig):
"""Configuration for the tools command."""
@ -64,6 +68,10 @@ class EnvConfig(CommonConfig):
self.dump = args.dump
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):
"""
@ -86,6 +94,10 @@ def show_dump_env(args):
),
docker=get_docker_details(args),
environ=os.environ.copy(),
location=dict(
pwd=os.environ.get('PWD', None),
cwd=os.getcwd(),
),
git=get_git_details(args),
platform=dict(
datetime=datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
@ -96,6 +108,7 @@ def show_dump_env(args):
executable=sys.executable,
version=platform.python_version(),
),
interpreters=get_available_python_versions(SUPPORTED_PYTHON_VERSIONS),
)
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)
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):
"""
:type args: CommonConfig
@ -299,7 +293,6 @@ def get_git_details(args):
base_commit=base_commit,
commit=commit,
merged_commit=get_merged_commit(args, commit),
root=os.getcwd(),
)
return git_details

@ -61,6 +61,7 @@ from .util import (
ANSIBLE_LIB_ROOT,
ANSIBLE_TEST_DATA_ROOT,
ANSIBLE_TEST_CONFIG_ROOT,
get_ansible_version,
)
from .util_common import (
@ -84,10 +85,6 @@ from .ansible_util import (
check_pyyaml,
)
from .env import (
get_ansible_version,
)
from .target import (
IntegrationTarget,
walk_internal_targets,

@ -26,6 +26,7 @@ from ..util import (
find_python,
is_subdir,
paths_to_dirs,
get_ansible_version,
)
from ..util_common import (
@ -67,10 +68,6 @@ from ..data import (
data_context,
)
from ..env import (
get_ansible_version,
)
COMMAND = 'sanity'
SANITY_ROOT = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'sanity')
@ -113,7 +110,7 @@ def command_sanity(args):
display.info(test.name)
continue
available_versions = get_available_python_versions(SUPPORTED_PYTHON_VERSIONS)
available_versions = sorted(get_available_python_versions(SUPPORTED_PYTHON_VERSIONS).keys())
if args.python:
# 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)
return SanityFailure(self.name, summary=summary)
if args.explain:
return SanitySuccess(self.name)
error_messages = settings.process_errors(error_messages, paths)
if error_messages:

@ -87,17 +87,17 @@ def walk_internal_targets(targets, includes=None, excludes=None, requires=None):
"""
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:
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:
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))
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]

@ -73,7 +73,7 @@ def command_units(args):
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:
# 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
def get_available_python_versions(versions): # type: (t.List[str]) -> t.Tuple[str, ...]
"""Return a tuple indicating which of the requested Python versions are available."""
return tuple(python_version for python_version in versions if find_python(python_version, required=False))
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_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):

Loading…
Cancel
Save