Skip to content

Commit 2e61231

Browse files
committed
Clean up imports
1 parent 883109e commit 2e61231

5 files changed

Lines changed: 19 additions & 202 deletions

File tree

pulp_rust/app/serializers.py

Lines changed: 2 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import logging
22

33
from gettext import gettext as _
4-
from django.db.utils import IntegrityError
5-
from pydantic import TypeAdapter, ValidationError
64
from rest_framework import serializers
75

86
from pulpcore.plugin import models as core_models
97
from pulpcore.plugin import serializers as core_serializers
10-
from pulpcore.plugin.util import get_domain
118

129
from . import models
1310

@@ -23,7 +20,8 @@ class IndexRootSerializer(serializers.Serializer):
2320
api = serializers.CharField(help_text=_("URL of the API root"), read_only=True)
2421
auth_required = serializers.BooleanField(
2522
help_text=_(
26-
"Indicates whether this is a private registry that requires all operations to be authenticated"
23+
"Indicates whether this is a private registry that requires all operations to "
24+
"be authenticated"
2725
),
2826
read_only=True,
2927
)
@@ -199,176 +197,6 @@ class Meta:
199197
model = models.RustContent
200198

201199

202-
class RustDependencySerializer(serializers.ModelSerializer):
203-
"""
204-
Serializer for RustDependency.
205-
206-
Represents a single dependency entry from the Cargo package index.
207-
"""
208-
209-
name = serializers.CharField(
210-
help_text=_("Dependency name as used in code (may be renamed via 'package' field)")
211-
)
212-
213-
req = serializers.CharField(
214-
help_text=_("Version requirement string (e.g., '^1.0', '>=0.2.3,<0.3')")
215-
)
216-
217-
features = serializers.ListField(
218-
child=serializers.CharField(),
219-
default=list,
220-
required=False,
221-
help_text=_("List of feature flags to enable for this dependency"),
222-
)
223-
224-
optional = serializers.BooleanField(
225-
default=False, required=False, help_text=_("Whether this is an optional dependency")
226-
)
227-
228-
default_features = serializers.BooleanField(
229-
default=True,
230-
required=False,
231-
help_text=_("Whether to enable the dependency's default features"),
232-
)
233-
234-
target = serializers.CharField(
235-
allow_null=True,
236-
required=False,
237-
help_text=_("Platform-specific target (e.g., 'cfg(unix)', 'cfg(windows)')"),
238-
)
239-
240-
kind = serializers.ChoiceField(
241-
choices=[("normal", "Normal"), ("dev", "Development"), ("build", "Build")],
242-
default="normal",
243-
required=False,
244-
help_text=_(
245-
"Dependency type: 'normal' (runtime), 'dev' (development), or 'build' (build script)"
246-
),
247-
)
248-
249-
registry = serializers.CharField(
250-
allow_null=True,
251-
required=False,
252-
help_text=_("Alternative registry URL if dependency is from a different registry"),
253-
)
254-
255-
package = serializers.CharField(
256-
allow_null=True,
257-
required=False,
258-
help_text=_("Original crate name if the dependency was renamed"),
259-
)
260-
261-
class Meta:
262-
model = models.RustDependency
263-
fields = (
264-
"name",
265-
"req",
266-
"features",
267-
"optional",
268-
"default_features",
269-
"target",
270-
"kind",
271-
"registry",
272-
"package",
273-
)
274-
275-
276-
class RustContentSerializer(core_serializers.SingleArtifactContentSerializer):
277-
"""
278-
Serializer for RustContent (Cargo package version).
279-
280-
Represents a single version of a Rust crate as defined in the Cargo registry
281-
index specification. Includes package metadata, dependencies, and features.
282-
"""
283-
284-
name = serializers.CharField(help_text=_("Package name (crate name)"))
285-
286-
vers = serializers.CharField(help_text=_("Semantic version string (SemVer 2.0.0)"))
287-
288-
dependencies = RustDependencySerializer(
289-
many=True, required=False, help_text=_("List of dependencies for this package version")
290-
)
291-
292-
cksum = serializers.CharField(help_text=_("SHA256 checksum of the .crate file (tarball)"))
293-
294-
features = serializers.JSONField(
295-
default=dict,
296-
required=False,
297-
help_text=_(
298-
"Feature flags mapping - maps feature names to lists of features/dependencies "
299-
"they enable"
300-
),
301-
)
302-
303-
features2 = serializers.JSONField(
304-
default=dict,
305-
required=False,
306-
allow_null=True,
307-
help_text=_("Extended feature syntax support (newer registry format)"),
308-
)
309-
310-
yanked = serializers.BooleanField(
311-
default=False,
312-
required=False,
313-
help_text=_("Whether this version has been yanked (removed from normal use)"),
314-
)
315-
316-
links = serializers.CharField(
317-
allow_null=True,
318-
required=False,
319-
help_text=_("Name of native library this package links to (from Cargo.toml 'links' field)"),
320-
)
321-
322-
v = serializers.IntegerField(
323-
default=1, required=False, help_text=_("Schema version of the index entry format")
324-
)
325-
rust_version = serializers.CharField(
326-
allow_null=True,
327-
required=False,
328-
help_text=_("Minimum Rust compiler version required (MSRV)"),
329-
)
330-
331-
def create(self, validated_data):
332-
"""Create RustContent and related dependencies."""
333-
dependencies_data = validated_data.pop("dependencies", [])
334-
content = super().create(validated_data)
335-
336-
# Create dependency records
337-
for dep_data in dependencies_data:
338-
models.RustDependency.objects.create(content=content, **dep_data)
339-
340-
return content
341-
342-
def update(self, instance, validated_data):
343-
"""Update RustContent and related dependencies."""
344-
dependencies_data = validated_data.pop("dependencies", None)
345-
346-
instance = super().update(instance, validated_data)
347-
348-
if dependencies_data is not None:
349-
# Replace all dependencies
350-
instance.dependencies.all().delete()
351-
for dep_data in dependencies_data:
352-
models.RustDependency.objects.create(content=instance, **dep_data)
353-
354-
return instance
355-
356-
class Meta:
357-
fields = core_serializers.SingleArtifactContentSerializer.Meta.fields + (
358-
"name",
359-
"vers",
360-
"dependencies",
361-
"cksum",
362-
"features",
363-
"features2",
364-
"yanked",
365-
"links",
366-
"v",
367-
"rust_version",
368-
)
369-
model = models.RustContent
370-
371-
372200
class RustRemoteSerializer(core_serializers.RemoteSerializer):
373201
"""
374202
A Serializer for RustRemote.

pulp_rust/app/tasks/synchronizing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def run(self):
7373
downloader = self.remote.get_downloader(url=self.remote.url)
7474
result = await downloader.run()
7575
# Use ProgressReport to report progress
76-
raise NotImplemented("Not implemented")
76+
raise NotImplementedError("Not implemented")
7777

7878
for entry in self.read_my_metadata_file_somehow(result.path):
7979
unit = RustContent(entry) # make the content unit in memory-only

pulp_rust/app/urls.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from django.conf import settings
2-
from django.urls import path, re_path
2+
from django.urls import path
33

44
from pulp_rust.app.views import IndexRoot, CargoIndexApiViewSet, CargoDownloadApiView
55

66
if settings.DOMAIN_ENABLED:
7-
path_re = r"(?P<pulp_domain>[-a-zA-Z0-9_]+)/(?P<name>[\w-]+)/(?P<path>.*)"
87
CRATES_IO_URL = "pulp/cargo/<slug:pulp_domain>/<slug:repo>/"
98
else:
10-
path_re = r"(?P<name>[\w-]+)/(?P<path>.*)"
119
CRATES_IO_URL = "pulp/cargo/<slug:repo>/"
1210

1311

@@ -23,5 +21,4 @@
2321
CargoIndexApiViewSet.as_view({"get": "retrieve"}),
2422
name="cargo-index-api",
2523
),
26-
# re_path(rf"^pulp/cargo/{path_re}$", CargoApiViewSet.as_view({"get": "retrieve"})),
2724
]

pulp_rust/app/views.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,28 @@
33

44
from rest_framework.views import APIView
55
from rest_framework.viewsets import ViewSet
6-
from rest_framework.renderers import BrowsableAPIRenderer, JSONRenderer, TemplateHTMLRenderer
76
from rest_framework.response import Response
8-
from rest_framework.decorators import api_view
9-
from rest_framework.exceptions import NotAcceptable, Throttled
7+
from rest_framework.exceptions import Throttled
108
from django.core.exceptions import ObjectDoesNotExist
11-
from django.shortcuts import redirect
12-
from datetime import datetime, timezone, timedelta
9+
from django.shortcuts import redirect, get_object_or_404
1310

14-
from django.contrib.sessions.models import Session
15-
from django.db import transaction
16-
from django.db.utils import DatabaseError
1711
from django.http.response import (
1812
Http404,
1913
HttpResponseNotFound,
20-
HttpResponseForbidden,
21-
HttpResponseBadRequest,
22-
StreamingHttpResponse,
2314
HttpResponse,
2415
)
2516
from drf_spectacular.utils import extend_schema
2617
from dynaconf import settings
27-
from itertools import chain
28-
from packaging.utils import canonicalize_name
29-
from urllib.parse import urljoin, urlparse, urlunsplit
3018
from pathlib import PurePath
19+
from urllib.parse import urljoin
3120

32-
from pulpcore.plugin.viewsets import OperationPostponedResponse
33-
from pulpcore.plugin.tasking import dispatch
34-
from pulpcore.plugin.util import get_domain, get_url
21+
from pulpcore.plugin.util import get_domain
3522

3623
from pulp_rust.app.models import RustDistribution, RustRepository, RustContent
3724
from pulp_rust.app.serializers import (
3825
IndexRootSerializer,
3926
RustContentSerializer,
4027
)
41-
from pulp_rust.app import tasks
4228

4329
log = logging.getLogger(__name__)
4430

@@ -68,7 +54,7 @@ def get_distribution(repo):
6854
try:
6955
return distro_qs.get(base_path=repo, pulp_domain=get_domain())
7056
except ObjectDoesNotExist:
71-
raise Http404(f"No RustDistribution found for base_path {path}")
57+
raise Http404(f"No RustDistribution found for base_path {repo}") # TODO: broken
7258

7359
@staticmethod
7460
def get_repository_version(distribution):
@@ -248,13 +234,19 @@ class CargoDownloadApiView(APIView):
248234
authentication_classes = []
249235
permission_classes = []
250236

237+
def get_full_path(self, base_path, pulp_domain=None): # TODO: replace with ApiMixin?
238+
if settings.DOMAIN_ENABLED:
239+
domain = pulp_domain or get_domain()
240+
return f"{domain.name}/{base_path}"
241+
return base_path
242+
251243
def redirect_to_content_app(self, distribution, relative_path, request):
252244
scheme = request.META.get("HTTP_X_FORWARDED_PROTO", request.scheme)
253245
hostname = request.META.get("HTTP_X_FORWARDED_HOST", request.get_host())
254246
content_origin = f"{scheme}://{hostname}"
255247
return redirect(
256248
f"{content_origin}{settings.CONTENT_PATH_PREFIX}"
257-
f"{get_full_path(distribution.base_path)}/{relative_path}"
249+
f"{self.get_full_path(distribution.base_path)}/{relative_path}"
258250
)
259251

260252
def get_repository_and_distributions(self, name):
@@ -270,7 +262,7 @@ def get(self, request, name, version):
270262
"""
271263
repo, distro = self.get_repository_and_distributions(name)
272264
content = get_object_or_404(
273-
RustPackage, name=name, vers=version, pk__in=repo.latest_version().content
265+
RustContent, name=name, vers=version, pk__in=repo.latest_version().content
274266
)
275267
relative_path = content.contentartifact_set.get().relative_path
276268
return self.redirect_to_content_app(distro, relative_path, request)

pulp_rust/app/viewsets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ def add_cached_content(self, request, pk):
193193
remote = serializer.validated_data.get("remote", repository.remote)
194194

195195
result = dispatch(
196-
add_cached_content_to_repository,
196+
tasks.add_cached_content_to_repository,
197197
shared_resources=[remote],
198198
exclusive_resources=[repository],
199199
kwargs={
200200
"remote_pk": str(remote.pk),
201201
"repository_pk": str(repository.pk),
202202
},
203203
)
204-
return OperationPostponedResponse(result, request)
204+
return core.OperationPostponedResponse(result, request)
205205

206206

207207
class RustRepositoryVersionViewSet(core.RepositoryVersionViewSet):

0 commit comments

Comments
 (0)