Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGES/1324.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for serving Python content form a repository version.
18 changes: 18 additions & 0 deletions pulp-glue/src/pulp_glue/python/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En
body["publication"] = None
if "repository" not in body and "publication" in body:
body["repository"] = None

if self.pulp_ctx.has_plugin(PluginRequirement("python", specifier=">=3.21.0")):
version = body.pop("version", None)
if version is not None:
if repository_href := body.pop("repository", None):
body["repository_version"] = f"{repository_href}versions/{version}/"
body["repository"] = None
else:
current_entity = getattr(self, "entity", {})
if repository_href := current_entity.get("repository"):
body["repository_version"] = f"{repository_href}versions/{version}/"
body["repository"] = None
elif repository_version_href := current_entity.get("repository_version"):
repository_href = repository_version_href.partition("versions")[0]
body["repository_version"] = f"{repository_href}versions/{version}/"
elif "repository" in body:
body["repository_version"] = None

return body


Expand Down
7 changes: 7 additions & 0 deletions src/pulpcore/cli/python/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
context_table={"python:python": PulpPythonRepositoryContext},
help=_(
"Repository to be used for auto-distributing."
" When used with --version, this will create repository_version instead."
" When set, this will unset the 'publication'."
" Specified as '[[<plugin>:]<type>:]<name>' or as href."
),
Expand Down Expand Up @@ -75,6 +76,12 @@ def distribution(ctx: click.Context, pulp_ctx: PulpCLIContext, /, distribution_t
),
),
repository_option,
pulp_option(
"--version",
type=int,
help=_("A repository version number, leave blank for latest."),
needs_plugins=[PluginRequirement("python", specifier=">=3.21.0")],
),
content_guard_option,
pulp_option(
"--allow-uploads/--block-uploads",
Expand Down
37 changes: 37 additions & 0 deletions tests/scripts/pulp_python/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cleanup() {
pulp python repository destroy --name "cli_test_python_distribution_repository" || true
pulp python remote destroy --name "cli_test_python_distribution_remote" || true
pulp python distribution destroy --name "cli_test_python_distro" || true
pulp python distribution destroy --name "cli_test_python_distro_repo_version" || true
}
trap cleanup EXIT

Expand Down Expand Up @@ -42,3 +43,39 @@ expect_succ pulp python distribution update \
--remote "cli_test_python_distribution_remote"

expect_succ pulp python distribution destroy --distribution "cli_test_python_distro"

# Test repository_version functionality
pulp debug has-plugin --name "python" --specifier ">=3.21.0" || exit 0

expect_succ pulp python distribution create \
--name "cli_test_python_distro_repo_version" \
--base-path "cli_test_python_distro_repo_version" \
--repository "cli_test_python_distribution_repository" \
--version 0
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version | contains("/versions/0/")'
echo "$OUTPUT" | jq -e '.repository == null'

expect_succ pulp python distribution update \
--distribution "cli_test_python_distro_repo_version" \
--repository "cli_test_python_distribution_repository" \
--version 1
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version | contains("/versions/1/")'
echo "$OUTPUT" | jq -e '.repository == null'

expect_succ pulp python distribution update \
--distribution "cli_test_python_distro_repo_version" \
--version 0
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version | contains("/versions/0/")'
echo "$OUTPUT" | jq -e '.repository == null'

expect_succ pulp python distribution update \
--distribution "cli_test_python_distro_repo_version" \
--repository "cli_test_python_distribution_repository"
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version == null'
echo "$OUTPUT" | jq -e '.repository != null'

expect_succ pulp python distribution destroy --distribution "cli_test_python_distro_repo_version"
Loading