add docker examples
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
{
|
||||
"include_symlinks": true,
|
||||
"prefixes": [
|
||||
"meta/runtime.yml",
|
||||
"plugins/modules/",
|
||||
"tests/sanity/extra/action-group."
|
||||
],
|
||||
"output": "path-message",
|
||||
"requirements": [
|
||||
"pyyaml"
|
||||
]
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2024, Felix Fontein <felix@fontein.de>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Make sure all modules that should show up in the action group."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
|
||||
|
||||
ACTION_GROUPS = {
|
||||
# The format is as follows:
|
||||
# * 'pattern': a regular expression matching all module names potentially belonging to the action group;
|
||||
# * 'exclusions': a list of modules that are not part of the action group; all other modules matching 'pattern' must be part of it;
|
||||
# * 'doc_fragment': the docs fragment that documents membership of the action group.
|
||||
'docker': {
|
||||
'pattern': re.compile('^.*$'),
|
||||
'exclusions': [
|
||||
'current_container_facts',
|
||||
'docker_context_info',
|
||||
],
|
||||
'doc_fragment': 'community.docker.attributes.actiongroup_docker',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
|
||||
# Load redirects
|
||||
meta_runtime = 'meta/runtime.yml'
|
||||
self_path = 'tests/sanity/extra/action-group.py'
|
||||
try:
|
||||
with open(meta_runtime, 'rb') as f:
|
||||
data = yaml.safe_load(f)
|
||||
action_groups = data['action_groups']
|
||||
except Exception as exc:
|
||||
print(f'{meta_runtime}: cannot load action groups: {exc}')
|
||||
return
|
||||
|
||||
for action_group in action_groups:
|
||||
if action_group not in ACTION_GROUPS:
|
||||
print(f'{meta_runtime}: found unknown action group {action_group!r}; likely {self_path} needs updating')
|
||||
for action_group, action_group_data in list(ACTION_GROUPS.items()):
|
||||
if action_group not in action_groups:
|
||||
print(f'{meta_runtime}: cannot find action group {action_group!r}; likely {self_path} needs updating')
|
||||
|
||||
modules_directory = 'plugins/modules/'
|
||||
modules_suffix = '.py'
|
||||
|
||||
for file in os.listdir(modules_directory):
|
||||
if not file.endswith(modules_suffix):
|
||||
continue
|
||||
module_name = file[:-len(modules_suffix)]
|
||||
|
||||
for action_group, action_group_data in ACTION_GROUPS.items():
|
||||
action_group_content = action_groups.get(action_group) or []
|
||||
path = os.path.join(modules_directory, file)
|
||||
|
||||
if not action_group_data['pattern'].match(module_name):
|
||||
if module_name in action_group_content:
|
||||
print(f'{path}: module is in action group {action_group!r} despite not matching its pattern as defined in {self_path}')
|
||||
continue
|
||||
|
||||
should_be_in_action_group = module_name not in action_group_data['exclusions']
|
||||
|
||||
if should_be_in_action_group:
|
||||
if module_name not in action_group_content:
|
||||
print(f'{meta_runtime}: module {module_name!r} is not part of {action_group!r} action group')
|
||||
else:
|
||||
action_group_content.remove(module_name)
|
||||
|
||||
documentation = []
|
||||
in_docs = False
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if line.startswith('DOCUMENTATION ='):
|
||||
in_docs = True
|
||||
elif line.startswith(("'''", '"""')) and in_docs:
|
||||
in_docs = False
|
||||
elif in_docs:
|
||||
documentation.append(line)
|
||||
if in_docs:
|
||||
print(f'{path}: cannot find DOCUMENTATION end')
|
||||
if not documentation:
|
||||
print(f'{path}: cannot find DOCUMENTATION')
|
||||
continue
|
||||
|
||||
try:
|
||||
docs = yaml.safe_load('\n'.join(documentation))
|
||||
if not isinstance(docs, dict):
|
||||
raise Exception('is not a top-level dictionary')
|
||||
except Exception as exc:
|
||||
print(f'{path}: cannot load DOCUMENTATION as YAML: {exc}')
|
||||
continue
|
||||
|
||||
docs_fragments = docs.get('extends_documentation_fragment') or []
|
||||
is_in_action_group = action_group_data['doc_fragment'] in docs_fragments
|
||||
|
||||
if should_be_in_action_group != is_in_action_group:
|
||||
if should_be_in_action_group:
|
||||
print(
|
||||
f'{path}: module does not document itself as part of action group {action_group!r}, but it should;'
|
||||
f' you need to add {action_group_data["doc_fragment"]} to "extends_documentation_fragment" in DOCUMENTATION'
|
||||
)
|
||||
else:
|
||||
print(f'{path}: module documents itself as part of action group {action_group!r}, but it should not be')
|
||||
|
||||
for action_group, action_group_data in ACTION_GROUPS.items():
|
||||
action_group_content = action_groups.get(action_group) or []
|
||||
for module_name in action_group_content:
|
||||
print(
|
||||
f'{meta_runtime}: module {module_name} mentioned in {action_group!r} action group'
|
||||
f' does not exist or does not match pattern defined in {self_path}'
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"include_symlinks": false,
|
||||
"prefixes": [
|
||||
"docs/docsite/",
|
||||
"plugins/",
|
||||
"roles/"
|
||||
],
|
||||
"output": "path-line-column-message",
|
||||
"requirements": [
|
||||
"ansible-core",
|
||||
"antsibull-docs"
|
||||
]
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Check extra collection docs with antsibull-docs."""
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
env = os.environ.copy()
|
||||
suffix = ':{env}'.format(env=env["ANSIBLE_COLLECTIONS_PATH"]) if 'ANSIBLE_COLLECTIONS_PATH' in env else ''
|
||||
env['ANSIBLE_COLLECTIONS_PATH'] = '{root}{suffix}'.format(root=os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd()))), suffix=suffix)
|
||||
p = subprocess.run(
|
||||
['antsibull-docs', 'lint-collection-docs', '--plugin-docs', '--skip-rstcheck', '.'],
|
||||
env=env,
|
||||
check=False,
|
||||
)
|
||||
if p.returncode not in (0, 3):
|
||||
print('{0}:0:0: unexpected return code {1}'.format(sys.argv[0], p.returncode))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"include_symlinks": false,
|
||||
"output": "path-message"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Prevent files without a correct license identifier from being added to the source tree."""
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import glob
|
||||
import sys
|
||||
|
||||
|
||||
def format_license_list(licenses):
|
||||
if not licenses:
|
||||
return '(empty)'
|
||||
return ', '.join(['"%s"' % license for license in licenses])
|
||||
|
||||
|
||||
def find_licenses(filename, relax=False):
|
||||
spdx_license_identifiers = []
|
||||
other_license_identifiers = []
|
||||
has_copyright = False
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
line = line.rstrip()
|
||||
if 'Copyright ' in line:
|
||||
has_copyright = True
|
||||
if 'Copyright: ' in line:
|
||||
print('%s: found copyright line with "Copyright:". Please remove the colon.' % (filename, ))
|
||||
if 'SPDX-FileCopyrightText: ' in line:
|
||||
has_copyright = True
|
||||
idx = line.find('SPDX-License-Identifier: ')
|
||||
if idx >= 0:
|
||||
lic_id = line[idx + len('SPDX-License-Identifier: '):]
|
||||
spdx_license_identifiers.extend(lic_id.split(' OR '))
|
||||
if 'GNU General Public License' in line:
|
||||
if 'v3.0+' in line:
|
||||
other_license_identifiers.append('GPL-3.0-or-later')
|
||||
if 'version 3 or later' in line:
|
||||
other_license_identifiers.append('GPL-3.0-or-later')
|
||||
if 'Simplified BSD License' in line:
|
||||
other_license_identifiers.append('BSD-2-Clause')
|
||||
if 'Apache License 2.0' in line:
|
||||
other_license_identifiers.append('Apache-2.0')
|
||||
if 'PSF License' in line or 'Python-2.0' in line:
|
||||
other_license_identifiers.append('PSF-2.0')
|
||||
if 'MIT License' in line:
|
||||
other_license_identifiers.append('MIT')
|
||||
except Exception as exc:
|
||||
print('%s: error while processing file: %s' % (filename, exc))
|
||||
if len(set(spdx_license_identifiers)) < len(spdx_license_identifiers):
|
||||
print('%s: found identical SPDX-License-Identifier values' % (filename, ))
|
||||
if other_license_identifiers and set(other_license_identifiers) != set(spdx_license_identifiers):
|
||||
print('%s: SPDX-License-Identifier yielded the license list %s, while manual guessing yielded the license list %s' % (
|
||||
filename, format_license_list(spdx_license_identifiers), format_license_list(other_license_identifiers)))
|
||||
if not has_copyright and not relax:
|
||||
print('%s: found no copyright notice' % (filename, ))
|
||||
return sorted(spdx_license_identifiers)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
paths = sys.argv[1:] or sys.stdin.read().splitlines()
|
||||
|
||||
# The following paths are allowed to have no license identifier
|
||||
no_comments_allowed = [
|
||||
'changelogs/fragments/*.yml',
|
||||
'changelogs/fragments/*.yaml',
|
||||
]
|
||||
|
||||
# These files are completely ignored
|
||||
ignore_paths = [
|
||||
'.ansible-test-timeout.json',
|
||||
'.reuse/dep5',
|
||||
'LICENSES/*.txt',
|
||||
'COPYING',
|
||||
]
|
||||
|
||||
no_comments_allowed = [fn for pattern in no_comments_allowed for fn in glob.glob(pattern)]
|
||||
ignore_paths = [fn for pattern in ignore_paths for fn in glob.glob(pattern)]
|
||||
|
||||
valid_licenses = [license_file[len('LICENSES/'):-len('.txt')] for license_file in glob.glob('LICENSES/*.txt')]
|
||||
|
||||
for path in paths:
|
||||
if path.startswith('./'):
|
||||
path = path[2:]
|
||||
if path in ignore_paths or path.startswith('tests/output/'):
|
||||
continue
|
||||
if os.stat(path).st_size == 0:
|
||||
continue
|
||||
if not path.endswith('.license') and os.path.exists(path + '.license'):
|
||||
path = path + '.license'
|
||||
valid_licenses_for_path = valid_licenses
|
||||
if path.startswith('plugins/') and not path.startswith(('plugins/modules/', 'plugins/module_utils/')):
|
||||
valid_licenses_for_path = [license for license in valid_licenses if license == 'GPL-3.0-or-later']
|
||||
licenses = find_licenses(path, relax=path in no_comments_allowed)
|
||||
if not licenses:
|
||||
if path not in no_comments_allowed:
|
||||
print('%s: must have at least one license' % (path, ))
|
||||
else:
|
||||
for license in licenses:
|
||||
if license not in valid_licenses_for_path:
|
||||
print('%s: found not allowed license "%s", must be one of %s' % (
|
||||
path, license, format_license_list(valid_licenses_for_path)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: 2022, Felix Fontein <felix@fontein.de>
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"include_symlinks": true,
|
||||
"prefixes": [
|
||||
"plugins/"
|
||||
],
|
||||
"output": "path-message"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Prevent unwanted files from being added to the source tree."""
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
paths = sys.argv[1:] or sys.stdin.read().splitlines()
|
||||
|
||||
allowed_extensions = (
|
||||
'.cs',
|
||||
'.ps1',
|
||||
'.psm1',
|
||||
'.py',
|
||||
)
|
||||
|
||||
skip_paths = set([
|
||||
])
|
||||
|
||||
skip_directories = (
|
||||
)
|
||||
|
||||
for path in paths:
|
||||
if path in skip_paths:
|
||||
continue
|
||||
|
||||
if any(path.startswith(skip_directory) for skip_directory in skip_directories):
|
||||
continue
|
||||
|
||||
ext = os.path.splitext(path)[1]
|
||||
|
||||
if ext not in allowed_extensions:
|
||||
print('%s: extension must be one of: %s' % (path, ', '.join(allowed_extensions)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user