Reformatted test/lib/ansible_test/_data/sanity/code-smell/galaxy-metadata.py file

pull/75335/head
Ompragash Viswanathan 3 years ago
parent 6611af16ee
commit 786ec38b4e

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
"""Validates the required keys (namespace, name, version, readme, authors) for the collection galaxy.yml metadata file""" """Validates the required keys (namespace, name, version, readme, authors) for the collection galaxy.yml metadata file"""
from __future__ import (absolute_import, division, print_function) from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
import re import re
@ -17,34 +18,46 @@ from ansible.module_utils.six import string_types
def validate_galaxy_metadata_file(path): def validate_galaxy_metadata_file(path):
"""Validate explicit galaxy.yml metadata file""" """Validate explicit galaxy.yml metadata file"""
try: try:
with open(path, 'r') as f_path: with open(path, "r") as f_path:
routing = yaml.safe_load(f_path) routing = yaml.safe_load(f_path)
except yaml.error.MarkedYAMLError as ex: except yaml.error.MarkedYAMLError as ex:
print('%s:%d:%d: YAML load failed: %s' % (path, ex.context_mark.line + print(
1, ex.context_mark.column + 1, re.sub(r'\s+', ' ', str(ex)))) "%s:%d:%d: YAML load failed: %s"
% (
path,
ex.context_mark.line + 1,
ex.context_mark.column + 1,
re.sub(r"\s+", " ", str(ex)),
)
)
return return
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
print('%s:%d:%d: YAML load failed: %s' % print(
(path, 0, 0, re.sub(r'\s+', ' ', str(ex)))) "%s:%d:%d: YAML load failed: %s"
% (path, 0, 0, re.sub(r"\s+", " ", str(ex)))
)
return return
schema = Schema({ schema = Schema(
Required('namespace'): Any(*string_types), {
Required('name'): Any(*string_types), Required("namespace"): Any(*string_types),
Required('version'): Any(*string_types), Required("name"): Any(*string_types),
Required('readme'): Any(*string_types), Required("version"): Any(*string_types),
Required('authors'): Any(list), Required("readme"): Any(*string_types),
Optional('description'): Any(*string_types), Required("authors"): Any(list),
Optional('license'): Any(list), Optional("description"): Any(*string_types),
Optional('license_file'): Any(*string_types), Optional("license"): Any(list),
Optional('tags'): Any(list), Optional("license_file"): Any(*string_types),
Optional('dependencies'): Any(dict), Optional("tags"): Any(list),
Optional('repository'): Any(*string_types), Optional("dependencies"): Any(dict),
Optional('documentation'): Any(*string_types), Optional("repository"): Any(*string_types),
Optional('homepage'): Any(*string_types), Optional("documentation"): Any(*string_types),
Optional('issues'): Any(*string_types), Optional("homepage"): Any(*string_types),
Optional('build_ignore'): Any(list), Optional("issues"): Any(*string_types),
}, required=True) Optional("build_ignore"): Any(list),
},
required=True,
)
# Ensure schema is valid # Ensure schema is valid
@ -53,19 +66,19 @@ def validate_galaxy_metadata_file(path):
except MultipleInvalid as ex: except MultipleInvalid as ex:
for error in ex.errors: for error in ex.errors:
# No way to get line/column numbers # No way to get line/column numbers
print('%s:%d:%d: %s' % (path, 0, 0, humanize_error(routing, error))) print("%s:%d:%d: %s" % (path, 0, 0, humanize_error(routing, error)))
def main(): def main():
"""Validate galaxy.yml metadata""" """Validate galaxy.yml metadata"""
paths = sys.argv[1:] or sys.stdin.read().splitlines() paths = sys.argv[1:] or sys.stdin.read().splitlines()
collection_galaxy_file = 'galaxy.yml' collection_galaxy_file = "galaxy.yml"
for path in paths: for path in paths:
if path == collection_galaxy_file: if path == collection_galaxy_file:
validate_galaxy_metadata_file(path) validate_galaxy_metadata_file(path)
if __name__ == '__main__': if __name__ == "__main__":
main() main()

Loading…
Cancel
Save