From 0c70ee036ab5f5f34b5bb87430fd53621350721e Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 16 Apr 2024 07:42:39 +0200 Subject: [PATCH 1/4] Fix error message formatting. --- src/antsibull_core/ansible_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/antsibull_core/ansible_core.py b/src/antsibull_core/ansible_core.py index 692a59a..f3325c0 100644 --- a/src/antsibull_core/ansible_core.py +++ b/src/antsibull_core/ansible_core.py @@ -149,7 +149,7 @@ async def retrieve(self, ansible_core_version: str, download_dir: StrPath) -> st 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: From 90b3b1f3ded1029531f17723d85b74fba6000af9 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 16 Apr 2024 07:49:35 +0200 Subject: [PATCH 2/4] Accept filename starting with ansible_core as well. --- changelogs/fragments/158-ansible-core-pypi.yml | 2 ++ src/antsibull_core/ansible_core.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/158-ansible-core-pypi.yml diff --git a/changelogs/fragments/158-ansible-core-pypi.yml b/changelogs/fragments/158-ansible-core-pypi.yml new file mode 100644 index 0000000..9c26dc6 --- /dev/null +++ b/changelogs/fragments/158-ansible-core-pypi.yml @@ -0,0 +1,2 @@ +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 (https://github.com/ansible-community/antsibull-core/pull/158)." diff --git a/src/antsibull_core/ansible_core.py b/src/antsibull_core/ansible_core.py index f3325c0..74ad351 100644 --- a/src/antsibull_core/ansible_core.py +++ b/src/antsibull_core/ansible_core.py @@ -141,7 +141,10 @@ async def retrieve(self, ansible_core_version: str, download_dir: StrPath) -> st digests = {} for release in release_info[ansible_core_version]: if release["filename"].startswith( - f"{package_name}-{ansible_core_version}.tar." + ( + f"{package_name}-{ansible_core_version}.tar.", + f"{package_name.replace('-', '_')}-{ansible_core_version}.tar.", + ) ): pypi_url = release["url"] digests = release["digests"] From cc0f19ca09fcaf04e82b70f3c7b0f2d86845cd16 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Tue, 16 Apr 2024 18:03:35 +0000 Subject: [PATCH 3/4] AnsibleCorePyPiClient.retrieve: ensure the correct filename is returned Code in antsibull relies on the top-level directory and the archive having the same basename. --- src/antsibull_core/ansible_core.py | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/antsibull_core/ansible_core.py b/src/antsibull_core/ansible_core.py index 74ad351..fc26d32 100644 --- a/src/antsibull_core/ansible_core.py +++ b/src/antsibull_core/ansible_core.py @@ -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. @@ -125,27 +128,34 @@ 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.", - f"{package_name.replace('-', '_')}-{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 From 460a7ed9bcedee608b880280904469620d8a76b5 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 16 Apr 2024 20:54:44 +0200 Subject: [PATCH 4/4] Update changelog. --- changelogs/fragments/158-ansible-core-pypi.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelogs/fragments/158-ansible-core-pypi.yml b/changelogs/fragments/158-ansible-core-pypi.yml index 9c26dc6..e06a4f8 100644 --- a/changelogs/fragments/158-ansible-core-pypi.yml +++ b/changelogs/fragments/158-ansible-core-pypi.yml @@ -1,2 +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 (https://github.com/ansible-community/antsibull-core/pull/158)." + - "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 `__ support in setuptools 69.3.0 (https://github.com/ansible-community/antsibull-core/pull/158)."