diff --git a/changelogs/fragments/429-ansible-community-version.yml b/changelogs/fragments/429-ansible-community-version.yml new file mode 100644 index 00000000..4aaa0dcc --- /dev/null +++ b/changelogs/fragments/429-ansible-community-version.yml @@ -0,0 +1,2 @@ +minor_changes: + - "Include ``ansible-community`` CLI program with ``--version`` parameter from Ansible 6.0.0rc1 on (https://github.com/ansible-community/antsibull/pull/429)." diff --git a/roles/build-release/tasks/tests.yaml b/roles/build-release/tasks/tests.yaml index b693719d..7dd713d6 100644 --- a/roles/build-release/tasks/tests.yaml +++ b/roles/build-release/tasks/tests.yaml @@ -74,6 +74,19 @@ success_msg: "ansible {{ _ansible_version_pypi.stdout }} matches {{ _deps_file }} as well as 'ansible_collections.ansible_release'" fail_msg: "ansible {{ _ansible_version_pypi.stdout }} does not match {{ _deps_file }} or 'ansible_collections.ansible_release'" + - when: antsibull_ansible_version is _antsibull_packaging_version('6.0.0rc1', '>=') + block: + - name: Retrieve the builtin reported version of ansible from the ansible-community CLI tool + command: >- + {{ antsibull_ansible_venv }}/bin/ansible-community --version + changed_when: false + register: _ansible_version_builtin_2 + + - name: Verify that the version output matches the one we expect + assert: + that: + - _ansible_version_builtin_2.stdout == ("Ansible community version " ~ antsibull_ansible_version) + - name: Retrieve installed collections environment: # In case we happen to be testing with devel, don't print a warning about it diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 05407c1b..425ab50c 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -130,6 +130,16 @@ def write_release_py(ansible_version: PypiVer, ansible_collections_dir: str) -> f.write(release_contents) +def write_ansible_community_py(ansible_version: PypiVer, ansible_collections_dir: str) -> None: + release_filename = os.path.join(ansible_collections_dir, 'ansible_community.py') + + release_tmpl = Template(get_antsibull_data('ansible-community.py.j2').decode('utf-8')) + release_contents = release_tmpl.render(version=ansible_version) + + with open(release_filename, 'w', encoding='utf-8') as f: + f.write(release_contents + '\n') + + def write_setup(ansible_version: PypiVer, ansible_core_version: PypiVer, collection_exclude_paths: t.List[str], @@ -143,7 +153,9 @@ def write_setup(ansible_version: PypiVer, ansible_core_package_name=get_ansible_core_package_name(ansible_core_version), ansible_core_version=ansible_core_version, collection_exclude_paths=collection_exclude_paths, - collection_deps=collection_deps) + collection_deps=collection_deps, + PypiVer=PypiVer, + ) with open(setup_filename, 'w', encoding='utf-8') as f: f.write(setup_contents) @@ -425,6 +437,10 @@ def rebuild_single_command() -> int: # Write the ansible release info to the collections dir write_release_py(app_ctx.extra['ansible_version'], ansible_collections_dir) + # Write the ansible-community CLI program (starting with Ansible 6.0.0rc1) + if app_ctx.extra['ansible_version'] >= PypiVer('6.0.0rc1'): + write_ansible_community_py(app_ctx.extra['ansible_version'], ansible_collections_dir) + # Install collections # TODO: PY3.8: # collections_to_install = [p for f in os.listdir(download_dir) diff --git a/src/antsibull/data/ansible-community.py.j2 b/src/antsibull/data/ansible-community.py.j2 new file mode 100644 index 00000000..6b98dcf5 --- /dev/null +++ b/src/antsibull/data/ansible-community.py.j2 @@ -0,0 +1,25 @@ +#!/usr/bin/python +# coding: utf-8 +# Author: Mario Lenz +# License: GPLv3+ +# Copyright: Ansible Project, 2022 +"""The ansible-community CLI program.""" + +import argparse + + +def main(): + '''Main entrypoint for the ansible-community CLI program.''' + parser = argparse.ArgumentParser() + parser.add_argument( + '--version', + action='version', + version='Ansible community version {{ version }}', + help="show the version of the Ansible community package", + ) + parser.parse_args() + parser.print_help() + + +if __name__ == '__main__': + main() diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index 95245aa5..4c881868 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -215,6 +215,13 @@ setup( 'Topic :: Utilities', ], data_files=[], +{%- if version >= PypiVer('6.0.0rc1') %} + entry_points={ + 'console_scripts': [ + 'ansible-community=ansible_collections.ansible_community:main' + ] + }, +{%- endif %} # Installing as zip files would break due to references to __file__ zip_safe=False )