Skip to content
Draft
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
2 changes: 1 addition & 1 deletion CHANGES/pulp-glue/1391.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added `PulpPythonBlocklistEntryContext` for `pulp_python>=3.30.0`.
Added `PulpPythonBlocklistEntryContext` for `pulp_python>=3.30.2`.
2 changes: 1 addition & 1 deletion pulp-glue/src/pulp_glue/python/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class PulpPythonBlocklistEntryContext(PulpEntityContext):
ENTITIES = _("blocklist entries")
HREF = "python_python_python_blocklist_entry_href"
ID_PREFIX = "repositories_python_python_blocklist_entries"
NEEDS_PLUGINS = [PluginRequirement("python", specifier=">=3.30.0")]
NEEDS_PLUGINS = [PluginRequirement("python", specifier=">=3.30.2")]
repository_ctx: PulpPythonRepositoryContext

def __init__(
Expand Down
92 changes: 55 additions & 37 deletions src/pulpcore/cli/python/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def repository() -> None:
)


@repository.group(needs_plugins=[PluginRequirement("python", specifier=">=3.30.0")])
@repository.group(needs_plugins=[PluginRequirement("python", specifier=">=3.30.2")])
@pass_repository_context
@pass_pulp_context
@click.pass_context
Expand All @@ -181,33 +181,61 @@ def blocklist(
click.option("--version", help=_HELP_BLOCKLIST_VERSION),
click.option("--filename", help=_HELP_BLOCKLIST_FILENAME),
]
blocklist_lookup_options = [
pulp_option(
"--name",
help=_HELP_BLOCKLIST_NAME,
callback=lookup_callback("name"),
expose_value=False,
),
pulp_option(
"--version",
help=_HELP_BLOCKLIST_VERSION,
callback=lookup_callback("version"),
expose_value=False,
),
pulp_option(
"--filename",
help=_HELP_BLOCKLIST_FILENAME,
callback=lookup_callback("filename"),
expose_value=False,
),
href_option,
]

blocklist.add_command(
create_command(name="add", decorators=nested_lookup_options + blocklist_options)
)
blocklist.add_command(list_command(decorators=nested_lookup_options + blocklist_options))
blocklist.add_command(show_command(decorators=nested_lookup_options + blocklist_lookup_options))


def _blocklist_lookup(
name: str | None,
version: str | None,
filename: str | None,
) -> dict[str, t.Any]:
if version and filename:
raise click.ClickException(_("'version' cannot be used with 'filename'."))
if version and not name:
raise click.ClickException(_("'version' requires 'name' to be provided."))
if name and filename:
raise click.ClickException(_("Exactly one of 'name' or 'filename' must be provided."))

if name:
lookup: dict[str, t.Any] = {"name": name}
if version:
lookup["version"] = version
else:
lookup["version__isnull"] = True
return lookup
elif filename:
return {"filename": filename}
return {}


@blocklist.command(name="show")
@repository_href_option
@repository_lookup_option
@click.option("--name", help=_HELP_BLOCKLIST_NAME)
@click.option("--version", help=_HELP_BLOCKLIST_VERSION)
@click.option("--filename", help=_HELP_BLOCKLIST_FILENAME)
@href_option
@pass_entity_context
@pass_pulp_context
def blocklist_show(
pulp_ctx: PulpCLIContext,
entity_ctx: PulpEntityContext,
/,
name: str | None,
version: str | None,
filename: str | None,
) -> None:
"""
Show a blocklist entry.
"""
assert isinstance(entity_ctx, PulpPythonBlocklistEntryContext)
lookup = _blocklist_lookup(name, version, filename)
if lookup:
entity_ctx.entity = lookup
pulp_ctx.output_result(entity_ctx.entity)


@blocklist.command(name="remove")
Expand All @@ -229,19 +257,9 @@ def blocklist_remove(
Remove a blocklist entry.
"""
assert isinstance(entity_ctx, PulpPythonBlocklistEntryContext)
if version and filename:
raise click.ClickException(_("'version' cannot be used with 'filename'."))
if version and not name:
raise click.ClickException(_("'version' requires 'name' to be provided."))
if name and filename:
raise click.ClickException(_("Exactly one of 'name' or 'filename' must be provided."))

if name:
entity_ctx.entity = {"name": name}
if version:
entity_ctx.entity = {"version": version}
if filename:
entity_ctx.entity = {"filename": filename}
lookup = _blocklist_lookup(name, version, filename)
if lookup:
entity_ctx.entity = lookup
entity_ctx.delete()


Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_python/test_blocklist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "python" --specifier ">=3.30.0" || exit 23
pulp debug has-plugin --name "python" --specifier ">=3.30.2" || exit 23

cleanup() {
pulp python repository destroy --name "cli_test_python_blocklist" || true
Expand Down
Loading