Skip to content

Commit d4a0b76

Browse files
committed
Use new helper from pulpcore for currently-served object lookup
And adapt to the possibility that the user may want to distribute a particular repository version, perhaps without having created a publication.
1 parent 5831a88 commit d4a0b76

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pulpcore enabled a feature to allow users to specify "repository_version" on their distributions, which pulp_python already allowed. However, some additional plugin changes were required in order to deconflict the two implementations.

pulp_python/app/models.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ def content_handler(self, path):
7979
name = None
8080
version = None
8181
domain = get_domain()
82+
83+
# Resolve the repo version and publication for this distribution.
84+
# The behavior of pulp_python differs from pulpcore here in that it always looks
85+
# for a publication even though distribution.SERVE_FROM_PUBLICATION = False
86+
publication = self.publication
87+
repo_version = self.repository_version
88+
if publication:
89+
repo_version = publication.repository_version
90+
elif self.repository:
91+
repo_version = self.repository.latest_version()
92+
if not publication and repo_version:
93+
try:
94+
publication = Publication.objects.filter(
95+
repository_version=repo_version, complete=True
96+
).latest("pulp_created")
97+
except ObjectDoesNotExist:
98+
pass
99+
82100
if path.match("pypi/*/*/json"):
83101
version = path.parts[2]
84102
name = path.parts[1]
@@ -88,13 +106,7 @@ def content_handler(self, path):
88106
# Temporary fix for PublishedMetadata not being properly served from remote storage
89107
# https://github.com/pulp/pulp_python/issues/413
90108
if domain.storage_class != "pulpcore.app.models.storage.FileSystem":
91-
if self.publication or self.repository:
92-
try:
93-
publication = self.publication or Publication.objects.filter(
94-
repository_version=self.repository.latest_version()
95-
).latest("pulp_created")
96-
except ObjectDoesNotExist:
97-
return None
109+
if publication:
98110
if len(path.parts) == 2:
99111
path = PurePath(f"simple/{canonicalize_name(path.parts[1])}")
100112
rel_path = f"{path}/index.html"
@@ -112,10 +124,10 @@ def content_handler(self, path):
112124
headers = {"Content-Type": "text/html"}
113125
return ArtifactResponse(ca.artifact, headers=headers)
114126

115-
if name:
127+
if name and repo_version:
116128
normalized = canonicalize_name(name)
117129
package_content = PythonPackageContent.objects.filter(
118-
pk__in=self.publication.repository_version.content, name__normalize=normalized
130+
pk__in=repo_version.content, name__normalize=normalized
119131
)
120132
# TODO Change this value to the Repo's serial value when implemented
121133
headers = {PYPI_LAST_SERIAL: str(PYPI_SERIAL_CONSTANT)}

pulp_python/app/serializers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ class PythonDistributionSerializer(core_serializers.DistributionSerializer):
7474
queryset=core_models.Publication.objects.exclude(complete=False),
7575
allow_null=True,
7676
)
77-
repository_version = core_serializers.RepositoryVersionRelatedField(
78-
required=False, help_text=_("RepositoryVersion to be served."), allow_null=True
79-
)
8077
base_url = serializers.SerializerMethodField(read_only=True)
8178
allow_uploads = serializers.BooleanField(
8279
default=True, help_text=_("Allow packages to be uploaded to this index.")
@@ -98,7 +95,6 @@ def get_base_url(self, obj):
9895
class Meta:
9996
fields = core_serializers.DistributionSerializer.Meta.fields + (
10097
"publication",
101-
"repository_version",
10298
"allow_uploads",
10399
"remote",
104100
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers=[
2626
]
2727
requires-python = ">=3.11"
2828
dependencies = [
29-
"pulpcore>=3.85.3,<3.115",
29+
"pulpcore>=3.106.0,<3.115",
3030
"pkginfo>=1.12.0,<1.13.0",
3131
"bandersnatch>=6.6.0,<6.7",
3232
"pypi-simple>=1.8.0,<2.0",

0 commit comments

Comments
 (0)