Skip to content

Commit 1a2ab02

Browse files
alexjavanlacerda
authored andcommitted
fixes pypi#10308 -- display wheel tags in a human readable way on package files page (pypi#15606)
* Added utility for extracting pretty wheel tags from filename * Show pretty wheel tags in PyPI interface * Update translations
1 parent 48bb241 commit 1a2ab02

File tree

6 files changed

+224
-49
lines changed

6 files changed

+224
-49
lines changed

tests/unit/packaging/test_models.py

+9
Original file line numberDiff line numberDiff line change
@@ -806,3 +806,12 @@ def test_published_via_trusted_publisher_from_uploaded_via_trusted_publisher(
806806
)
807807

808808
assert rfile.uploaded_via_trusted_publisher
809+
810+
def test_pretty_wheel_tags(self, db_session):
811+
project = DBProjectFactory.create()
812+
release = DBReleaseFactory.create(project=project)
813+
rfile = DBFileFactory.create(
814+
release=release, filename=f"{project.name}-{release.version}.tar.gz"
815+
)
816+
817+
assert rfile.pretty_wheel_tags == ["Source"]

tests/unit/utils/test_wheel.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
import pytest
14+
15+
from warehouse.utils import wheel
16+
17+
18+
@pytest.mark.parametrize(
19+
("filename", "expected_tags"),
20+
[
21+
("cryptography-42.0.5.tar.gz", ["Source"]),
22+
(
23+
"cryptography-42.0.5-pp310-pypy310_pp73-win_amd64.whl",
24+
["PyPy", "Windows x86-64"],
25+
),
26+
(
27+
"cryptography-42.0.5-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl",
28+
["PyPy", "manylinux: glibc 2.28+ x86-64"],
29+
),
30+
(
31+
"cryptography-42.0.5-cp37-abi3-musllinux_1_2_x86_64.whl",
32+
["CPython 3.7+", "musllinux: musl 1.2+ x86-64"],
33+
),
34+
(
35+
"cryptography-42.0.5-cp37-abi3-macosx_10_12_universal2.whl",
36+
["CPython 3.7+", "macOS 10.12+ universal2 (ARM64, x86-64)"],
37+
),
38+
(
39+
"pgf-1.0-pp27-pypy_73-manylinux2010_x86_64.whl",
40+
["PyPy", "manylinux: glibc 2.12+ x86-64"],
41+
),
42+
("pdfcomparator-0_2_0-py2-none-any.whl", []),
43+
(
44+
"mclbn256-0.6.0-py3-abi3-macosx_12_0_arm64.whl",
45+
["Python 3", "macOS 12.0+ ARM64"],
46+
),
47+
(
48+
"pep272_encryption-0.4-py2.pp35.pp36.pp37.pp38.pp39-none-any.whl",
49+
["PyPy", "Python 2"],
50+
),
51+
(
52+
"ruff-0.3.2-py3-none-musllinux_1_2_armv7l.whl",
53+
["Python 3", "musllinux: musl 1.2+ ARMv7l"],
54+
),
55+
(
56+
"numpy-1.26.4-cp312-cp312-musllinux_1_1_x86_64.whl",
57+
["CPython 3.12", "musllinux: musl 1.1+ x86-64"],
58+
),
59+
(
60+
"numpy-1.26.4-lol-lol-musllinux_1_1_x86_64.whl",
61+
["musllinux: musl 1.1+ x86-64"],
62+
),
63+
],
64+
)
65+
def test_wheel_to_pretty_tags(filename, expected_tags):
66+
assert wheel.filename_to_pretty_tags(filename) == expected_tags

warehouse/locale/messages.pot

+45-45
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ msgstr ""
790790
#: warehouse/templates/manage/project/release.html:200
791791
#: warehouse/templates/manage/project/releases.html:140
792792
#: warehouse/templates/manage/project/releases.html:179
793-
#: warehouse/templates/packaging/detail.html:378
794-
#: warehouse/templates/packaging/detail.html:397
793+
#: warehouse/templates/packaging/detail.html:376
794+
#: warehouse/templates/packaging/detail.html:395
795795
#: warehouse/templates/pages/classifiers.html:25
796796
#: warehouse/templates/pages/help.html:20
797797
#: warehouse/templates/pages/help.html:218
@@ -2877,7 +2877,7 @@ msgstr ""
28772877
#: warehouse/templates/manage/account.html:206
28782878
#: warehouse/templates/manage/account/recovery_codes-provision.html:58
28792879
#: warehouse/templates/manage/account/totp-provision.html:57
2880-
#: warehouse/templates/packaging/detail.html:160
2880+
#: warehouse/templates/packaging/detail.html:158
28812881
#: warehouse/templates/pages/classifiers.html:38
28822882
msgid "Copy to clipboard"
28832883
msgstr ""
@@ -6639,149 +6639,149 @@ msgstr ""
66396639
msgid "view hashes"
66406640
msgstr ""
66416641

6642-
#: warehouse/templates/packaging/detail.html:128
6642+
#: warehouse/templates/packaging/detail.html:126
66436643
#, python-format
66446644
msgid "RSS: latest releases for %(project_name)s"
66456645
msgstr ""
66466646

6647-
#: warehouse/templates/packaging/detail.html:162
6647+
#: warehouse/templates/packaging/detail.html:160
66486648
msgid "Copy PIP instructions"
66496649
msgstr ""
66506650

6651-
#: warehouse/templates/packaging/detail.html:173
6651+
#: warehouse/templates/packaging/detail.html:171
66526652
msgid "This release has been yanked"
66536653
msgstr ""
66546654

6655-
#: warehouse/templates/packaging/detail.html:179
6655+
#: warehouse/templates/packaging/detail.html:177
66566656
#, python-format
66576657
msgid "Stable version available (%(version)s)"
66586658
msgstr ""
66596659

6660-
#: warehouse/templates/packaging/detail.html:183
6660+
#: warehouse/templates/packaging/detail.html:181
66616661
#, python-format
66626662
msgid "Newer version available (%(version)s)"
66636663
msgstr ""
66646664

6665-
#: warehouse/templates/packaging/detail.html:187
6665+
#: warehouse/templates/packaging/detail.html:185
66666666
msgid "Latest version"
66676667
msgstr ""
66686668

6669-
#: warehouse/templates/packaging/detail.html:192
6669+
#: warehouse/templates/packaging/detail.html:190
66706670
#, python-format
66716671
msgid "Released: %(release_date)s"
66726672
msgstr ""
66736673

6674-
#: warehouse/templates/packaging/detail.html:206
6674+
#: warehouse/templates/packaging/detail.html:204
66756675
msgid "No project description provided"
66766676
msgstr ""
66776677

6678-
#: warehouse/templates/packaging/detail.html:219
6678+
#: warehouse/templates/packaging/detail.html:217
66796679
msgid "Navigation"
66806680
msgstr ""
66816681

6682-
#: warehouse/templates/packaging/detail.html:220
6683-
#: warehouse/templates/packaging/detail.html:254
6682+
#: warehouse/templates/packaging/detail.html:218
6683+
#: warehouse/templates/packaging/detail.html:252
66846684
#, python-format
66856685
msgid "Navigation for %(project)s"
66866686
msgstr ""
66876687

6688-
#: warehouse/templates/packaging/detail.html:223
6689-
#: warehouse/templates/packaging/detail.html:257
6688+
#: warehouse/templates/packaging/detail.html:221
6689+
#: warehouse/templates/packaging/detail.html:255
66906690
msgid "Project description. Focus will be moved to the description."
66916691
msgstr ""
66926692

6693-
#: warehouse/templates/packaging/detail.html:225
6694-
#: warehouse/templates/packaging/detail.html:259
6695-
#: warehouse/templates/packaging/detail.html:293
6693+
#: warehouse/templates/packaging/detail.html:223
6694+
#: warehouse/templates/packaging/detail.html:257
6695+
#: warehouse/templates/packaging/detail.html:291
66966696
msgid "Project description"
66976697
msgstr ""
66986698

6699-
#: warehouse/templates/packaging/detail.html:229
6700-
#: warehouse/templates/packaging/detail.html:269
6699+
#: warehouse/templates/packaging/detail.html:227
6700+
#: warehouse/templates/packaging/detail.html:267
67016701
msgid "Release history. Focus will be moved to the history panel."
67026702
msgstr ""
67036703

6704-
#: warehouse/templates/packaging/detail.html:231
6705-
#: warehouse/templates/packaging/detail.html:271
6706-
#: warehouse/templates/packaging/detail.html:315
6704+
#: warehouse/templates/packaging/detail.html:229
6705+
#: warehouse/templates/packaging/detail.html:269
6706+
#: warehouse/templates/packaging/detail.html:313
67076707
msgid "Release history"
67086708
msgstr ""
67096709

6710-
#: warehouse/templates/packaging/detail.html:236
6711-
#: warehouse/templates/packaging/detail.html:276
6710+
#: warehouse/templates/packaging/detail.html:234
6711+
#: warehouse/templates/packaging/detail.html:274
67126712
msgid "Download files. Focus will be moved to the project files."
67136713
msgstr ""
67146714

6715-
#: warehouse/templates/packaging/detail.html:238
6716-
#: warehouse/templates/packaging/detail.html:278
6717-
#: warehouse/templates/packaging/detail.html:377
6715+
#: warehouse/templates/packaging/detail.html:236
6716+
#: warehouse/templates/packaging/detail.html:276
6717+
#: warehouse/templates/packaging/detail.html:375
67186718
msgid "Download files"
67196719
msgstr ""
67206720

6721-
#: warehouse/templates/packaging/detail.html:263
6721+
#: warehouse/templates/packaging/detail.html:261
67226722
msgid "Project details. Focus will be moved to the project details."
67236723
msgstr ""
67246724

6725-
#: warehouse/templates/packaging/detail.html:265
6726-
#: warehouse/templates/packaging/detail.html:307
6725+
#: warehouse/templates/packaging/detail.html:263
6726+
#: warehouse/templates/packaging/detail.html:305
67276727
msgid "Project details"
67286728
msgstr ""
67296729

6730-
#: warehouse/templates/packaging/detail.html:289
6731-
#: warehouse/templates/packaging/detail.html:364
6730+
#: warehouse/templates/packaging/detail.html:287
6731+
#: warehouse/templates/packaging/detail.html:362
67326732
msgid "Reason this release was yanked:"
67336733
msgstr ""
67346734

6735-
#: warehouse/templates/packaging/detail.html:300
6735+
#: warehouse/templates/packaging/detail.html:298
67366736
msgid "The author of this package has not provided a project description"
67376737
msgstr ""
67386738

6739-
#: warehouse/templates/packaging/detail.html:317
6739+
#: warehouse/templates/packaging/detail.html:315
67406740
msgid "Release notifications"
67416741
msgstr ""
67426742

6743-
#: warehouse/templates/packaging/detail.html:318
6743+
#: warehouse/templates/packaging/detail.html:316
67446744
msgid "RSS feed"
67456745
msgstr ""
67466746

6747-
#: warehouse/templates/packaging/detail.html:330
6747+
#: warehouse/templates/packaging/detail.html:328
67486748
msgid "This version"
67496749
msgstr ""
67506750

6751-
#: warehouse/templates/packaging/detail.html:350
6751+
#: warehouse/templates/packaging/detail.html:348
67526752
msgid "pre-release"
67536753
msgstr ""
67546754

6755-
#: warehouse/templates/packaging/detail.html:355
6755+
#: warehouse/templates/packaging/detail.html:353
67566756
msgid "yanked"
67576757
msgstr ""
67586758

6759-
#: warehouse/templates/packaging/detail.html:378
6759+
#: warehouse/templates/packaging/detail.html:376
67606760
#, python-format
67616761
msgid ""
67626762
"Download the file for your platform. If you're not sure which to choose, "
67636763
"learn more about <a href=\"%(href)s\" title=\"%(title)s\" "
67646764
"target=\"_blank\" rel=\"noopener\">installing packages</a>."
67656765
msgstr ""
67666766

6767-
#: warehouse/templates/packaging/detail.html:380
6767+
#: warehouse/templates/packaging/detail.html:378
67686768
msgid "Source Distribution"
67696769
msgid_plural "Source Distributions"
67706770
msgstr[0] ""
67716771
msgstr[1] ""
67726772

6773-
#: warehouse/templates/packaging/detail.html:396
6773+
#: warehouse/templates/packaging/detail.html:394
67746774
msgid "No source distribution files available for this release."
67756775
msgstr ""
67766776

6777-
#: warehouse/templates/packaging/detail.html:397
6777+
#: warehouse/templates/packaging/detail.html:395
67786778
#, python-format
67796779
msgid ""
67806780
"See tutorial on <a href=\"%(href)s\" title=\"%(title)s\" "
67816781
"target=\"_blank\" rel=\"noopener\">generating distribution archives</a>."
67826782
msgstr ""
67836783

6784-
#: warehouse/templates/packaging/detail.html:404
6784+
#: warehouse/templates/packaging/detail.html:402
67856785
msgid "Built Distribution"
67866786
msgid_plural "Built Distributions"
67876787
msgstr[0] ""

warehouse/packaging/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
TeamProjectRole,
6868
)
6969
from warehouse.sitemap.models import SitemapMixin
70-
from warehouse.utils import dotted_navigator
70+
from warehouse.utils import dotted_navigator, wheel
7171
from warehouse.utils.attrs import make_repr
7272
from warehouse.utils.db.types import bool_false, datetime_now
7373

@@ -803,6 +803,10 @@ def metadata_path(self):
803803
def validates_requires_python(self, *args, **kwargs):
804804
raise RuntimeError("Cannot set File.requires_python")
805805

806+
@property
807+
def pretty_wheel_tags(self) -> list[str]:
808+
return wheel.filename_to_pretty_tags(self.filename)
809+
806810

807811
class Filename(db.ModelBase):
808812
__tablename__ = "file_registry"

warehouse/templates/packaging/detail.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ <h3 class="package-snippet__title">
108108
<a href="#copy-hash-modal-{{ file.id }}">{%- trans -%}view hashes{%- endtrans -%}</a>)
109109
<p class="file__meta">
110110
Uploaded {{ humanize(file.upload_time) }}
111-
{% if file.python_version %}
112-
{% for tag in file.python_version.split('.') %}
111+
{% for tag in file.pretty_wheel_tags %}
113112
<code>{{ tag }}</code>
114113
{% endfor %}
115-
{% endif %}
116114
</p>
117115
</div>
118116
</div>

0 commit comments

Comments
 (0)