From b970dc351004dbeb9aee677f1e11557f9d95037a Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sun, 24 Dec 2023 00:54:56 +0000 Subject: [PATCH 1/3] Remove support for old ansible versions Fixes: https://github.com/ansible-community/antsibull-core/issues/123 --- src/antsibull_core/dependency_files.py | 30 ++++++----------------- tests/functional/test_dependency_files.py | 2 +- tests/units/test_parse_pieces.py | 4 +-- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/antsibull_core/dependency_files.py b/src/antsibull_core/dependency_files.py index 303fa82..9e3120e 100644 --- a/src/antsibull_core/dependency_files.py +++ b/src/antsibull_core/dependency_files.py @@ -58,20 +58,18 @@ def _parse_name_version_spec_file(filename: StrPath) -> DependencyFileData: for line in parse_pieces_file(filename): record = [entry.strip() for entry in line.split(":", 1)] - if record[0] in ("_ansible_version", "_acd_version"): + if record[0] == "_ansible_version": if ansible_version is not None: raise InvalidFileFormat( - f"{filename!r} specified _ansible_version/_acd_version" - " more than once" + f"{filename!r} specified _ansible_version more than once" ) ansible_version = record[1] continue - if record[0] in ("_ansible_base_version", "_ansible_core_version"): + if record[0] == "_ansible_core_version": if ansible_core_version is not None: raise InvalidFileFormat( - f"{filename!r} specified _ansible_base_version/_ansible_core_version more than" - " once" + f"{filename!r} specified _ansible_core_version more than once" ) ansible_core_version = record[1] continue @@ -105,8 +103,6 @@ class DepsFile: _ansible_version: X1.Y1.Z1 _ansible_core_version: X2.Y2.Z2 - (Instead of _ansible_core_version, _ansible_base_version can also be used.) - These are, respectively, the ansible version that was built and the ansible-core version which it was built against. Note that the ansible release will depend on a compatible version of that ansible-core version, not an exact dependency on that precise version. @@ -154,10 +150,7 @@ def write( with open(self.filename, "w", encoding="utf-8") as f: f.write(f"_ansible_version: {ansible_version}\n") - if ansible_version.major > 5: - f.write(f"_ansible_core_version: {ansible_core_version}\n") - else: - f.write(f"_ansible_base_version: {ansible_core_version}\n") + f.write(f"_ansible_core_version: {ansible_core_version}\n") if python_requires is not None: f.write(f"_python: {python_requires}\n") f.write("\n".join(records)) @@ -207,17 +200,8 @@ def write( records.sort() with open(self.filename, "w", encoding="utf-8") as f: - if ansible_version.major > 2: - # Ansible 3.0.0 and newer use semver, so we only need the major version - f.write(f"_ansible_version: {ansible_version.major}\n") - else: - f.write( - f"_ansible_version: {ansible_version.major}.{ansible_version.minor}\n" - ) - if ansible_version.major > 5: - f.write(f"_ansible_core_version: {ansible_core_version}\n") - else: - f.write(f"_ansible_base_version: {ansible_core_version}\n") + f.write(f"_ansible_version: {ansible_version.major}\n") + f.write(f"_ansible_core_version: {ansible_core_version}\n") if python_requires is not None: f.write(f"_python: {python_requires}\n") f.write("\n".join(records)) diff --git a/tests/functional/test_dependency_files.py b/tests/functional/test_dependency_files.py index 43cc597..3e53c1e 100644 --- a/tests/functional/test_dependency_files.py +++ b/tests/functional/test_dependency_files.py @@ -9,7 +9,7 @@ from antsibull_core.dependency_files import BuildFile SIMPLE_TEST_FILE = """_ansible_version: 4 -_ansible_base_version: 2.11.0rc1 +_ansible_core_version: 2.11.0rc1 community.general: >=1.0.0,<2.0.0 community.routeros: >=2.0.0-a2,<3.0.0 """ diff --git a/tests/units/test_parse_pieces.py b/tests/units/test_parse_pieces.py index 53636a2..feb7f46 100644 --- a/tests/units/test_parse_pieces.py +++ b/tests/units/test_parse_pieces.py @@ -28,7 +28,7 @@ DEPS = """ _ansible_version: 2.10.5 # this is a comment -_ansible_base_version: 2.10.4 +_ansible_core_version: 2.10.4 # supported by ansible ansible.netcommon: 1.4.1 ansible.posix: 1.1.1 @@ -70,7 +70,7 @@ BUILD = """ _ansible_version: 2.10 # this is a comment -_ansible_base_version: 2.10.1 +_ansible_core_version: 2.10.1 # supported by ansible ansible.netcommon: >=1.2.0,<2.0.0 ansible.posix: >=1.1.0,<2.0.0 From 14fa222b92611683fc03de77a8011dc09bddb596 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sun, 21 Jan 2024 22:21:48 +0000 Subject: [PATCH 2/3] ansible_core: remove get_ansible_core_package_name() --- src/antsibull_core/ansible_core.py | 52 +++++------------------------- tests/units/test_ansible_core.py | 18 ----------- 2 files changed, 8 insertions(+), 62 deletions(-) diff --git a/src/antsibull_core/ansible_core.py b/src/antsibull_core/ansible_core.py index d831f43..bea28f6 100644 --- a/src/antsibull_core/ansible_core.py +++ b/src/antsibull_core/ansible_core.py @@ -9,7 +9,6 @@ from __future__ import annotations import ast -import asyncio import os import re import tempfile @@ -74,37 +73,19 @@ async def get_release_info( self, package_name: t.Optional[str] = None ) -> dict[str, t.Any]: """ - Retrieve information about releases of the ansible-core/ansible-base package from pypi. + Retrieve information about releases of the ansible-core package from pypi. - :arg package_name: Either 'ansible-core', 'ansible-base', or None. + :arg package_name: Either 'ansible-core' or None. :returns: The dict which represents the release info keyed by version number. To examine the data structure, use:: curl https://pypi.org/pypi/ansible-core/json| python3 -m json.tool - - .. note:: Returns an aggregate of ansible-base and ansible-core releases. """ - # Retrieve the ansible-base and ansible-core package info from pypi - tasks = [] - for a_package_name in ( - ("ansible-core", "ansible-base") - if package_name is None - else (package_name,) - ): - query_url = urljoin(self.pypi_server_url, f"pypi/{a_package_name}/json") - tasks.append(asyncio.create_task(self._get_json(query_url))) - - # Note: gather maintains the order of results - results = await asyncio.gather(*tasks) - if len(results) > 1: - release_info = results[1]["releases"] # ansible-base information - release_info.update(results[0]["releases"]) # ansible-core information - elif len(results) == 1: - release_info = results[0]["releases"] - else: - release_info = {} - - return release_info + # Retrieve the ansible-core package info from pypi + package_name = package_name or "ansible-core" + query_url = urljoin(self.pypi_server_url, f"pypi/{package_name}/json") + resp = await self._get_json(query_url) + return resp["releases"] async def get_versions(self) -> list[PypiVer]: """ @@ -142,7 +123,7 @@ async def retrieve(self, ansible_core_version: str, download_dir: StrPath) -> st :arg download_dir: Directory to download the tarball to. :returns: The name of the downloaded tarball. """ - package_name = get_ansible_core_package_name(ansible_core_version) + package_name = "ansible-core" release_info = await self.get_release_info(package_name) tar_filename = f"{package_name}-{ansible_core_version}.tar.gz" @@ -189,23 +170,6 @@ async def retrieve(self, ansible_core_version: str, download_dir: StrPath) -> st return tar_path -def get_ansible_core_package_name(ansible_core_version: str | PypiVer) -> str: - """ - Returns the name of the minimal ansible package. - - :arg ansible_core_version: The version of the minimal ansible package to retrieve the - name for. - :returns: 'ansible-core' when the version is 2.11 or higher. Otherwise 'ansible-base'. - """ - if not isinstance(ansible_core_version, PypiVer): - ansible_core_version = PypiVer(ansible_core_version) - - if ansible_core_version.major <= 2 and ansible_core_version.minor <= 10: - return "ansible-base" - - return "ansible-core" - - def _get_source_version(ansible_core_source: StrPath) -> PypiVer: with open( os.path.join(ansible_core_source, "lib", "ansible", "release.py"), diff --git a/tests/units/test_ansible_core.py b/tests/units/test_ansible_core.py index 3a3b6d7..9f35f2d 100644 --- a/tests/units/test_ansible_core.py +++ b/tests/units/test_ansible_core.py @@ -8,24 +8,6 @@ import antsibull_core.ansible_core as ac -@pytest.mark.parametrize( - "version", - ("2.9", "2.9.10", "1.0", "1", "0.7", "2.10", "2.10.0", "2.10.8", "2.10.12"), -) -def test_get_core_package_name_returns_ansible_base(version): - assert ac.get_ansible_core_package_name(version) == "ansible-base" - assert ac.get_ansible_core_package_name(Version(version)) == "ansible-base" - - -@pytest.mark.parametrize( - "version", - ("2.11", "2.11.0", "2.11.8", "2.11.12", "2.13", "2.11.0a1", "3", "3.7.10"), -) -def test_get_core_package_name_returns_ansible_core(version): - assert ac.get_ansible_core_package_name(version) == "ansible-core" - assert ac.get_ansible_core_package_name(Version(version)) == "ansible-core" - - @pytest.mark.parametrize( "version, is_devel", [ From 804e3f7eb487ff8ab21d8003b17d26a35c5afb6c Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Mon, 22 Jan 2024 23:23:07 +0000 Subject: [PATCH 3/3] add changelog entries --- changelogs/fragments/130-old-ansible-rm.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 changelogs/fragments/130-old-ansible-rm.yaml diff --git a/changelogs/fragments/130-old-ansible-rm.yaml b/changelogs/fragments/130-old-ansible-rm.yaml new file mode 100644 index 0000000..e6e13d4 --- /dev/null +++ b/changelogs/fragments/130-old-ansible-rm.yaml @@ -0,0 +1,15 @@ +--- +breaking_changes: + - "Drop support for building Ansible versions less than 6.0.0 + (https://github.com/ansible-community/antsibull-core/pull/132)." +removed_features: + - "``ansible_core`` - remove ``get_ansible_core_package_name()`` function. + This is no longer necessary now that support for ansible-base has been dropped + (https://github.com/ansible-community/antsibull-core/pull/132)." + - "``ansible_core`` - remove ansible-core/ansible-base normalization in + ``AnsibleCorePyPiClient``. Data retrieval is only supported for ``ansible-core`` + (https://github.com/ansible-community/antsibull-core/pull/132)." + - "``dependency_files`` - drop support for ``_ansible_base_version`` and + ``_acd_version`` in pieces files. ``_ansible_core_version`` and + ``_ansible_version``, respectively, should be used instead + (https://github.com/ansible-community/antsibull-core/pull/132)."