Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Remove support for old ansible versions #132

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 8 additions & 44 deletions src/antsibull_core/ansible_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from __future__ import annotations

import ast
import asyncio
import os
import re
import tempfile
Expand Down Expand Up @@ -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]:
"""
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
"""
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"),
Expand Down
30 changes: 7 additions & 23 deletions src/antsibull_core/dependency_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_dependency_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
18 changes: 0 additions & 18 deletions tests/units/test_ansible_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down
4 changes: 2 additions & 2 deletions tests/units/test_parse_pieces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down