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/982.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ability to serve a specific repository version of a PyPI index.
3 changes: 3 additions & 0 deletions pulp_python/app/pypi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ def get_repository_version(distribution):
"""Finds the repository version this distribution is serving."""
pub = distribution.publication
rep = distribution.repository
rep_version = distribution.repository_version
if pub:
return pub.repository_version or pub.repository.latest_version()
elif rep:
return rep.latest_version()
elif rep_version:
return rep_version
else:
raise Http404("No repository associated with this index")

Expand Down
4 changes: 4 additions & 0 deletions pulp_python/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class PythonDistributionSerializer(core_serializers.DistributionSerializer):
queryset=core_models.Publication.objects.exclude(complete=False),
allow_null=True,
)
repository_version = core_serializers.RepositoryVersionRelatedField(
required=False, help_text=_("RepositoryVersion to be served."), allow_null=True
)
base_url = serializers.SerializerMethodField(read_only=True)
allow_uploads = serializers.BooleanField(
default=True, help_text=_("Allow packages to be uploaded to this index.")
Expand All @@ -74,6 +77,7 @@ def get_base_url(self, obj):
class Meta:
fields = core_serializers.DistributionSerializer.Meta.fields + (
"publication",
"repository_version",
"allow_uploads",
"remote",
)
Expand Down
2 changes: 1 addition & 1 deletion pulp_python/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _gen_python_distribution(
ver_href = f"{repo_href}versions/{version}/"
else:
ver_href = get_href(version)
body = {"repository_version": ver_href}
body["repository_version"] = ver_href
else:
body["repository"] = repo_href
kwargs = {}
Expand Down
5 changes: 5 additions & 0 deletions pulp_python/tests/functional/api/test_pypi_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ def test_pypi_json(python_remote_factory, python_repo_with_sync, python_distribu
distro = python_distribution_factory(repository=repo)
response = requests.get(urljoin(distro.base_url, "pypi/shelf-reader/json"))
assert_pypi_json(response.json())
# Test serving a repository version
distro = python_distribution_factory(repository=repo, version="1")
assert distro.repository is None
response = requests.get(urljoin(distro.base_url, "pypi/shelf-reader/json"))
assert_pypi_json(response.json())


@pytest.mark.parallel
Expand Down
Loading