From 15c4150afde8b3e9e33d42ae5d7e5b726692f777 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 20:38:47 +0200 Subject: [PATCH 1/9] Add CLI program from 6.0.0b3 on. --- src/antsibull/build_ansible_commands.py | 14 ++++++++++++++ src/antsibull/data/ansible-community.py.j2 | 22 ++++++++++++++++++++++ src/antsibull/data/ansible-setup_py.j2 | 7 +++++++ 3 files changed, 43 insertions(+) create mode 100644 src/antsibull/data/ansible-community.py.j2 diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 05407c1b..237b0c6d 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) + + def write_setup(ansible_version: PypiVer, ansible_core_version: PypiVer, collection_exclude_paths: t.List[str], @@ -425,6 +435,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.0b3) + if app_ctx.extra['ansible_version'] >= '6.0.0b3': + 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..80da5b8e --- /dev/null +++ b/src/antsibull/data/ansible-community.py.j2 @@ -0,0 +1,22 @@ +#!/usr/bin/python +# coding: utf-8 +# Author: Mario Lenz +# License: GPLv3+ +# Copyright: Ansible Project, 2022 + +import argparse + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + '--version', + action='version', + version='Ansible community version {{ version }}', + help="show the version of the Ansible community package", + ) + args = parser.parse_args() + + +if __name__ == '__main__': + main() diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index 95245aa5..b276361e 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 >= '6.0.0b3' %} + 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 ) From 87834150daa5a48cdb76ceb5500e50501e726980 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 20:46:41 +0200 Subject: [PATCH 2/9] Add simple test. --- roles/build-release/tasks/tests.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/roles/build-release/tasks/tests.yaml b/roles/build-release/tasks/tests.yaml index b693719d..6dc96df3 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 version('6.0.0b3', '>=') or antsibull_ansible_version == '6.0.0' + 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 From 3efd6683fb19554b0b1cefb84239258cbaa1e8cf Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 20:51:58 +0200 Subject: [PATCH 3/9] Make PypiVer available for version comparisons. --- src/antsibull/build_ansible_commands.py | 6 ++++-- src/antsibull/data/ansible-setup_py.j2 | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 237b0c6d..d59c6141 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -153,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) @@ -436,7 +438,7 @@ def rebuild_single_command() -> int: write_release_py(app_ctx.extra['ansible_version'], ansible_collections_dir) # Write the ansible-community CLI program (starting with Ansible 6.0.0b3) - if app_ctx.extra['ansible_version'] >= '6.0.0b3': + if app_ctx.extra['ansible_version'] >= PypiVer('6.0.0b3'): write_ansible_community_py(app_ctx.extra['ansible_version'], ansible_collections_dir) # Install collections diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index b276361e..21098762 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -215,7 +215,7 @@ setup( 'Topic :: Utilities', ], data_files=[], -{%- if version >= '6.0.0b3' %} +{%- if version >= PypiVer('6.0.0b3') %} entry_points={ 'console_scripts': [ 'ansible-community=ansible_collections.ansible_community:main' From 6d3eefc126dd7c8f39cb78fdfd4453b6d29eedb7 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 20:52:40 +0200 Subject: [PATCH 4/9] Simplify comparison. --- roles/build-release/tasks/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/build-release/tasks/tests.yaml b/roles/build-release/tasks/tests.yaml index 6dc96df3..201a945d 100644 --- a/roles/build-release/tasks/tests.yaml +++ b/roles/build-release/tasks/tests.yaml @@ -74,7 +74,7 @@ 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 version('6.0.0b3', '>=') or antsibull_ansible_version == '6.0.0' + - when: antsibull_ansible_version is packaging_version('6.0.0b3', '>=') block: - name: Retrieve the builtin reported version of ansible from the ansible-community CLI tool command: >- From c95a9f9ed5f24f1ae5650c54555e2bb4267b8bfd Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 20:59:09 +0200 Subject: [PATCH 5/9] Add changelog. --- changelogs/fragments/429-ansible-community-version.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/429-ansible-community-version.yml diff --git a/changelogs/fragments/429-ansible-community-version.yml b/changelogs/fragments/429-ansible-community-version.yml new file mode 100644 index 00000000..a1dc7321 --- /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.0b3 on (https://github.com/ansible-community/antsibull/pull/429)." From e4f8ade745a5578aabd4828a5b0e67d950a6c5ba Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 21:00:49 +0200 Subject: [PATCH 6/9] Spell test correctly. --- roles/build-release/tasks/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/build-release/tasks/tests.yaml b/roles/build-release/tasks/tests.yaml index 201a945d..cf68d484 100644 --- a/roles/build-release/tasks/tests.yaml +++ b/roles/build-release/tasks/tests.yaml @@ -74,7 +74,7 @@ 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 packaging_version('6.0.0b3', '>=') + - when: antsibull_ansible_version is _antsibull_packaging_version('6.0.0b3', '>=') block: - name: Retrieve the builtin reported version of ansible from the ansible-community CLI tool command: >- From 384a0ad27ba568f0a903eb292963314e50db945b Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 21:49:37 +0200 Subject: [PATCH 7/9] Make sure tool passes linting. Also print help if --version is not specified. --- src/antsibull/build_ansible_commands.py | 2 +- src/antsibull/data/ansible-community.py.j2 | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index d59c6141..ac2f5c5b 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -137,7 +137,7 @@ def write_ansible_community_py(ansible_version: PypiVer, ansible_collections_dir release_contents = release_tmpl.render(version=ansible_version) with open(release_filename, 'w', encoding='utf-8') as f: - f.write(release_contents) + f.write(release_contents + '\n') def write_setup(ansible_version: PypiVer, diff --git a/src/antsibull/data/ansible-community.py.j2 b/src/antsibull/data/ansible-community.py.j2 index 80da5b8e..fb1a11b5 100644 --- a/src/antsibull/data/ansible-community.py.j2 +++ b/src/antsibull/data/ansible-community.py.j2 @@ -3,11 +3,13 @@ # 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', @@ -15,7 +17,8 @@ def main(): version='Ansible community version {{ version }}', help="show the version of the Ansible community package", ) - args = parser.parse_args() + args = parser.parse_args() # noqa: F841, pylint: disable=unused-variable + parser.print_help() if __name__ == '__main__': From 0477a3ca5f1e0e767da1b5514d02e46c00b6309c Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 1 Jun 2022 22:10:00 +0200 Subject: [PATCH 8/9] There is no 6.0.0b3. The next planned release is 6.0.0rc1. --- changelogs/fragments/429-ansible-community-version.yml | 2 +- roles/build-release/tasks/tests.yaml | 2 +- src/antsibull/build_ansible_commands.py | 4 ++-- src/antsibull/data/ansible-setup_py.j2 | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/changelogs/fragments/429-ansible-community-version.yml b/changelogs/fragments/429-ansible-community-version.yml index a1dc7321..4aaa0dcc 100644 --- a/changelogs/fragments/429-ansible-community-version.yml +++ b/changelogs/fragments/429-ansible-community-version.yml @@ -1,2 +1,2 @@ minor_changes: - - "Include ``ansible-community`` CLI program with ``--version`` parameter from Ansible 6.0.0b3 on (https://github.com/ansible-community/antsibull/pull/429)." + - "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 cf68d484..7dd713d6 100644 --- a/roles/build-release/tasks/tests.yaml +++ b/roles/build-release/tasks/tests.yaml @@ -74,7 +74,7 @@ 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.0b3', '>=') + - 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: >- diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index ac2f5c5b..425ab50c 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -437,8 +437,8 @@ 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.0b3) - if app_ctx.extra['ansible_version'] >= PypiVer('6.0.0b3'): + # 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 diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index 21098762..4c881868 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -215,7 +215,7 @@ setup( 'Topic :: Utilities', ], data_files=[], -{%- if version >= PypiVer('6.0.0b3') %} +{%- if version >= PypiVer('6.0.0rc1') %} entry_points={ 'console_scripts': [ 'ansible-community=ansible_collections.ansible_community:main' From e32049d3d780545291e4629afaf1f93688ef3022 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 4 Jun 2022 11:50:38 +0200 Subject: [PATCH 9/9] Remove the not-used arguments. --- src/antsibull/data/ansible-community.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/antsibull/data/ansible-community.py.j2 b/src/antsibull/data/ansible-community.py.j2 index fb1a11b5..6b98dcf5 100644 --- a/src/antsibull/data/ansible-community.py.j2 +++ b/src/antsibull/data/ansible-community.py.j2 @@ -17,7 +17,7 @@ def main(): version='Ansible community version {{ version }}', help="show the version of the Ansible community package", ) - args = parser.parse_args() # noqa: F841, pylint: disable=unused-variable + parser.parse_args() parser.print_help()