Skip to content

Commit 12405cc

Browse files
authored
Merge pull request #243 from asmacdo/split-distribution
Add detail python distribution
2 parents ff5c179 + 754de77 commit 12405cc

File tree

8 files changed

+61
-18
lines changed

8 files changed

+61
-18
lines changed

docs/_scripts/distribution.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Distributions are created asynchronously. Create one, and specify the publication that will
22
# be served at the base path specified.
3-
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/distributions/ \
3+
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/distributions/python/pypi/ \
44
name='baz' \
55
base_path='foo' \
66
publication=$PUBLICATION_HREF | jq -r '.task')

docs/_static/api.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/workflows/publish-host.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,17 @@ demonstrated in :ref:`using distributions<using-distributions>`.
4141
Distribution GET Response::
4242

4343
{
44-
"_created": "2019-04-29T15:58:07.586250Z",
45-
"_href": "/pulp/api/v3/distributions/63d532cc-94ea-402c-bb6d-2340242c6df8/",
44+
"_created": "2019-05-13T12:39:48.698103Z",
45+
"_href": "/pulp/api/v3/distributions/python/pypi/682d64c3-fee1-411c-a3af-3f74cab56c5e/",
4646
"base_path": "foo",
4747
"base_url": "localhost:24816/pulp/content/foo",
4848
"content_guard": null,
4949
"name": "baz",
50-
"publication": "/pulp/api/v3/publications/python/pypi/4cc1ddbb-64ff-4795-894a-09d5ca372774/",
51-
"publisher": null,
52-
"remote": null,
53-
"repository": null
50+
"publication": "/pulp/api/v3/publications/python/pypi/23f4c6fb-204b-45b6-8826-f61d4d38748d/",
51+
"remote": null
5452
}
5553

56-
Reference (pulpcore): `Distribution API Usage
57-
<https://docs.pulpproject.org/en/3.0/nightly/restapi.html#tag/distributions>`_
54+
Reference: `Python Distribution Usage <../restapi.html#tag/distributions>`_
5855

5956
.. _using-distributions:
6057

pulp_python/app/models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from django.db import models
44

5-
from pulpcore.plugin.models import Content, Model, Publication, Remote
5+
from pulpcore.plugin.models import Content, Model, Publication, PublicationDistribution, Remote
66

77
log = getLogger(__name__)
88

@@ -83,6 +83,14 @@ class Meta:
8383
unique_together = ('name', 'version_specifier', 'exclude', 'remote')
8484

8585

86+
class PythonDistribution(PublicationDistribution):
87+
"""
88+
Distribution for 'Python' Content.
89+
"""
90+
91+
TYPE = 'python'
92+
93+
8694
class PythonPackageContent(Content):
8795
"""
8896
A Content Type representing Python's Distribution Package.

pulp_python/app/serializers.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ class Meta:
5656
fields = ('name', 'version_specifier')
5757

5858

59+
class PythonDistributionSerializer(core_serializers.PublicationDistributionSerializer):
60+
"""
61+
Serializer for Pulp distributions for the Python type.
62+
63+
"""
64+
65+
class Meta:
66+
fields = core_serializers.PublicationDistributionSerializer.Meta.fields
67+
model = python_models.PythonDistribution
68+
69+
5970
class PythonPackageContentSerializer(core_serializers.SingleArtifactContentSerializer):
6071
"""
6172
A Serializer for PythonPackageContent.
@@ -334,6 +345,14 @@ class PythonPublicationSerializer(core_serializers.PublicationSerializer):
334345
A Serializer for PythonPublication.
335346
"""
336347

348+
distributions = core_serializers.DetailRelatedField(
349+
help_text=_('This publication is currently being hosted as configured by these '
350+
'distributions.'),
351+
source="pythondistribution_set",
352+
many=True,
353+
read_only=True,
354+
)
355+
337356
class Meta:
338-
fields = core_serializers.PublicationSerializer.Meta.fields
357+
fields = core_serializers.PublicationSerializer.Meta.fields + ('distributions',)
339358
model = python_models.PythonPublication

pulp_python/app/viewsets.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@
4040
}
4141

4242

43+
class PythonDistributionViewSet(platform.BaseDistributionViewSet):
44+
"""
45+
<!-- User-facing documentation, rendered as html-->
46+
Pulp Python Distributions are used to distribute
47+
<a href="../restapi.html#tag/publications">Python Publications.</a> <b> Pulp Python
48+
Distributions should not be confused with "Python Distribution" as defined by the Python
49+
community.</b> In Pulp usage, Python content is refered to as <a
50+
href="../restapi.html#tag/content">Python Package Content.</a>
51+
"""
52+
53+
endpoint_name = 'pypi'
54+
queryset = python_models.PythonDistribution.objects.all()
55+
serializer_class = python_serializers.PythonDistributionSerializer
56+
57+
4358
class PythonPackageContentFilter(platform.ContentFilter):
4459
"""
4560
FilterSet for PythonPackageContent.

pulp_python/tests/functional/api/test_download_content.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from urllib.parse import urljoin
55

66
from pulp_smash import api, config, utils
7-
from pulp_smash.pulp3.constants import DISTRIBUTION_PATH, REPO_PATH
7+
from pulp_smash.pulp3.constants import REPO_PATH
88
from pulp_smash.pulp3.utils import (
99
download_content_unit,
1010
gen_distribution,
@@ -15,6 +15,7 @@
1515
from pulp_python.tests.functional.constants import (
1616
PYTHON_FIXTURES_URL,
1717
PYTHON_REMOTE_PATH,
18+
PYTHON_DISTRIBUTION_PATH,
1819
)
1920
from pulp_python.tests.functional.utils import (
2021
get_python_content_paths,
@@ -77,7 +78,7 @@ def test_all(self):
7778
body = gen_distribution()
7879
body['publication'] = publication['_href']
7980
distribution = client.using_handler(api.task_handler).post(
80-
DISTRIBUTION_PATH,
81+
PYTHON_DISTRIBUTION_PATH,
8182
body
8283
)
8384
self.addCleanup(client.delete, distribution['_href'])

pulp_python/tests/functional/constants.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
from pulp_smash.constants import PULP_FIXTURES_BASE_URL
44
from pulp_smash.pulp3.constants import (
5+
BASE_DISTRIBUTION_PATH,
56
BASE_PUBLICATION_PATH,
67
BASE_REMOTE_PATH,
78
CONTENT_PATH
89
)
910

1011

12+
PYPI_URL = "https://pypi.org/"
13+
1114
PYTHON_CONTENT_NAME = 'python.python'
1215

1316
PYTHON_CONTENT_PATH = urljoin(CONTENT_PATH, 'python/packages/')
1417

15-
PYTHON_REMOTE_PATH = urljoin(BASE_REMOTE_PATH, 'python/python/')
16-
17-
PYTHON_PUBLICATION_PATH = urljoin(BASE_PUBLICATION_PATH, 'python/pypi/')
18+
PYTHON_DISTRIBUTION_PATH = urljoin(BASE_DISTRIBUTION_PATH, 'python/pypi/')
1819

1920
PYTHON_FIXTURES_URL = urljoin(PULP_FIXTURES_BASE_URL, 'python-pypi/')
2021

21-
PYPI_URL = "https://pypi.org/"
22+
PYTHON_PUBLICATION_PATH = urljoin(BASE_PUBLICATION_PATH, 'python/pypi/')
23+
24+
PYTHON_REMOTE_PATH = urljoin(BASE_REMOTE_PATH, 'python/python/')
2225

2326

2427
# Specifier for testing empty syncs, or no excludes

0 commit comments

Comments
 (0)