From 15f22e1ec899592f3dd42c7f478192c2214513d7 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 24 Nov 2023 21:24:36 +0100 Subject: [PATCH] Insert antsibull version into the build-ansible.sh script (#563) * Insert antsibull version into the build-ansible.sh script. * update package-files test_data for build-ansible.sh change * Use proper placeholder instead of a real version. * Fix spelling error. Co-authored-by: Maxwell G --------- Co-authored-by: Maxwell G --- .../fragments/563-version-build-ansible.yml | 3 +++ src/antsibull/build_ansible_commands.py | 5 ++++- src/antsibull/data/build-ansible.sh.j2 | 2 +- .../package-files/7.5.0/build-ansible.sh | 2 +- .../package-files/8.1.0/build-ansible.sh | 2 +- .../force_setup_cfg/8.1.0/build-ansible.sh | 2 +- tests/verify_package_files.py | 18 +++++++++++++++++- 7 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/563-version-build-ansible.yml diff --git a/changelogs/fragments/563-version-build-ansible.yml b/changelogs/fragments/563-version-build-ansible.yml new file mode 100644 index 00000000..488e36ab --- /dev/null +++ b/changelogs/fragments/563-version-build-ansible.yml @@ -0,0 +1,3 @@ +minor_changes: + - "Adjust the ``pip install antsibull`` call in the ``build-ansible.sh`` script added to the ``ansible`` source distribution + to use the version of antsibull used to build the ansible release (https://github.com/ansible-community/antsibull/pull/563)." diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index f2e1732f..63975268 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -38,6 +38,7 @@ from antsibull.constants import MINIMUM_ANSIBLE_VERSIONS from antsibull.python_metadata import BuildMetaMaker, LegacyBuildMetaMaker +from . import __version__ as antsibull_version from .build_changelog import ReleaseNotes from .changelog import ChangelogData, get_changelog from .dep_closure import check_collection_dependencies @@ -394,7 +395,9 @@ def write_build_script( get_antsibull_data("build-ansible.sh.j2").decode("utf-8") ) build_ansible_contents = build_ansible_tmpl.render( - version=ansible_version, ansible_core_version=ansible_core_version + version=ansible_version, + ansible_core_version=ansible_core_version, + antsibull_version=antsibull_version, ) with open(build_ansible_filename, "w", encoding="utf-8") as f: diff --git a/src/antsibull/data/build-ansible.sh.j2 b/src/antsibull/data/build-ansible.sh.j2 index 7b7f93b6..0cb68ef4 100644 --- a/src/antsibull/data/build-ansible.sh.j2 +++ b/src/antsibull/data/build-ansible.sh.j2 @@ -15,7 +15,7 @@ MAJOR="{{ version.major }}" # For idempotency, remove build data or built output first rm -rf ansible-build-data built -pip3 install --user --upgrade antsibull +pip3 install --user --upgrade "antsibull=={{ antsibull_version }}" git clone https://github.com/ansible-community/ansible-build-data.git mkdir -p built collection-cache diff --git a/tests/test_data/package-files/7.5.0/build-ansible.sh b/tests/test_data/package-files/7.5.0/build-ansible.sh index 7f87fc4f..8582de56 100755 --- a/tests/test_data/package-files/7.5.0/build-ansible.sh +++ b/tests/test_data/package-files/7.5.0/build-ansible.sh @@ -11,7 +11,7 @@ MAJOR="7" # For idempotency, remove build data or built output first rm -rf ansible-build-data built -pip3 install --user --upgrade antsibull +pip3 install --user --upgrade "antsibull==(ANTSIBULL_VERSION)" git clone https://github.com/ansible-community/ansible-build-data.git mkdir -p built collection-cache BUILD_DATA_DIR="ansible-build-data/${MAJOR}" diff --git a/tests/test_data/package-files/8.1.0/build-ansible.sh b/tests/test_data/package-files/8.1.0/build-ansible.sh index e57495af..01e5f402 100755 --- a/tests/test_data/package-files/8.1.0/build-ansible.sh +++ b/tests/test_data/package-files/8.1.0/build-ansible.sh @@ -11,7 +11,7 @@ MAJOR="8" # For idempotency, remove build data or built output first rm -rf ansible-build-data built -pip3 install --user --upgrade antsibull +pip3 install --user --upgrade "antsibull==(ANTSIBULL_VERSION)" git clone https://github.com/ansible-community/ansible-build-data.git mkdir -p built collection-cache BUILD_DATA_DIR="ansible-build-data/${MAJOR}" diff --git a/tests/test_data/package-files/force_setup_cfg/8.1.0/build-ansible.sh b/tests/test_data/package-files/force_setup_cfg/8.1.0/build-ansible.sh index e57495af..01e5f402 100755 --- a/tests/test_data/package-files/force_setup_cfg/8.1.0/build-ansible.sh +++ b/tests/test_data/package-files/force_setup_cfg/8.1.0/build-ansible.sh @@ -11,7 +11,7 @@ MAJOR="8" # For idempotency, remove build data or built output first rm -rf ansible-build-data built -pip3 install --user --upgrade antsibull +pip3 install --user --upgrade "antsibull==(ANTSIBULL_VERSION)" git clone https://github.com/ansible-community/ansible-build-data.git mkdir -p built collection-cache BUILD_DATA_DIR="ansible-build-data/${MAJOR}" diff --git a/tests/verify_package_files.py b/tests/verify_package_files.py index ea90667b..bceca20a 100644 --- a/tests/verify_package_files.py +++ b/tests/verify_package_files.py @@ -24,6 +24,7 @@ import aiohttp from packaging.version import Version as PypiVer +import antsibull.build_ansible_commands from antsibull.cli import antsibull_build from antsibull.constants import MINIMUM_ANSIBLE_VERSIONS @@ -38,6 +39,7 @@ SDIST_PATH = f"{PYPI_PATH}/source/a/ansible/ansible-{{version}}.tar.gz" ANTSIBULL_BUILD = os.environ.get("ANTSIBULL_BUILD", "antsibull-build") +PLACEHOLDER_ANTSIBULL_VERSION = "(ANTSIBULL_VERSION)" @dataclasses.dataclass @@ -154,7 +156,11 @@ def generate_package_files( if force_generate_setup_cfg else contextlib.nullcontext() ) - with cm, cm2: + with cm, cm2, patch_object( + antsibull.build_ansible_commands, + "antsibull_version", + PLACEHOLDER_ANTSIBULL_VERSION, + ): if r := antsibull_build.run( [ "antsibull-build", @@ -189,6 +195,16 @@ def patch_dict(mapping: MutableMapping, key: Any, value: Any) -> Iterator[None]: mapping[key] = old +@contextlib.contextmanager +def patch_object(object: Any, attr: str, new_value: Any) -> Iterator[None]: + old_value = getattr(object, attr) + try: + setattr(object, attr, new_value) + yield + finally: + setattr(object, attr, old_value) + + def write_file_list( version: str, source_dir: Path, build_dir: Path | None = None ) -> DIST_TUPLE: