From 61ce14f07273a9910ac502a3eda9041e634d1298 Mon Sep 17 00:00:00 2001 From: Jitka Halova Date: Thu, 19 Mar 2026 20:18:16 +0100 Subject: [PATCH] Add repair-metadata command for Python repos closes #1340 Assisted by: Claude Sonnet 4 --- CHANGES/1340.feature | 1 + CHANGES/pulp-glue/1340.feature | 1 + pulp-glue/src/pulp_glue/python/context.py | 5 +++++ src/pulpcore/cli/python/repository.py | 21 ++++++++++++++++++++ tests/scripts/pulp_python/test_repository.sh | 5 +++++ 5 files changed, 33 insertions(+) create mode 100644 CHANGES/1340.feature create mode 100644 CHANGES/pulp-glue/1340.feature diff --git a/CHANGES/1340.feature b/CHANGES/1340.feature new file mode 100644 index 000000000..9e412feea --- /dev/null +++ b/CHANGES/1340.feature @@ -0,0 +1 @@ +Added `repair-metadata` command to `pulp python repository` for repairing package metadata. diff --git a/CHANGES/pulp-glue/1340.feature b/CHANGES/pulp-glue/1340.feature new file mode 100644 index 000000000..fe82c9103 --- /dev/null +++ b/CHANGES/pulp-glue/1340.feature @@ -0,0 +1 @@ +Added `repair_metadata` method to `PulpPythonRepositoryContext` for `pulp_python>=3.26.0`. diff --git a/pulp-glue/src/pulp_glue/python/context.py b/pulp-glue/src/pulp_glue/python/context.py index 5614136b8..7828ee076 100644 --- a/pulp-glue/src/pulp_glue/python/context.py +++ b/pulp-glue/src/pulp_glue/python/context.py @@ -150,6 +150,7 @@ class PulpPythonRepositoryContext(PulpRepositoryContext): CAPABILITIES = { "sync": [PluginRequirement("python")], "pulpexport": [PluginRequirement("python", specifier=">=3.11.0")], + "repair_metadata": [PluginRequirement("python", specifier=">=3.26.0")], } NEEDS_PLUGINS = [PluginRequirement("python", specifier=">=3.1.0")] @@ -158,3 +159,7 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En if "autopublish" in body: self.pulp_ctx.needs_plugin(PluginRequirement("python", specifier=">=3.3.0")) return body + + def repair_metadata(self) -> t.Any: + self.needs_capability("repair_metadata") + return self.call("repair_metadata", parameters={self.HREF: self.pulp_href}) diff --git a/src/pulpcore/cli/python/repository.py b/src/pulpcore/cli/python/repository.py index b78ed2909..c06bffd31 100644 --- a/src/pulpcore/cli/python/repository.py +++ b/src/pulpcore/cli/python/repository.py @@ -183,3 +183,24 @@ def sync( ) repository_ctx.sync(body=body) + + +@repository.command() +@name_option +@href_option +@repository_lookup_option +@pass_repository_context +@pass_pulp_context +def repair_metadata( + pulp_ctx: PulpCLIContext, + repository_ctx: PulpRepositoryContext, + /, +) -> None: + """ + Repair the metadata for all immediate and on-demand packages in the latest version + of the specified repository. For immediate wheel packages, also repair metadata + artifacts derived from the main artifact. + """ + assert isinstance(repository_ctx, PulpPythonRepositoryContext) + result = repository_ctx.repair_metadata() + pulp_ctx.output_result(result) diff --git a/tests/scripts/pulp_python/test_repository.sh b/tests/scripts/pulp_python/test_repository.sh index 54f0562d3..17f8de7d1 100755 --- a/tests/scripts/pulp_python/test_repository.sh +++ b/tests/scripts/pulp_python/test_repository.sh @@ -32,4 +32,9 @@ expect_succ test "$(echo "$OUTPUT" | jq -r '.remote')" = "" expect_succ pulp python repository list test "$(echo "$OUTPUT" | jq -r '.|length')" != "0" +if pulp debug has-plugin --name "python" --specifier ">=3.26.0"; then + expect_succ pulp python repository repair-metadata --repository "cli_test_python_repo" + expect_succ test "$(echo "$OUTPUT" | jq -r '.state')" = "completed" +fi + expect_succ pulp python repository destroy --name "cli_test_python_repo"