pulp-python 3.13.6__py3-none-any.whl → 3.13.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pulp_python/__init__.py +1 -1
- pulp_python/app/__init__.py +5 -3
- pulp_python/app/global_access_conditions.py +0 -1
- pulp_python/app/management/commands/repair-python-metadata.py +5 -4
- pulp_python/app/modelresource.py +1 -0
- pulp_python/app/models.py +8 -7
- pulp_python/app/pypi/serializers.py +11 -9
- pulp_python/app/pypi/views.py +69 -54
- pulp_python/app/replica.py +3 -2
- pulp_python/app/serializers.py +187 -110
- pulp_python/app/settings.py +1 -1
- pulp_python/app/tasks/publish.py +24 -25
- pulp_python/app/tasks/sync.py +15 -29
- pulp_python/app/tasks/upload.py +7 -8
- pulp_python/app/urls.py +5 -5
- pulp_python/app/utils.py +54 -47
- pulp_python/app/viewsets.py +43 -46
- pulp_python/pytest_plugin.py +14 -5
- pulp_python/tests/functional/api/test_consume_content.py +0 -1
- pulp_python/tests/functional/api/test_crud_content_unit.py +8 -5
- pulp_python/tests/functional/api/test_crud_publications.py +9 -6
- pulp_python/tests/functional/api/test_crud_remotes.py +3 -2
- pulp_python/tests/functional/api/test_domains.py +9 -7
- pulp_python/tests/functional/api/test_download_content.py +2 -2
- pulp_python/tests/functional/api/test_export_import.py +7 -4
- pulp_python/tests/functional/api/test_full_mirror.py +4 -4
- pulp_python/tests/functional/api/test_pypi_apis.py +13 -18
- pulp_python/tests/functional/api/test_rbac.py +6 -5
- pulp_python/tests/functional/api/test_repair.py +3 -2
- pulp_python/tests/functional/api/test_sync.py +28 -19
- pulp_python/tests/functional/constants.py +15 -33
- pulp_python/tests/functional/utils.py +15 -6
- {pulp_python-3.13.6.dist-info → pulp_python-3.13.8.dist-info}/METADATA +1 -1
- {pulp_python-3.13.6.dist-info → pulp_python-3.13.8.dist-info}/RECORD +38 -38
- {pulp_python-3.13.6.dist-info → pulp_python-3.13.8.dist-info}/WHEEL +0 -0
- {pulp_python-3.13.6.dist-info → pulp_python-3.13.8.dist-info}/entry_points.txt +0 -0
- {pulp_python-3.13.6.dist-info → pulp_python-3.13.8.dist-info}/licenses/LICENSE +0 -0
- {pulp_python-3.13.6.dist-info → pulp_python-3.13.8.dist-info}/top_level.txt +0 -0
pulp_python/app/tasks/sync.py
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
|
|
3
|
-
from aiohttp import ClientResponseError, ClientError
|
|
4
|
-
from lxml.etree import LxmlError
|
|
5
|
-
from gettext import gettext as _
|
|
6
2
|
from functools import partial
|
|
3
|
+
from gettext import gettext as _
|
|
4
|
+
from urllib.parse import urljoin
|
|
7
5
|
|
|
6
|
+
from aiohttp import ClientError, ClientResponseError
|
|
7
|
+
from bandersnatch.configuration import BandersnatchConfig
|
|
8
|
+
from bandersnatch.master import Master
|
|
9
|
+
from bandersnatch.mirror import Mirror
|
|
10
|
+
from lxml.etree import LxmlError
|
|
11
|
+
from packaging.requirements import Requirement
|
|
12
|
+
from pypi_simple import IndexPage
|
|
8
13
|
from rest_framework import serializers
|
|
9
14
|
|
|
10
15
|
from pulpcore.plugin.download import HttpDownloader
|
|
@@ -20,14 +25,7 @@ from pulp_python.app.models import (
|
|
|
20
25
|
PythonPackageContent,
|
|
21
26
|
PythonRemote,
|
|
22
27
|
)
|
|
23
|
-
from pulp_python.app.utils import
|
|
24
|
-
from pypi_simple import IndexPage
|
|
25
|
-
|
|
26
|
-
from bandersnatch.mirror import Mirror
|
|
27
|
-
from bandersnatch.master import Master
|
|
28
|
-
from bandersnatch.configuration import BandersnatchConfig
|
|
29
|
-
from packaging.requirements import Requirement
|
|
30
|
-
from urllib.parse import urljoin
|
|
28
|
+
from pulp_python.app.utils import PYPI_LAST_SERIAL, parse_metadata
|
|
31
29
|
|
|
32
30
|
logger = logging.getLogger(__name__)
|
|
33
31
|
|
|
@@ -51,9 +49,7 @@ def sync(remote_pk, repository_pk, mirror):
|
|
|
51
49
|
repository = Repository.objects.get(pk=repository_pk)
|
|
52
50
|
|
|
53
51
|
if not remote.url:
|
|
54
|
-
raise serializers.ValidationError(
|
|
55
|
-
detail=_("A remote must have a url attribute to sync.")
|
|
56
|
-
)
|
|
52
|
+
raise serializers.ValidationError(detail=_("A remote must have a url attribute to sync."))
|
|
57
53
|
|
|
58
54
|
first_stage = PythonBanderStage(remote)
|
|
59
55
|
DeclarativeVersion(first_stage, repository, mirror).create()
|
|
@@ -146,9 +142,7 @@ class PythonBanderStage(Stage):
|
|
|
146
142
|
)
|
|
147
143
|
packages_to_sync = None
|
|
148
144
|
if self.remote.includes:
|
|
149
|
-
packages_to_sync = [
|
|
150
|
-
Requirement(pkg).name for pkg in self.remote.includes
|
|
151
|
-
]
|
|
145
|
+
packages_to_sync = [Requirement(pkg).name for pkg in self.remote.includes]
|
|
152
146
|
await pmirror.synchronize(packages_to_sync)
|
|
153
147
|
# place back old session so that it is properly closed
|
|
154
148
|
master.session = old_session
|
|
@@ -159,9 +153,7 @@ class PulpMirror(Mirror):
|
|
|
159
153
|
Pulp Mirror Class to perform syncing using Bandersnatch
|
|
160
154
|
"""
|
|
161
155
|
|
|
162
|
-
def __init__(
|
|
163
|
-
self, serial, master, workers, deferred_download, python_stage, progress_report
|
|
164
|
-
):
|
|
156
|
+
def __init__(self, serial, master, workers, deferred_download, python_stage, progress_report):
|
|
165
157
|
"""Initialize Bandersnatch Mirror"""
|
|
166
158
|
super().__init__(master=master, workers=workers)
|
|
167
159
|
self.synced_serial = serial
|
|
@@ -176,11 +168,7 @@ class PulpMirror(Mirror):
|
|
|
176
168
|
"""
|
|
177
169
|
number_xmlrpc_attempts = 3
|
|
178
170
|
for attempt in range(number_xmlrpc_attempts):
|
|
179
|
-
logger.info(
|
|
180
|
-
"Attempt {} to get package list from {}".format(
|
|
181
|
-
attempt, self.master.url
|
|
182
|
-
)
|
|
183
|
-
)
|
|
171
|
+
logger.info("Attempt {} to get package list from {}".format(attempt, self.master.url))
|
|
184
172
|
try:
|
|
185
173
|
if not self.synced_serial:
|
|
186
174
|
logger.info("Syncing all packages.")
|
|
@@ -192,9 +180,7 @@ class PulpMirror(Mirror):
|
|
|
192
180
|
)
|
|
193
181
|
else:
|
|
194
182
|
logger.info("Syncing based on changelog.")
|
|
195
|
-
changed_packages = await self.master.changed_packages(
|
|
196
|
-
self.synced_serial
|
|
197
|
-
)
|
|
183
|
+
changed_packages = await self.master.changed_packages(self.synced_serial)
|
|
198
184
|
self.packages_to_sync.update(changed_packages)
|
|
199
185
|
self.target_serial = max(
|
|
200
186
|
[self.synced_serial] + [int(v) for v in self.packages_to_sync.values()]
|
pulp_python/app/tasks/upload.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import time
|
|
2
|
-
|
|
3
2
|
from datetime import datetime, timezone
|
|
4
|
-
|
|
3
|
+
|
|
5
4
|
from django.contrib.sessions.models import Session
|
|
6
|
-
from
|
|
5
|
+
from django.db import transaction
|
|
6
|
+
|
|
7
|
+
from pulpcore.plugin.models import Artifact, ContentArtifact, CreatedResource
|
|
7
8
|
from pulpcore.plugin.util import get_domain
|
|
8
9
|
|
|
9
10
|
from pulp_python.app.models import PythonPackageContent, PythonRepository
|
|
@@ -43,10 +44,10 @@ def upload_group(session_pk, repository_pk=None):
|
|
|
43
44
|
with transaction.atomic():
|
|
44
45
|
session_data = s_query.first().get_decoded()
|
|
45
46
|
now = datetime.now(tz=timezone.utc)
|
|
46
|
-
start_time = datetime.fromisoformat(session_data[
|
|
47
|
+
start_time = datetime.fromisoformat(session_data["start"])
|
|
47
48
|
if now >= start_time:
|
|
48
49
|
content_to_add = PythonPackageContent.objects.none()
|
|
49
|
-
for artifact_sha256, filename in session_data[
|
|
50
|
+
for artifact_sha256, filename in session_data["artifacts"]:
|
|
50
51
|
pre_check = PythonPackageContent.objects.filter(
|
|
51
52
|
sha256=artifact_sha256, _pulp_domain=domain
|
|
52
53
|
)
|
|
@@ -81,9 +82,7 @@ def create_content(artifact_sha256, filename, domain):
|
|
|
81
82
|
@transaction.atomic()
|
|
82
83
|
def create():
|
|
83
84
|
content = PythonPackageContent.objects.create(**data)
|
|
84
|
-
ContentArtifact.objects.create(
|
|
85
|
-
artifact=artifact, content=content, relative_path=filename
|
|
86
|
-
)
|
|
85
|
+
ContentArtifact.objects.create(artifact=artifact, content=content, relative_path=filename)
|
|
87
86
|
return content
|
|
88
87
|
|
|
89
88
|
new_content = create()
|
pulp_python/app/urls.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from django.conf import settings
|
|
2
2
|
from django.urls import path
|
|
3
3
|
|
|
4
|
-
from pulp_python.app.pypi.views import
|
|
4
|
+
from pulp_python.app.pypi.views import MetadataView, PyPIView, SimpleView, UploadView
|
|
5
5
|
|
|
6
6
|
if settings.DOMAIN_ENABLED:
|
|
7
7
|
PYPI_API_URL = "pypi/<slug:pulp_domain>/<path:path>/"
|
|
@@ -16,17 +16,17 @@ urlpatterns = [
|
|
|
16
16
|
path(
|
|
17
17
|
PYPI_API_URL + "pypi/<path:meta>/",
|
|
18
18
|
MetadataView.as_view({"get": "retrieve"}),
|
|
19
|
-
name="pypi-metadata"
|
|
19
|
+
name="pypi-metadata",
|
|
20
20
|
),
|
|
21
21
|
path(
|
|
22
22
|
PYPI_API_URL + "simple/<str:package>/",
|
|
23
23
|
SimpleView.as_view({"get": "retrieve"}),
|
|
24
|
-
name="simple-package-detail"
|
|
24
|
+
name="simple-package-detail",
|
|
25
25
|
),
|
|
26
26
|
path(
|
|
27
|
-
PYPI_API_URL +
|
|
27
|
+
PYPI_API_URL + "simple/",
|
|
28
28
|
SimpleView.as_view({"get": "list", "post": "create"}),
|
|
29
|
-
name="simple-detail"
|
|
29
|
+
name="simple-detail",
|
|
30
30
|
),
|
|
31
31
|
path(PYPI_API_URL, PyPIView.as_view({"get": "retrieve"}), name="pypi-detail"),
|
|
32
32
|
]
|
pulp_python/app/utils.py
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
2
3
|
import re
|
|
3
4
|
import shutil
|
|
4
5
|
import tempfile
|
|
5
|
-
import json
|
|
6
6
|
from collections import defaultdict
|
|
7
|
+
|
|
8
|
+
import pkginfo
|
|
7
9
|
from django.conf import settings
|
|
8
10
|
from jinja2 import Template
|
|
9
11
|
from packaging.utils import canonicalize_name
|
|
10
12
|
from packaging.version import parse
|
|
11
13
|
|
|
12
|
-
|
|
13
14
|
PYPI_LAST_SERIAL = "X-PYPI-LAST-SERIAL"
|
|
14
15
|
"""TODO This serial constant is temporary until Python repositories implements serials"""
|
|
15
16
|
PYPI_SERIAL_CONSTANT = 1000000000
|
|
@@ -58,10 +59,12 @@ DIST_REGEXES = {
|
|
|
58
59
|
r"""^(?P<name>.+?)-(?P<version>.*?)
|
|
59
60
|
((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
|
|
60
61
|
\.whl|\.dist-info)$""",
|
|
61
|
-
re.VERBOSE
|
|
62
|
+
re.VERBOSE,
|
|
62
63
|
),
|
|
63
64
|
# regex based on https://setuptools.pypa.io/en/latest/deprecated/python_eggs.html#filename-embedded-metadata # noqa: E501
|
|
64
|
-
".egg": re.compile(
|
|
65
|
+
".egg": re.compile(
|
|
66
|
+
r"^(?P<name>.+?)-(?P<version>.*?)(-(?P<pyver>.+?(-(?P<plat>.+?))?))?\.egg|\.egg-info$"
|
|
67
|
+
), # noqa: E501
|
|
65
68
|
# regex based on https://github.com/python/cpython/blob/v3.7.0/Lib/distutils/command/bdist_wininst.py#L292 # noqa: E501
|
|
66
69
|
".exe": re.compile(r"^(?P<name>.+?)-(?P<version>.*?)\.(?P<plat>.+?)(-(?P<pyver>.+?))?\.exe$"),
|
|
67
70
|
}
|
|
@@ -86,32 +89,32 @@ def parse_project_metadata(project):
|
|
|
86
89
|
|
|
87
90
|
"""
|
|
88
91
|
package = {}
|
|
89
|
-
package[
|
|
90
|
-
package[
|
|
91
|
-
package[
|
|
92
|
-
package[
|
|
93
|
-
package[
|
|
94
|
-
package[
|
|
95
|
-
package[
|
|
96
|
-
package[
|
|
97
|
-
package[
|
|
98
|
-
package[
|
|
99
|
-
package[
|
|
100
|
-
package[
|
|
101
|
-
package[
|
|
102
|
-
package[
|
|
103
|
-
package[
|
|
104
|
-
package[
|
|
105
|
-
package[
|
|
106
|
-
package[
|
|
107
|
-
package[
|
|
108
|
-
package[
|
|
109
|
-
package[
|
|
110
|
-
package[
|
|
111
|
-
package[
|
|
112
|
-
package[
|
|
113
|
-
package[
|
|
114
|
-
package[
|
|
92
|
+
package["name"] = project.get("name") or ""
|
|
93
|
+
package["version"] = project.get("version") or ""
|
|
94
|
+
package["packagetype"] = project.get("packagetype") or ""
|
|
95
|
+
package["metadata_version"] = project.get("metadata_version") or ""
|
|
96
|
+
package["summary"] = project.get("summary") or ""
|
|
97
|
+
package["description"] = project.get("description") or ""
|
|
98
|
+
package["keywords"] = project.get("keywords") or ""
|
|
99
|
+
package["home_page"] = project.get("home_page") or ""
|
|
100
|
+
package["download_url"] = project.get("download_url") or ""
|
|
101
|
+
package["author"] = project.get("author") or ""
|
|
102
|
+
package["author_email"] = project.get("author_email") or ""
|
|
103
|
+
package["maintainer"] = project.get("maintainer") or ""
|
|
104
|
+
package["maintainer_email"] = project.get("maintainer_email") or ""
|
|
105
|
+
package["license"] = project.get("license") or ""
|
|
106
|
+
package["project_url"] = project.get("project_url") or ""
|
|
107
|
+
package["platform"] = project.get("platform") or ""
|
|
108
|
+
package["supported_platform"] = project.get("supported_platform") or ""
|
|
109
|
+
package["requires_python"] = project.get("requires_python") or ""
|
|
110
|
+
package["requires_dist"] = json.dumps(project.get("requires_dist", []))
|
|
111
|
+
package["provides_dist"] = json.dumps(project.get("provides_dist", []))
|
|
112
|
+
package["obsoletes_dist"] = json.dumps(project.get("obsoletes_dist", []))
|
|
113
|
+
package["requires_external"] = json.dumps(project.get("requires_external", []))
|
|
114
|
+
package["classifiers"] = json.dumps(project.get("classifiers", []))
|
|
115
|
+
package["project_urls"] = json.dumps(project.get("project_urls", {}))
|
|
116
|
+
package["description_content_type"] = project.get("description_content_type") or ""
|
|
117
|
+
package["python_version"] = project.get("python_version") or ""
|
|
115
118
|
|
|
116
119
|
return package
|
|
117
120
|
|
|
@@ -134,13 +137,15 @@ def parse_metadata(project, version, distribution):
|
|
|
134
137
|
"""
|
|
135
138
|
package = parse_project_metadata(project)
|
|
136
139
|
|
|
137
|
-
package[
|
|
138
|
-
package[
|
|
139
|
-
package[
|
|
140
|
-
package[
|
|
141
|
-
package[
|
|
142
|
-
package[
|
|
143
|
-
package[
|
|
140
|
+
package["filename"] = distribution.get("filename") or ""
|
|
141
|
+
package["packagetype"] = distribution.get("packagetype") or ""
|
|
142
|
+
package["version"] = version
|
|
143
|
+
package["url"] = distribution.get("url") or ""
|
|
144
|
+
package["sha256"] = distribution.get("digests", {}).get("sha256") or ""
|
|
145
|
+
package["python_version"] = distribution.get("python_version") or package.get("python_version")
|
|
146
|
+
package["requires_python"] = distribution.get("requires_python") or package.get(
|
|
147
|
+
"requires_python"
|
|
148
|
+
) # noqa: E501
|
|
144
149
|
|
|
145
150
|
return package
|
|
146
151
|
|
|
@@ -159,7 +164,7 @@ def get_project_metadata_from_artifact(filename, artifact):
|
|
|
159
164
|
# Copy file to a temp directory under the user provided filename, we do this
|
|
160
165
|
# because pkginfo validates that the filename has a valid extension before
|
|
161
166
|
# reading it
|
|
162
|
-
with tempfile.NamedTemporaryFile(
|
|
167
|
+
with tempfile.NamedTemporaryFile("wb", dir=".", suffix=filename) as temp_file:
|
|
163
168
|
shutil.copyfileobj(artifact.file, temp_file)
|
|
164
169
|
temp_file.flush()
|
|
165
170
|
metadata = DIST_TYPES[packagetype](temp_file.name)
|
|
@@ -169,7 +174,7 @@ def get_project_metadata_from_artifact(filename, artifact):
|
|
|
169
174
|
else:
|
|
170
175
|
pyver = ""
|
|
171
176
|
regex = DIST_REGEXES[extensions[pkg_type_index]]
|
|
172
|
-
if bdist_name := regex.match(filename):
|
|
177
|
+
if bdist_name := regex.match(os.path.basename(filename)):
|
|
173
178
|
pyver = bdist_name.group("pyver") or ""
|
|
174
179
|
metadata.python_version = pyver
|
|
175
180
|
return metadata
|
|
@@ -181,10 +186,10 @@ def artifact_to_python_content_data(filename, artifact, domain=None):
|
|
|
181
186
|
"""
|
|
182
187
|
metadata = get_project_metadata_from_artifact(filename, artifact)
|
|
183
188
|
data = parse_project_metadata(vars(metadata))
|
|
184
|
-
data[
|
|
185
|
-
data[
|
|
186
|
-
data[
|
|
187
|
-
data[
|
|
189
|
+
data["sha256"] = artifact.sha256
|
|
190
|
+
data["filename"] = filename
|
|
191
|
+
data["pulp_domain"] = domain or artifact.pulp_domain
|
|
192
|
+
data["_pulp_domain"] = data["pulp_domain"]
|
|
188
193
|
return data
|
|
189
194
|
|
|
190
195
|
|
|
@@ -306,10 +311,12 @@ def python_content_to_download_info(content, base_path, domain=None):
|
|
|
306
311
|
Takes in a PythonPackageContent and base path of the distribution to create a dictionary of
|
|
307
312
|
download information for that content. This dictionary is used by Releases and Urls.
|
|
308
313
|
"""
|
|
314
|
+
|
|
309
315
|
def find_artifact():
|
|
310
316
|
_art = content_artifact.artifact
|
|
311
317
|
if not _art:
|
|
312
318
|
from pulpcore.plugin import models
|
|
319
|
+
|
|
313
320
|
_art = models.RemoteArtifact.objects.filter(content_artifact=content_artifact).first()
|
|
314
321
|
return _art
|
|
315
322
|
|
|
@@ -340,19 +347,19 @@ def python_content_to_download_info(content, base_path, domain=None):
|
|
|
340
347
|
"upload_time_iso_8601": str(content.pulp_created.isoformat()),
|
|
341
348
|
"url": url,
|
|
342
349
|
"yanked": False,
|
|
343
|
-
"yanked_reason": None
|
|
350
|
+
"yanked_reason": None,
|
|
344
351
|
}
|
|
345
352
|
|
|
346
353
|
|
|
347
354
|
def write_simple_index(project_names, streamed=False):
|
|
348
355
|
"""Writes the simple index."""
|
|
349
|
-
simple = Template(simple_index_template)
|
|
356
|
+
simple = Template(simple_index_template, autoescape=True)
|
|
350
357
|
context = {"projects": ((x, canonicalize_name(x)) for x in project_names)}
|
|
351
358
|
return simple.stream(**context) if streamed else simple.render(**context)
|
|
352
359
|
|
|
353
360
|
|
|
354
361
|
def write_simple_detail(project_name, project_packages, streamed=False):
|
|
355
362
|
"""Writes the simple detail page of a package."""
|
|
356
|
-
detail = Template(simple_detail_template)
|
|
363
|
+
detail = Template(simple_detail_template, autoescape=True)
|
|
357
364
|
context = {"project_name": project_name, "project_packages": project_packages}
|
|
358
365
|
return detail.stream(**context) if streamed else detail.render(**context)
|
pulp_python/app/viewsets.py
CHANGED
|
@@ -26,7 +26,7 @@ class PythonRepositoryViewSet(
|
|
|
26
26
|
synced, added, or removed.
|
|
27
27
|
"""
|
|
28
28
|
|
|
29
|
-
endpoint_name =
|
|
29
|
+
endpoint_name = "python"
|
|
30
30
|
queryset = python_models.PythonRepository.objects.all()
|
|
31
31
|
serializer_class = python_serializers.PythonRepositorySerializer
|
|
32
32
|
queryset_filtering_required_permission = "python.view_pythonrepository"
|
|
@@ -122,11 +122,8 @@ class PythonRepositoryViewSet(
|
|
|
122
122
|
"python.pythonrepository_viewer": ["python.view_pythonrepository"],
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
@extend_schema(
|
|
126
|
-
|
|
127
|
-
responses={202: AsyncOperationResponseSerializer}
|
|
128
|
-
)
|
|
129
|
-
@action(detail=True, methods=['post'], serializer_class=RepositorySyncURLSerializer)
|
|
125
|
+
@extend_schema(summary="Sync from remote", responses={202: AsyncOperationResponseSerializer})
|
|
126
|
+
@action(detail=True, methods=["post"], serializer_class=RepositorySyncURLSerializer)
|
|
130
127
|
def sync(self, request, pk):
|
|
131
128
|
"""
|
|
132
129
|
<!-- User-facing documentation, rendered as html-->
|
|
@@ -136,22 +133,21 @@ class PythonRepositoryViewSet(
|
|
|
136
133
|
"""
|
|
137
134
|
repository = self.get_object()
|
|
138
135
|
serializer = RepositorySyncURLSerializer(
|
|
139
|
-
data=request.data,
|
|
140
|
-
context={'request': request, "repository_pk": pk}
|
|
136
|
+
data=request.data, context={"request": request, "repository_pk": pk}
|
|
141
137
|
)
|
|
142
138
|
serializer.is_valid(raise_exception=True)
|
|
143
|
-
remote = serializer.validated_data.get(
|
|
144
|
-
mirror = serializer.validated_data.get(
|
|
139
|
+
remote = serializer.validated_data.get("remote", repository.remote)
|
|
140
|
+
mirror = serializer.validated_data.get("mirror")
|
|
145
141
|
|
|
146
142
|
result = dispatch(
|
|
147
143
|
tasks.sync,
|
|
148
144
|
exclusive_resources=[repository],
|
|
149
145
|
shared_resources=[remote],
|
|
150
146
|
kwargs={
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
147
|
+
"remote_pk": str(remote.pk),
|
|
148
|
+
"repository_pk": str(repository.pk),
|
|
149
|
+
"mirror": mirror,
|
|
150
|
+
},
|
|
155
151
|
)
|
|
156
152
|
return core_viewsets.OperationPostponedResponse(result, request)
|
|
157
153
|
|
|
@@ -169,8 +165,7 @@ class PythonRepositoryVersionViewSet(core_viewsets.RepositoryVersionViewSet):
|
|
|
169
165
|
"action": ["list", "retrieve"],
|
|
170
166
|
"principal": "authenticated",
|
|
171
167
|
"effect": "allow",
|
|
172
|
-
"condition":
|
|
173
|
-
"has_repository_model_or_domain_or_obj_perms:python.view_pythonrepository",
|
|
168
|
+
"condition": "has_repository_model_or_domain_or_obj_perms:python.view_pythonrepository",
|
|
174
169
|
},
|
|
175
170
|
{
|
|
176
171
|
"action": ["destroy"],
|
|
@@ -205,7 +200,7 @@ class PythonDistributionViewSet(core_viewsets.DistributionViewSet, core_viewsets
|
|
|
205
200
|
href="./#tag/Content:-Packages">Python Package Content.</a>
|
|
206
201
|
"""
|
|
207
202
|
|
|
208
|
-
endpoint_name =
|
|
203
|
+
endpoint_name = "pypi"
|
|
209
204
|
queryset = python_models.PythonDistribution.objects.all()
|
|
210
205
|
serializer_class = python_serializers.PythonDistributionSerializer
|
|
211
206
|
queryset_filtering_required_permission = "python.view_pythondistribution"
|
|
@@ -294,19 +289,20 @@ class PythonPackageContentFilter(core_viewsets.ContentFilter):
|
|
|
294
289
|
class Meta:
|
|
295
290
|
model = python_models.PythonPackageContent
|
|
296
291
|
fields = {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
292
|
+
"name": ["exact", "in"],
|
|
293
|
+
"author": ["exact", "in"],
|
|
294
|
+
"packagetype": ["exact", "in"],
|
|
295
|
+
"requires_python": ["exact", "in", "contains"],
|
|
296
|
+
"filename": ["exact", "in", "contains"],
|
|
297
|
+
"keywords": ["in", "contains"],
|
|
298
|
+
"sha256": ["exact", "in"],
|
|
299
|
+
"version": ["exact", "gt", "lt", "gte", "lte"],
|
|
305
300
|
}
|
|
306
301
|
|
|
307
302
|
|
|
308
303
|
class PythonPackageSingleArtifactContentUploadViewSet(
|
|
309
|
-
|
|
304
|
+
core_viewsets.SingleArtifactContentUploadViewSet
|
|
305
|
+
):
|
|
310
306
|
"""
|
|
311
307
|
<!-- User-facing documentation, rendered as html-->
|
|
312
308
|
PythonPackageContent represents each individually installable Python package. In the Python
|
|
@@ -317,7 +313,7 @@ class PythonPackageSingleArtifactContentUploadViewSet(
|
|
|
317
313
|
|
|
318
314
|
"""
|
|
319
315
|
|
|
320
|
-
endpoint_name =
|
|
316
|
+
endpoint_name = "packages"
|
|
321
317
|
queryset = python_models.PythonPackageContent.objects.all()
|
|
322
318
|
serializer_class = python_serializers.PythonPackageContentSerializer
|
|
323
319
|
minimal_serializer_class = python_serializers.MinimalPythonPackageContentSerializer
|
|
@@ -354,7 +350,7 @@ class PythonRemoteViewSet(core_viewsets.RemoteViewSet, core_viewsets.RolesMixin)
|
|
|
354
350
|
|
|
355
351
|
"""
|
|
356
352
|
|
|
357
|
-
endpoint_name =
|
|
353
|
+
endpoint_name = "python"
|
|
358
354
|
queryset = python_models.PythonRemote.objects.all()
|
|
359
355
|
serializer_class = python_serializers.PythonRemoteSerializer
|
|
360
356
|
queryset_filtering_required_permission = "python.view_pythonremote"
|
|
@@ -426,8 +422,11 @@ class PythonRemoteViewSet(core_viewsets.RemoteViewSet, core_viewsets.RolesMixin)
|
|
|
426
422
|
summary="Create from Bandersnatch",
|
|
427
423
|
responses={201: python_serializers.PythonRemoteSerializer},
|
|
428
424
|
)
|
|
429
|
-
@action(
|
|
430
|
-
|
|
425
|
+
@action(
|
|
426
|
+
detail=False,
|
|
427
|
+
methods=["post"],
|
|
428
|
+
serializer_class=python_serializers.PythonBanderRemoteSerializer,
|
|
429
|
+
)
|
|
431
430
|
def from_bandersnatch(self, request):
|
|
432
431
|
"""
|
|
433
432
|
<!-- User-facing documentation, rendered as html-->
|
|
@@ -439,11 +438,12 @@ class PythonRemoteViewSet(core_viewsets.RemoteViewSet, core_viewsets.RolesMixin)
|
|
|
439
438
|
name = serializer.validated_data.get("name")
|
|
440
439
|
policy = serializer.validated_data.get("policy")
|
|
441
440
|
bander_config = BandersnatchConfig(bander_config_file.file.name).config
|
|
442
|
-
data = {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
441
|
+
data = {
|
|
442
|
+
"name": name,
|
|
443
|
+
"policy": policy,
|
|
444
|
+
"url": bander_config.get("mirror", "master"),
|
|
445
|
+
"download_concurrency": bander_config.get("mirror", "workers"),
|
|
446
|
+
}
|
|
447
447
|
enabled = bander_config.get("plugins", "enabled")
|
|
448
448
|
enabled_all = "all" in enabled
|
|
449
449
|
data["prereleases"] = not (enabled_all or "prerelease_release" in enabled)
|
|
@@ -460,8 +460,9 @@ class PythonRemoteViewSet(core_viewsets.RemoteViewSet, core_viewsets.RolesMixin)
|
|
|
460
460
|
"exclude_platform": ("blocklist", "platforms", "exclude_platforms"),
|
|
461
461
|
}
|
|
462
462
|
for plugin, options in plugin_filters.items():
|
|
463
|
-
if (enabled_all or plugin in enabled) and
|
|
464
|
-
|
|
463
|
+
if (enabled_all or plugin in enabled) and bander_config.has_option(
|
|
464
|
+
options[0], options[1]
|
|
465
|
+
):
|
|
465
466
|
data[options[2]] = bander_config.get(options[0], options[1]).split()
|
|
466
467
|
remote = python_serializers.PythonRemoteSerializer(data=data, context={"request": request})
|
|
467
468
|
remote.is_valid(raise_exception=True)
|
|
@@ -478,7 +479,7 @@ class PythonPublicationViewSet(core_viewsets.PublicationViewSet, core_viewsets.R
|
|
|
478
479
|
|
|
479
480
|
"""
|
|
480
481
|
|
|
481
|
-
endpoint_name =
|
|
482
|
+
endpoint_name = "pypi"
|
|
482
483
|
queryset = python_models.PythonPublication.objects.exclude(complete=False)
|
|
483
484
|
serializer_class = python_serializers.PythonPublicationSerializer
|
|
484
485
|
queryset_filtering_required_permission = "python.view_pythonpublication"
|
|
@@ -542,9 +543,7 @@ class PythonPublicationViewSet(core_viewsets.PublicationViewSet, core_viewsets.R
|
|
|
542
543
|
"python.pythonpublication_viewer": ["python.view_pythonpublication"],
|
|
543
544
|
}
|
|
544
545
|
|
|
545
|
-
@extend_schema(
|
|
546
|
-
responses={202: AsyncOperationResponseSerializer}
|
|
547
|
-
)
|
|
546
|
+
@extend_schema(responses={202: AsyncOperationResponseSerializer})
|
|
548
547
|
def create(self, request):
|
|
549
548
|
"""
|
|
550
549
|
<!-- User-facing documentation, rendered as html-->
|
|
@@ -552,18 +551,16 @@ class PythonPublicationViewSet(core_viewsets.PublicationViewSet, core_viewsets.R
|
|
|
552
551
|
"""
|
|
553
552
|
serializer = self.get_serializer(data=request.data)
|
|
554
553
|
serializer.is_valid(raise_exception=True)
|
|
555
|
-
repository_version = serializer.validated_data.get(
|
|
554
|
+
repository_version = serializer.validated_data.get("repository_version")
|
|
556
555
|
|
|
557
556
|
# Safe because version OR repository is enforced by serializer.
|
|
558
557
|
if not repository_version:
|
|
559
|
-
repository = serializer.validated_data.get(
|
|
558
|
+
repository = serializer.validated_data.get("repository")
|
|
560
559
|
repository_version = RepositoryVersion.latest(repository)
|
|
561
560
|
|
|
562
561
|
result = dispatch(
|
|
563
562
|
tasks.publish,
|
|
564
563
|
shared_resources=[repository_version.repository],
|
|
565
|
-
kwargs={
|
|
566
|
-
'repository_version_pk': str(repository_version.pk)
|
|
567
|
-
}
|
|
564
|
+
kwargs={"repository_version_pk": str(repository_version.pk)},
|
|
568
565
|
)
|
|
569
566
|
return core_viewsets.OperationPostponedResponse(result, request)
|
pulp_python/pytest_plugin.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
import uuid
|
|
3
1
|
import subprocess
|
|
2
|
+
import uuid
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
4
5
|
|
|
5
6
|
from pulpcore.tests.functional.utils import BindingsNamespace
|
|
7
|
+
|
|
6
8
|
from pulp_python.tests.functional.constants import (
|
|
7
|
-
PYTHON_FIXTURE_URL,
|
|
8
|
-
PYTHON_XS_PROJECT_SPECIFIER,
|
|
9
9
|
PYTHON_EGG_FILENAME,
|
|
10
|
+
PYTHON_FIXTURE_URL,
|
|
10
11
|
PYTHON_URL,
|
|
12
|
+
PYTHON_XS_PROJECT_SPECIFIER,
|
|
11
13
|
)
|
|
12
14
|
|
|
13
|
-
|
|
14
15
|
# Bindings API Fixtures
|
|
15
16
|
|
|
16
17
|
|
|
@@ -35,6 +36,7 @@ def python_bindings(_api_client_set, bindings_cfg):
|
|
|
35
36
|
@pytest.fixture
|
|
36
37
|
def python_repo_factory(python_bindings, gen_object_with_cleanup):
|
|
37
38
|
"""A factory to generate a Python Repository with auto-cleanup."""
|
|
39
|
+
|
|
38
40
|
def _gen_python_repo(remote=None, pulp_domain=None, **body):
|
|
39
41
|
body.setdefault("name", str(uuid.uuid4()))
|
|
40
42
|
kwargs = {}
|
|
@@ -56,6 +58,7 @@ def python_repo(python_repo_factory):
|
|
|
56
58
|
@pytest.fixture
|
|
57
59
|
def python_distribution_factory(python_bindings, gen_object_with_cleanup):
|
|
58
60
|
"""A factory to generate a Python Distribution with auto-cleanup."""
|
|
61
|
+
|
|
59
62
|
def _gen_python_distribution(
|
|
60
63
|
publication=None, repository=None, version=None, pulp_domain=None, **body
|
|
61
64
|
):
|
|
@@ -85,6 +88,7 @@ def python_distribution_factory(python_bindings, gen_object_with_cleanup):
|
|
|
85
88
|
@pytest.fixture
|
|
86
89
|
def python_publication_factory(python_bindings, gen_object_with_cleanup):
|
|
87
90
|
"""A factory to generate a Python Publication with auto-cleanup."""
|
|
91
|
+
|
|
88
92
|
def _gen_python_publication(repository, version=None, pulp_domain=None):
|
|
89
93
|
repo_href = get_href(repository)
|
|
90
94
|
if version:
|
|
@@ -106,6 +110,7 @@ def python_publication_factory(python_bindings, gen_object_with_cleanup):
|
|
|
106
110
|
@pytest.fixture
|
|
107
111
|
def python_remote_factory(python_bindings, gen_object_with_cleanup):
|
|
108
112
|
"""A factory to generate a Python Remote with auto-cleanup."""
|
|
113
|
+
|
|
109
114
|
def _gen_python_remote(url=PYTHON_FIXTURE_URL, includes=None, pulp_domain=None, **body):
|
|
110
115
|
body.setdefault("name", str(uuid.uuid4()))
|
|
111
116
|
body.setdefault("url", url)
|
|
@@ -125,6 +130,7 @@ def python_repo_with_sync(
|
|
|
125
130
|
python_bindings, python_repo_factory, python_remote_factory, monitor_task
|
|
126
131
|
):
|
|
127
132
|
"""A factory to generate a Python Repository synced with the passed in Remote."""
|
|
133
|
+
|
|
128
134
|
def _gen_python_repo_sync(remote=None, mirror=False, repository=None, **body):
|
|
129
135
|
kwargs = {}
|
|
130
136
|
if pulp_domain := body.get("pulp_domain"):
|
|
@@ -141,6 +147,7 @@ def python_repo_with_sync(
|
|
|
141
147
|
@pytest.fixture
|
|
142
148
|
def download_python_file(tmp_path, http_get):
|
|
143
149
|
"""Download a Python file and return its path."""
|
|
150
|
+
|
|
144
151
|
def _download_python_file(relative_path, url):
|
|
145
152
|
file_path = tmp_path / relative_path
|
|
146
153
|
with open(file_path, mode="wb") as f:
|
|
@@ -159,6 +166,7 @@ def python_file(download_python_file):
|
|
|
159
166
|
@pytest.fixture
|
|
160
167
|
def python_content_factory(python_bindings, download_python_file, monitor_task):
|
|
161
168
|
"""A factory to create a Python Package Content."""
|
|
169
|
+
|
|
162
170
|
def _gen_python_content(relative_path=PYTHON_EGG_FILENAME, url=None, **body):
|
|
163
171
|
body["relative_path"] = relative_path
|
|
164
172
|
if url:
|
|
@@ -191,6 +199,7 @@ def shelf_reader_cleanup():
|
|
|
191
199
|
@pytest.fixture
|
|
192
200
|
def python_content_summary(python_bindings):
|
|
193
201
|
"""Get a summary of the repository version's content."""
|
|
202
|
+
|
|
194
203
|
def _gen_summary(repository_version=None, repository=None, version=None):
|
|
195
204
|
if repository_version is None:
|
|
196
205
|
repo_href = get_href(repository)
|