mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add PyYAML check for libyaml support.
This commit is contained in:
parent
d758d5bab1
commit
817ec5ab48
4 changed files with 60 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
from lib.constants import (
|
||||
|
@ -10,14 +11,21 @@ from lib.constants import (
|
|||
|
||||
from lib.util import (
|
||||
common_environment,
|
||||
display,
|
||||
find_python,
|
||||
run_command,
|
||||
ApplicationError,
|
||||
)
|
||||
|
||||
from lib.config import (
|
||||
IntegrationConfig,
|
||||
EnvironmentConfig,
|
||||
)
|
||||
|
||||
|
||||
CHECK_YAML_VERSIONS = {}
|
||||
|
||||
|
||||
def ansible_environment(args, color=True, ansible_config=None):
|
||||
"""
|
||||
:type args: CommonConfig
|
||||
|
@ -65,3 +73,28 @@ def ansible_environment(args, color=True, ansible_config=None):
|
|||
))
|
||||
|
||||
return env
|
||||
|
||||
|
||||
def check_pyyaml(args, version):
|
||||
"""
|
||||
:type args: EnvironmentConfig
|
||||
:type version: str
|
||||
"""
|
||||
if version in CHECK_YAML_VERSIONS:
|
||||
return
|
||||
|
||||
python = find_python(version)
|
||||
stdout, _dummy = run_command(args, [python, 'test/runner/yamlcheck.py'], capture=True)
|
||||
|
||||
if args.explain:
|
||||
return
|
||||
|
||||
CHECK_YAML_VERSIONS[version] = result = json.loads(stdout)
|
||||
|
||||
yaml = result['yaml']
|
||||
cloader = result['cloader']
|
||||
|
||||
if not yaml:
|
||||
display.warning('PyYAML is not installed for interpreter: %s' % python)
|
||||
elif not cloader:
|
||||
display.warning('PyYAML will be slow due to installation without libyaml support for interpreter: %s' % python)
|
||||
|
|
|
@ -74,6 +74,7 @@ from lib.docker_util import (
|
|||
|
||||
from lib.ansible_util import (
|
||||
ansible_environment,
|
||||
check_pyyaml,
|
||||
)
|
||||
|
||||
from lib.target import (
|
||||
|
@ -804,6 +805,8 @@ def command_integration_filtered(args, targets, all_targets, inventory_path, pre
|
|||
if setup_errors:
|
||||
raise ApplicationError('Found %d invalid setup aliases:\n%s' % (len(setup_errors), '\n'.join(setup_errors)))
|
||||
|
||||
check_pyyaml(args, args.python_version)
|
||||
|
||||
test_dir = os.path.expanduser('~/ansible_testing')
|
||||
|
||||
if not args.explain and any('needs/ssh/' in target.aliases for target in targets):
|
||||
|
@ -1347,6 +1350,8 @@ def command_units(args):
|
|||
sys.exit()
|
||||
|
||||
for version, command, env in version_commands:
|
||||
check_pyyaml(args, version)
|
||||
|
||||
display.info('Unit test with Python %s' % version)
|
||||
|
||||
try:
|
||||
|
|
|
@ -23,6 +23,7 @@ from lib.util import (
|
|||
|
||||
from lib.ansible_util import (
|
||||
ansible_environment,
|
||||
check_pyyaml,
|
||||
)
|
||||
|
||||
from lib.target import (
|
||||
|
@ -100,6 +101,8 @@ def command_sanity(args):
|
|||
if args.python and version and version != args.python_version:
|
||||
continue
|
||||
|
||||
check_pyyaml(args, version or args.python_version)
|
||||
|
||||
display.info('Sanity check using %s%s' % (test.name, ' with Python %s' % version if version else ''))
|
||||
|
||||
options = ''
|
||||
|
|
19
test/runner/yamlcheck.py
Executable file
19
test/runner/yamlcheck.py
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python
|
||||
"""Show python and pip versions."""
|
||||
|
||||
import json
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
yaml = None
|
||||
|
||||
try:
|
||||
from yaml import CLoader
|
||||
except ImportError:
|
||||
CLoader = None
|
||||
|
||||
print(json.dumps(dict(
|
||||
yaml=bool(yaml),
|
||||
cloader=bool(CLoader),
|
||||
)))
|
Loading…
Reference in a new issue