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

Accept ansible-core filename starting with ansible_core-<version>.tar as well; fix error message formatting #158

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions changelogs/fragments/158-ansible-core-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "Adjusting ansible-core PyPI code to also accept a filename starting with ``ansible_core``, which seems to be in use since ansible-core 2.16.6
due to `PEP-625 <https://peps.python.org/pep-0625/>`__ support in setuptools 69.3.0 (https://github.com/ansible-community/antsibull-core/pull/158)."
33 changes: 23 additions & 10 deletions src/antsibull_core/ansible_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ async def get_latest_version(self) -> PypiVer:
versions = await self.get_versions()
return versions[0]

async def retrieve(self, ansible_core_version: str, download_dir: StrPath) -> str:
# TODO(anyone): Make function less complex
async def retrieve( # noqa C901
self, ansible_core_version: str, download_dir: StrPath
) -> str:
"""
Get the release from pypi.

Expand All @@ -125,31 +128,41 @@ async def retrieve(self, ansible_core_version: str, download_dir: StrPath) -> st
"""
package_name = "ansible-core"

tar_filename = f"{package_name}-{ansible_core_version}.tar.gz"
# https://github.com/pypa/setuptools/pull/4286
# Newer setuptools versions perform dist filename normalization
tar_filenames = (
f"{package_name.replace('-', '_')}-{ansible_core_version}.tar.gz",
f"{package_name}-{ansible_core_version}.tar.gz",
)
tar_filename = tar_filenames[0]
tar_path = os.path.join(download_dir, tar_filename)

lib_ctx = app_context.lib_ctx.get()
if lib_ctx.ansible_core_cache and lib_ctx.trust_ansible_core_cache:
cached_path = os.path.join(lib_ctx.ansible_core_cache, tar_filename)
if os.path.isfile(cached_path):
await copy_file(cached_path, tar_path, check_content=False)
return tar_path
for tar_filename in tar_filenames:
cached_path = os.path.join(
t.cast(str, lib_ctx.ansible_core_cache), tar_filename
)
if os.path.isfile(cached_path):
tar_path = os.path.join(download_dir, tar_filename)
await copy_file(cached_path, tar_path, check_content=False)
return tar_path

release_info = await self.get_release_info(package_name)

pypi_url = ""
digests = {}
for release in release_info[ansible_core_version]:
if release["filename"].startswith(
f"{package_name}-{ansible_core_version}.tar."
):
if release["filename"] in tar_filenames:
tar_filename = release["filename"]
tar_path = os.path.join(download_dir, tar_filename)
pypi_url = release["url"]
digests = release["digests"]
break
else: # for-else: http://bit.ly/1ElPkyg
raise UnknownVersion(
f"{package_name} {ansible_core_version} does not"
" exist on {self.pypi_server_url}"
f" exist on {self.pypi_server_url}"
)

if lib_ctx.ansible_core_cache and "sha256" in digests:
Expand Down