Skip to content

Commit 98dd71c

Browse files
committed
Adds repository_version to the Python Distribution API.
This allows serving a specific repository version.
1 parent 198588b commit 98dd71c

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

CHANGES/982.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ability to serve a specific repository version of a PyPI index.

pulp_python/app/pypi/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ def get_repository_version(distribution):
8989
"""Finds the repository version this distribution is serving."""
9090
pub = distribution.publication
9191
rep = distribution.repository
92+
rep_version = distribution.repository_version
9293
if pub:
9394
return pub.repository_version or pub.repository.latest_version()
9495
elif rep:
9596
return rep.latest_version()
97+
elif rep_version:
98+
return rep_version
9699
else:
97100
raise Http404("No repository associated with this index")
98101

pulp_python/app/serializers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class PythonDistributionSerializer(core_serializers.DistributionSerializer):
5353
queryset=core_models.Publication.objects.exclude(complete=False),
5454
allow_null=True,
5555
)
56+
repository_version = core_serializers.RepositoryVersionRelatedField(
57+
required=False, help_text=_("RepositoryVersion to be served."), allow_null=True
58+
)
5659
base_url = serializers.SerializerMethodField(read_only=True)
5760
allow_uploads = serializers.BooleanField(
5861
default=True, help_text=_("Allow packages to be uploaded to this index.")
@@ -74,6 +77,7 @@ def get_base_url(self, obj):
7477
class Meta:
7578
fields = core_serializers.DistributionSerializer.Meta.fields + (
7679
"publication",
80+
"repository_version",
7781
"allow_uploads",
7882
"remote",
7983
)

pulp_python/pytest_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _gen_python_distribution(
7373
ver_href = f"{repo_href}versions/{version}/"
7474
else:
7575
ver_href = get_href(version)
76-
body = {"repository_version": ver_href}
76+
body["repository_version"] = ver_href
7777
else:
7878
body["repository"] = repo_href
7979
kwargs = {}

pulp_python/tests/functional/api/test_pypi_apis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ def test_pypi_json(python_remote_factory, python_repo_with_sync, python_distribu
267267
distro = python_distribution_factory(repository=repo)
268268
response = requests.get(urljoin(distro.base_url, "pypi/shelf-reader/json"))
269269
assert_pypi_json(response.json())
270-
270+
# Test serving a repository version
271+
distro = python_distribution_factory(repository=repo, version="1")
272+
assert distro.repository is None
273+
response = requests.get(urljoin(distro.base_url, "pypi/shelf-reader/json"))
274+
assert_pypi_json(response.json())
271275

272276
@pytest.mark.parallel
273277
def test_pypi_json_content_app(

0 commit comments

Comments
 (0)