Skip to content

Commit b018bcf

Browse files
committed
Sort metadata by version and name
1 parent 1f7010c commit b018bcf

File tree

3 files changed

+152
-135
lines changed

3 files changed

+152
-135
lines changed

pulp_python/app/models.py

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -145,44 +145,50 @@ class PythonPackageContent(Content):
145145
https://www.python.org/dev/peps/pep-0491/
146146
https://www.python.org/dev/peps/pep-0345/
147147
"""
148-
149-
PROTECTED_FROM_RECLAIM = False
150-
151-
TYPE = "python"
152-
repo_key_fields = ("filename",)
153-
# Required metadata
154-
filename = models.TextField(db_index=True)
155-
packagetype = models.TextField(choices=PACKAGE_TYPES)
156-
name = models.TextField()
157-
name.register_lookup(NormalizeName)
158-
version = models.TextField()
159-
sha256 = models.CharField(db_index=True, max_length=64)
160-
# Optional metadata
161-
python_version = models.TextField()
162-
metadata_version = models.TextField()
163-
summary = models.TextField()
164-
description = models.TextField()
165-
keywords = models.TextField()
166-
home_page = models.TextField()
167-
download_url = models.TextField()
148+
# Core metadata
149+
# Version 1.0
168150
author = models.TextField()
169151
author_email = models.TextField()
152+
description = models.TextField()
153+
home_page = models.TextField() # Deprecated in favour of Project-URL
154+
keywords = models.TextField()
155+
license = models.TextField() # Deprecated in favour of License-Expression
156+
metadata_version = models.TextField()
157+
name = models.TextField()
158+
platform = models.TextField()
159+
summary = models.TextField()
160+
version = models.TextField()
161+
# Version 1.1
162+
classifiers = models.JSONField(default=list)
163+
download_url = models.TextField() # Deprecated in favour of Project-URL
164+
supported_platform = models.TextField()
165+
# Version 1.2
170166
maintainer = models.TextField()
171167
maintainer_email = models.TextField()
172-
license = models.TextField()
173-
requires_python = models.TextField()
168+
obsoletes_dist = models.JSONField(default=list)
174169
project_url = models.TextField()
175-
platform = models.TextField()
176-
supported_platform = models.TextField()
177-
requires_dist = models.JSONField(default=list)
170+
project_urls = models.JSONField(default=dict)
178171
provides_dist = models.JSONField(default=list)
179-
obsoletes_dist = models.JSONField(default=list)
180172
requires_external = models.JSONField(default=list)
181-
classifiers = models.JSONField(default=list)
182-
project_urls = models.JSONField(default=dict)
173+
requires_dist = models.JSONField(default=list)
174+
requires_python = models.TextField()
175+
# Version 2.1
183176
description_content_type = models.TextField()
184-
# Pulp Domains
185-
_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
177+
178+
# Release metadata
179+
filename = models.TextField(db_index=True)
180+
packagetype = models.TextField(choices=PACKAGE_TYPES)
181+
python_version = models.TextField()
182+
sha256 = models.CharField(db_index=True, max_length=64)
183+
184+
# From pulpcore
185+
PROTECTED_FROM_RECLAIM = False
186+
TYPE = "python"
187+
_pulp_domain = models.ForeignKey(
188+
"core.Domain", default=get_domain_pk, on_delete=models.PROTECT
189+
)
190+
name.register_lookup(NormalizeName)
191+
repo_key_fields = ("filename",)
186192

187193
@staticmethod
188194
def init_from_artifact_and_relative_path(artifact, relative_path):

pulp_python/app/serializers.py

Lines changed: 82 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -72,69 +72,69 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
7272
"""
7373
A Serializer for PythonPackageContent.
7474
"""
75-
76-
filename = serializers.CharField(
77-
help_text=_('The name of the distribution package, usually of the format:'
78-
' {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}'
79-
'-{platform tag}.{packagetype}'),
80-
read_only=True,
81-
)
82-
packagetype = serializers.CharField(
83-
help_text=_('The type of the distribution package '
84-
'(e.g. sdist, bdist_wheel, bdist_egg, etc)'),
85-
read_only=True,
86-
)
87-
name = serializers.CharField(
88-
help_text=_('The name of the python project.'),
89-
read_only=True,
90-
)
91-
version = serializers.CharField(
92-
help_text=_('The packages version number.'),
93-
read_only=True,
94-
)
95-
sha256 = serializers.CharField(
96-
default='',
97-
help_text=_('The SHA256 digest of this package.'),
98-
)
99-
metadata_version = serializers.CharField(
100-
help_text=_('Version of the file format'),
101-
read_only=True,
75+
# Core metadata
76+
# Version 1.0
77+
author = serializers.CharField(
78+
required=False, allow_blank=True,
79+
help_text=_('Text containing the author\'s name. Contact information can also be added,'
80+
' separated with newlines.')
10281
)
103-
summary = serializers.CharField(
82+
author_email = serializers.CharField(
10483
required=False, allow_blank=True,
105-
help_text=_('A one-line summary of what the package does.')
84+
help_text=_('The author\'s e-mail address. ')
10685
)
10786
description = serializers.CharField(
10887
required=False, allow_blank=True,
10988
help_text=_('A longer description of the package that can run to several paragraphs.')
11089
)
111-
description_content_type = serializers.CharField(
90+
home_page = serializers.CharField(
11291
required=False, allow_blank=True,
113-
help_text=_('A string stating the markup syntax (if any) used in the distribution’s'
114-
' description, so that tools can intelligently render the description.')
92+
help_text=_('The URL for the package\'s home page.')
11593
)
11694
keywords = serializers.CharField(
11795
required=False, allow_blank=True,
11896
help_text=_('Additional keywords to be used to assist searching for the '
11997
'package in a larger catalog.')
12098
)
121-
home_page = serializers.CharField(
99+
license = serializers.CharField(
122100
required=False, allow_blank=True,
123-
help_text=_('The URL for the package\'s home page.')
101+
help_text=_('Text indicating the license covering the distribution')
124102
)
125-
download_url = serializers.CharField(
103+
metadata_version = serializers.CharField(
104+
help_text=_('Version of the file format'),
105+
read_only=True,
106+
)
107+
name = serializers.CharField(
108+
help_text=_('The name of the python project.'),
109+
read_only=True,
110+
)
111+
platform = serializers.CharField(
126112
required=False, allow_blank=True,
127-
help_text=_('Legacy field denoting the URL from which this package can be downloaded.')
113+
help_text=_('A comma-separated list of platform specifications, '
114+
'summarizing the operating systems supported by the package.')
128115
)
129-
author = serializers.CharField(
116+
summary = serializers.CharField(
130117
required=False, allow_blank=True,
131-
help_text=_('Text containing the author\'s name. Contact information can also be added,'
132-
' separated with newlines.')
118+
help_text=_('A one-line summary of what the package does.')
133119
)
134-
author_email = serializers.CharField(
120+
version = serializers.CharField(
121+
help_text=_('The packages version number.'),
122+
read_only=True,
123+
)
124+
# Version 1.1
125+
classifiers = serializers.JSONField(
126+
required=False, default=list,
127+
help_text=_('A JSON list containing classification values for a Python package.')
128+
)
129+
download_url = serializers.CharField(
135130
required=False, allow_blank=True,
136-
help_text=_('The author\'s e-mail address. ')
131+
help_text=_('Legacy field denoting the URL from which this package can be downloaded.')
137132
)
133+
supported_platform = serializers.CharField(
134+
required=False, allow_blank=True,
135+
help_text=_('Field to specify the OS and CPU for which the binary package was compiled. ')
136+
)
137+
# Version 1.2
138138
maintainer = serializers.CharField(
139139
required=False, allow_blank=True,
140140
help_text=_('The maintainer\'s name at a minimum; '
@@ -144,14 +144,11 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
144144
required=False, allow_blank=True,
145145
help_text=_('The maintainer\'s e-mail address.')
146146
)
147-
license = serializers.CharField(
148-
required=False, allow_blank=True,
149-
help_text=_('Text indicating the license covering the distribution')
150-
)
151-
requires_python = serializers.CharField(
152-
required=False, allow_blank=True,
153-
help_text=_('The Python version(s) that the distribution is guaranteed to be '
154-
'compatible with.')
147+
obsoletes_dist = serializers.JSONField(
148+
required=False, default=list,
149+
help_text=_('A JSON list containing names of a distutils project\'s distribution which '
150+
'this distribution renders obsolete, meaning that the two projects should not '
151+
'be installed at the same time.')
155152
)
156153
project_url = serializers.CharField(
157154
required=False, allow_blank=True,
@@ -161,39 +158,47 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa
161158
required=False, default=dict,
162159
help_text=_('A dictionary of labels and URLs for the project.')
163160
)
164-
platform = serializers.CharField(
165-
required=False, allow_blank=True,
166-
help_text=_('A comma-separated list of platform specifications, '
167-
'summarizing the operating systems supported by the package.')
168-
)
169-
supported_platform = serializers.CharField(
170-
required=False, allow_blank=True,
171-
help_text=_('Field to specify the OS and CPU for which the binary package was compiled. ')
172-
)
173-
requires_dist = serializers.JSONField(
174-
required=False, default=list,
175-
help_text=_('A JSON list containing names of some other distutils project '
176-
'required by this distribution.')
177-
)
178161
provides_dist = serializers.JSONField(
179162
required=False, default=list,
180163
help_text=_('A JSON list containing names of a Distutils project which is contained'
181164
' within this distribution.')
182165
)
183-
obsoletes_dist = serializers.JSONField(
184-
required=False, default=list,
185-
help_text=_('A JSON list containing names of a distutils project\'s distribution which '
186-
'this distribution renders obsolete, meaning that the two projects should not '
187-
'be installed at the same time.')
188-
)
189166
requires_external = serializers.JSONField(
190167
required=False, default=list,
191168
help_text=_('A JSON list containing some dependency in the system that the distribution '
192169
'is to be used.')
193170
)
194-
classifiers = serializers.JSONField(
171+
requires_dist = serializers.JSONField(
195172
required=False, default=list,
196-
help_text=_('A JSON list containing classification values for a Python package.')
173+
help_text=_('A JSON list containing names of some other distutils project '
174+
'required by this distribution.')
175+
)
176+
requires_python = serializers.CharField(
177+
required=False, allow_blank=True,
178+
help_text=_('The Python version(s) that the distribution is guaranteed to be '
179+
'compatible with.')
180+
)
181+
# Version 2.1
182+
description_content_type = serializers.CharField(
183+
required=False, allow_blank=True,
184+
help_text=_('A string stating the markup syntax (if any) used in the distribution’s'
185+
' description, so that tools can intelligently render the description.')
186+
)
187+
# Release metadata
188+
filename = serializers.CharField(
189+
help_text=_('The name of the distribution package, usually of the format:'
190+
' {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}'
191+
'-{platform tag}.{packagetype}'),
192+
read_only=True,
193+
)
194+
packagetype = serializers.CharField(
195+
help_text=_('The type of the distribution package '
196+
'(e.g. sdist, bdist_wheel, bdist_egg, etc)'),
197+
read_only=True,
198+
)
199+
sha256 = serializers.CharField(
200+
default='',
201+
help_text=_('The SHA256 digest of this package.'),
197202
)
198203

199204
def deferred_validate(self, data):
@@ -242,11 +247,12 @@ def retrieve(self, validated_data):
242247

243248
class Meta:
244249
fields = core_serializers.SingleArtifactContentUploadSerializer.Meta.fields + (
245-
'filename', 'packagetype', 'name', 'version', 'sha256', 'metadata_version', 'summary',
246-
'description', 'description_content_type', 'keywords', 'home_page', 'download_url',
247-
'author', 'author_email', 'maintainer', 'maintainer_email', 'license',
248-
'requires_python', 'project_url', 'project_urls', 'platform', 'supported_platform',
249-
'requires_dist', 'provides_dist', 'obsoletes_dist', 'requires_external', 'classifiers'
250+
'author', 'author_email', 'description', 'home_page', 'keywords', 'license',
251+
'metadata_version', 'name', 'platform', 'summary', 'version', 'classifiers',
252+
'download_url', 'supported_platform', 'maintainer', 'maintainer_email',
253+
'obsoletes_dist', 'project_url', 'project_urls', 'provides_dist', 'requires_external',
254+
'requires_dist', 'requires_python', 'description_content_type',
255+
'filename', 'packagetype', 'sha256'
250256
)
251257
model = python_models.PythonPackageContent
252258

pulp_python/app/utils.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,35 +87,40 @@ def parse_project_metadata(project):
8787
dictionary: of python project metadata
8888
8989
"""
90-
package = {}
91-
package['name'] = project.get('name') or ""
92-
package['version'] = project.get('version') or ""
93-
package['packagetype'] = project.get('packagetype') or ""
94-
package['metadata_version'] = project.get('metadata_version') or ""
95-
package['summary'] = project.get('summary') or ""
96-
package['description'] = project.get('description') or ""
97-
package['keywords'] = project.get('keywords') or ""
98-
package['home_page'] = project.get('home_page') or ""
99-
package['download_url'] = project.get('download_url') or ""
100-
package['author'] = project.get('author') or ""
101-
package['author_email'] = project.get('author_email') or ""
102-
package['maintainer'] = project.get('maintainer') or ""
103-
package['maintainer_email'] = project.get('maintainer_email') or ""
104-
package['license'] = project.get('license') or ""
105-
package['project_url'] = project.get('project_url') or ""
106-
package['platform'] = project.get('platform') or ""
107-
package['supported_platform'] = project.get('supported_platform') or ""
108-
package['requires_python'] = project.get('requires_python') or ""
109-
package['requires_dist'] = json.dumps(project.get('requires_dist', []))
110-
package['provides_dist'] = json.dumps(project.get('provides_dist', []))
111-
package['obsoletes_dist'] = json.dumps(project.get('obsoletes_dist', []))
112-
package['requires_external'] = json.dumps(project.get('requires_external', []))
113-
package['classifiers'] = json.dumps(project.get('classifiers', []))
114-
package['project_urls'] = json.dumps(project.get('project_urls', {}))
115-
package['description_content_type'] = project.get('description_content_type') or ""
116-
package['python_version'] = project.get('python_version') or ""
117-
118-
return package
90+
return {
91+
# Core metadata
92+
# Version 1.0
93+
'author': project.get('author') or "",
94+
'author_email': project.get('author_email') or "",
95+
'description': project.get('description') or "",
96+
'home_page': project.get('home_page') or "",
97+
'keywords': project.get('keywords') or "",
98+
'license': project.get('license') or "",
99+
'metadata_version': project.get('metadata_version') or "",
100+
'name': project.get('name') or "",
101+
'platform': project.get('platform') or "",
102+
'summary': project.get('summary') or "",
103+
'version': project.get('version') or "",
104+
# Version 1.1
105+
'classifiers': json.dumps(project.get('classifiers', [])),
106+
'download_url': project.get('download_url') or "",
107+
'supported_platform': project.get('supported_platform') or "",
108+
# Version 1.2
109+
'maintainer': project.get('maintainer') or "",
110+
'maintainer_email': project.get('maintainer_email') or "",
111+
'obsoletes_dist': json.dumps(project.get('obsoletes_dist', [])),
112+
'project_url': project.get('project_url') or "",
113+
'project_urls': json.dumps(project.get('project_urls', {})),
114+
'provides_dist': json.dumps(project.get('provides_dist', [])),
115+
'requires_external': json.dumps(project.get('requires_external', [])),
116+
'requires_dist': json.dumps(project.get('requires_dist', [])),
117+
'requires_python': project.get('requires_python') or "",
118+
# Version 2.1
119+
'description_content_type': project.get('description_content_type') or "",
120+
# Release metadata
121+
'packagetype': project.get('packagetype') or "",
122+
'python_version': project.get('python_version') or "",
123+
}
119124

120125

121126
def parse_metadata(project, version, distribution):

0 commit comments

Comments
 (0)