Merge lp:~dustin-ingram/pkginfo/add-new-fields into lp:pkginfo

Proposed by dustingram
Status: Merged
Approved by: Tres Seaver
Approved revision: 146
Merged at revision: 145
Proposed branch: lp:~dustin-ingram/pkginfo/add-new-fields
Merge into: lp:pkginfo
Diff against target: 106 lines (+32/-10)
3 files modified
pkginfo/distribution.py (+14/-1)
pkginfo/tests/test_distribution.py (+18/-0)
pkginfo/wheel.py (+0/-9)
To merge this branch: bzr merge lp:~dustin-ingram/pkginfo/add-new-fields
Reviewer Review Type Date Requested Status
Tres Seaver Pending
Review via email: mp+330572@code.launchpad.net

Commit message

Add 'Provides-Extra' and 'Description-Content-Type' fields

Description of the change

Add the 'Provides-Extra' and 'Description-Content-Type' fields, per https://packaging.python.org/specifications/.

To post a comment you must log in.
145. By dustingram

Add defaults for 'provides_extras' and 'description_content_type'

Revision history for this message
Tres Seaver (tseaver) wrote :

Looking at the branch, I'd like some guidance from the PyPA about what metadata version is supposed to define those fields. See my query on https://github.com/python/peps/issues/388

146. By dustingram

Updates for PEP 566

Revision history for this message
dustingram (dustin-ingram) wrote :

> Looking at the branch, I'd like some guidance from the PyPA about what
> metadata version is supposed to define those fields. See my query on
> https://github.com/python/peps/issues/388

PEP 566 has now been accepted, I've updated this merge request accordingly.

Revision history for this message
Tres Seaver (tseaver) wrote :

Thanks for the patch! I will release a new version after reviewing open merge requests / issues.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkginfo/distribution.py'
2--- pkginfo/distribution.py 2013-11-27 22:09:41 +0000
3+++ pkginfo/distribution.py 2018-03-03 22:34:24 +0000
4@@ -58,11 +58,17 @@
5
6 HEADER_ATTRS_2_0 = HEADER_ATTRS_1_2 #XXX PEP 426?
7
8+HEADER_ATTRS_2_1 = HEADER_ATTRS_1_2 + ( # PEP 566
9+ ('Provides-Extra', 'provides_extras', True),
10+ ('Description-Content-Type', 'description_content_type', False)
11+)
12+
13 HEADER_ATTRS = {
14 '1.0': HEADER_ATTRS_1_0,
15 '1.1': HEADER_ATTRS_1_1,
16 '1.2': HEADER_ATTRS_1_2,
17 '2.0': HEADER_ATTRS_2_0,
18+ '2.1': HEADER_ATTRS_2_1,
19 }
20
21 class Distribution(object):
22@@ -94,6 +100,9 @@
23 provides_dist = ()
24 obsoletes_dist = ()
25 project_urls = ()
26+ # version 2.1
27+ provides_extras = ()
28+ description_content_type = None
29
30 def extractMetadata(self):
31 data = self.read()
32@@ -126,7 +135,11 @@
33 value = get(msg, header_name)
34 if value != 'UNKNOWN':
35 setattr(self, attr_name, value)
36-
37+
38+ body = msg.get_payload()
39+ if body:
40+ setattr(self, 'description', body)
41+
42 def __iter__(self):
43 for header_name, attr_name, multiple in self._getHeaderAttrs():
44 yield attr_name
45
46=== modified file 'pkginfo/tests/test_distribution.py'
47--- pkginfo/tests/test_distribution.py 2013-10-09 21:36:30 +0000
48+++ pkginfo/tests/test_distribution.py 2018-03-03 22:34:24 +0000
49@@ -74,6 +74,14 @@
50 self.assertEqual(list(dist),
51 [x[1] for x in HEADER_ATTRS_1_2])
52
53+ def test_parse_Metadata_Version_2_1(self):
54+ from pkginfo.distribution import HEADER_ATTRS_2_1
55+ dist = self._makeOne(None)
56+ dist.parse('Metadata-Version: 2.1')
57+ self.assertEqual(dist.metadata_version, '2.1')
58+ self.assertEqual(list(dist),
59+ [x[1] for x in HEADER_ATTRS_2_1])
60+
61 def test_parse_Metadata_Version_unknown(self):
62 dist = self._makeOne(None)
63 dist.parse('Metadata-Version: 1.3')
64@@ -138,6 +146,16 @@
65 'This package enables integration with\n'
66 'foo servers.')
67
68+ def test_parse_Description_in_payload(self):
69+ dist = self._makeOne()
70+ dist.parse('Foo: Bar\n'
71+ '\n'
72+ 'This package enables integration with\n'
73+ 'foo servers.')
74+ self.assertEqual(dist.description,
75+ 'This package enables integration with\n'
76+ 'foo servers.')
77+
78 def test_parse_Keywords(self):
79 dist = self._makeOne()
80 dist.parse('Keywords: bar foo qux')
81
82=== modified file 'pkginfo/wheel.py'
83--- pkginfo/wheel.py 2013-11-27 22:09:41 +0000
84+++ pkginfo/wheel.py 2018-03-03 22:34:24 +0000
85@@ -1,11 +1,8 @@
86-from io import StringIO
87 import os
88 import zipfile
89
90
91 from .distribution import Distribution
92-from .distribution import must_decode
93-from .distribution import parse
94
95
96 class Wheel(Distribution):
97@@ -41,9 +38,3 @@
98 archive.close()
99
100 raise ValueError('No METADATA in archive: %s' % fqn)
101-
102- def parse(self, data):
103- super(Wheel, self).parse(data)
104- fp = StringIO(must_decode(data))
105- msg = parse(fp)
106- self.description = msg.get_payload()

Subscribers

People subscribed via source and target branches