Skip to content

Commit deda5e0

Browse files
author
Li
committed
#253: Pypi: add author object mapper and update the test to make sure the build passes
1 parent bcbee9b commit deda5e0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/packagedcode/pypi.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from commoncode import fileutils
3333
from packagedcode.models import AssertedLicense
3434
from packagedcode.models import PythonPackage
35+
from packagedcode import models
3536

3637

3738
"""
@@ -76,7 +77,7 @@ def parse_pkg_info(location):
7677
asserted_licenses=[AssertedLicense(license=infos.get('License'))],
7778
# FIXME: what about Party objects and email?
7879
# FIXME: what about maintainers?
79-
authors=[infos.get('Author')],
80+
authors=[models.Party(type=models.party_person, name=infos.get('Author'))],
8081
)
8182
return package
8283

@@ -122,15 +123,14 @@ def parse_metadata(location):
122123
"""
123124
if not location or not location.endswith('metadata.json'):
124125
return
125-
126126
parent_dir = fileutils.parent_directory(location)
127127
# FIXME: is the absence of these two files a show stopper?
128128
if not all(os.path.exists(os.path.join(parent_dir, fname))
129-
for fname in ('METADATA' 'DESCRIPTION.rst')):
129+
for fname in ('METADATA', 'DESCRIPTION.rst')):
130130
return
131131
# FIXME: wrap in a with statement
132132
infos = json.loads(open(location, 'rb').read())
133-
133+
print(infos)
134134
homepage_url = None
135135
authors = []
136136
if infos['extensions']:
@@ -141,7 +141,7 @@ def parse_metadata(location):
141141
pass
142142
try:
143143
for contact in infos['extensions']['python.details']['contacts']:
144-
authors.append(contact['name'])
144+
authors.append(models.Party(type=models.party_person, name=contact['name'],))
145145
except:
146146
# FIXME: why catch all expections?
147147
pass
@@ -169,7 +169,7 @@ def parse(location):
169169
homepage_url=get_attribute(location, 'url'),
170170
description=get_attribute(location, 'description'),
171171
version=get_attribute(location, 'version'),
172-
authors=[get_attribute(location, 'author')],
172+
authors=[models.Party(type=models.party_person, name=get_attribute(location, 'author'))],
173173
asserted_licenses=[AssertedLicense(license=get_attribute(location, 'license'))],
174174
)
175175
return package

tests/packagedcode/test_pypi.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_parse(self):
4141
package = pypi.parse(test_file)
4242
assert 'scancode-toolkit' == package.name
4343
assert '1.5.0' == package.version
44-
assert 'ScanCode' == package.authors[0]
44+
assert 'ScanCode' == package.authors[0].name
4545
assert 'ScanCode is a tool to scan code for license, copyright and other interesting facts.' == package.description
4646
assert 'https://github.com/nexB/scancode-toolkit' == package.homepage_url
4747

@@ -54,13 +54,14 @@ def test_get_attribute(self):
5454
assert 'ScanCode' == pypi.get_attribute(test_file, 'author')
5555

5656
def test_parse_metadata(self):
57-
test_file = self.get_test_loc('pypi/metadata.json')
57+
test_folder = self.get_test_loc('pypi')
58+
test_file = os.path.join(test_folder, 'metadata.json')
5859
package = pypi.parse_metadata(test_file)
5960
assert 'six' == package.name
6061
assert '1.10.0' == package.version
6162
assert 'Python 2 and 3 compatibility utilities' == package.summary
6263
assert 'MIT' == package.asserted_licenses[0].license
63-
assert ['Benjamin Peterson'] == package.authors
64+
assert 'Benjamin Peterson' == package.authors[0].name
6465
assert 'http://pypi.python.org/pypi/six/' == package.homepage_url
6566

6667
def test_parse_pkg_info(self):
@@ -71,4 +72,4 @@ def test_parse_pkg_info(self):
7172
assert 'Import CSV and Excel files' == package.summary
7273
assert 'BSD' == package.asserted_licenses[0].license
7374
assert 'http://nexb.com' == package.homepage_url
74-
assert ['Francois Granade'] == package.authors
75+
assert 'Francois Granade' == package.authors[0].name

0 commit comments

Comments
 (0)