Skip to content

Commit

Permalink
ansible_core: remove get_ansible_core_package_name()
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmax23 committed Jan 21, 2024
1 parent b970dc3 commit c79e05f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 61 deletions.
51 changes: 8 additions & 43 deletions src/antsibull_core/ansible_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,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 +124,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 +171,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"),
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

0 comments on commit c79e05f

Please sign in to comment.