Skip to content

Commit 9466e0f

Browse files
Create PackageManifest class fot aboutfiles
Creates PackacgeManifest class for aboutfiles and overrides detection and PackageMamanifest creation methods. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 1d561d5 commit 9466e0f

6 files changed

Lines changed: 161 additions & 154 deletions

File tree

src/packagedcode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
models.JBossSar,
5151
models.Axis2Mar,
5252

53-
about.AboutPackage,
53+
about.Aboutfile,
5454
npm.NpmPackage,
5555
phpcomposer.PHPComposerPackage,
5656
haxe.HaxePackage,

src/packagedcode/about.py

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929
# TODO: Override get_package_resource so it returns the Resource that the ABOUT file is describing
3030

3131
@attr.s()
32-
class AboutPackage(models.Package, models.PackageManifest):
33-
file_patterns = ('*.ABOUT',)
34-
default_type = 'about'
32+
class AboutPackage(models.Package):
3533

36-
@classmethod
37-
def recognize(cls, location):
38-
yield parse(location)
34+
default_type = 'about'
3935

4036
def get_package_root(self, manifest_resource, codebase):
4137
about_resource = self.extra_data.get('about_resource')
@@ -47,53 +43,55 @@ def get_package_root(self, manifest_resource, codebase):
4743
return manifest_resource
4844

4945

50-
def is_about_file(location):
51-
return (filetype.is_file(location)
52-
and location.lower().endswith(('.about',)))
53-
54-
55-
def parse(location):
56-
"""
57-
Return a Package object from an ABOUT file or None.
58-
"""
59-
if not is_about_file(location):
60-
return
61-
62-
with io.open(location, encoding='utf-8') as loc:
63-
package_data = saneyaml.load(loc.read())
64-
65-
return build_package(package_data)
66-
67-
68-
def build_package(package_data):
69-
"""
70-
Return a Package built from `package_data` obtained by an ABOUT file.
71-
"""
72-
name = package_data.get('name')
73-
# FIXME: having no name may not be a problem See #1514
74-
if not name:
75-
return
76-
77-
version = package_data.get('version')
78-
homepage_url = package_data.get('home_url') or package_data.get('homepage_url')
79-
download_url = package_data.get('download_url')
80-
declared_license = package_data.get('license_expression')
81-
copyright_statement = package_data.get('copyright')
82-
83-
owner = package_data.get('owner')
84-
if not isinstance(owner, str):
85-
owner = repr(owner)
86-
parties = [models.Party(type=models.party_person, name=owner, role='owner')]
87-
88-
about_package = AboutPackage(
89-
type='about',
90-
name=name,
91-
version=version,
92-
declared_license=declared_license,
93-
copyright=copyright_statement,
94-
parties=parties,
95-
homepage_url=homepage_url,
96-
download_url=download_url,
97-
)
98-
about_package.extra_data['about_resource'] = package_data.get('about_resource')
99-
return about_package
46+
@attr.s()
47+
class Aboutfile(AboutPackage, models.PackageManifest):
48+
49+
file_patterns = ('*.ABOUT',)
50+
extensions = ('.ABOUT',)
51+
manifest_type = 'aboutfile'
52+
53+
@classmethod
54+
def is_manifest(cls, location):
55+
"""
56+
Return True if the file at ``location`` is likely a manifest of this type.
57+
"""
58+
return (filetype.is_file(location) and location.lower().endswith(('.about',)))
59+
60+
@classmethod
61+
def recognize(cls, location):
62+
"""
63+
Yield one or more Package manifest objects given a file ``location`` pointing to a
64+
package archive, manifest or similar.
65+
"""
66+
with io.open(location, encoding='utf-8') as loc:
67+
package_data = saneyaml.load(loc.read())
68+
69+
name = package_data.get('name')
70+
# FIXME: having no name may not be a problem See #1514
71+
if not name:
72+
return
73+
74+
version = package_data.get('version')
75+
homepage_url = package_data.get('home_url') or package_data.get('homepage_url')
76+
download_url = package_data.get('download_url')
77+
declared_license = package_data.get('license_expression')
78+
copyright_statement = package_data.get('copyright')
79+
80+
owner = package_data.get('owner')
81+
if not isinstance(owner, str):
82+
owner = repr(owner)
83+
parties = [models.Party(type=models.party_person, name=owner, role='owner')]
84+
85+
about_package = cls(
86+
type='about',
87+
name=name,
88+
version=version,
89+
declared_license=declared_license,
90+
copyright=copyright_statement,
91+
parties=parties,
92+
homepage_url=homepage_url,
93+
download_url=download_url,
94+
)
95+
96+
about_package.extra_data['about_resource'] = package_data.get('about_resource')
97+
yield about_package
Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
1-
{
2-
"type": "about",
3-
"namespace": null,
4-
"name": "apipkg",
5-
"version": "1.4",
6-
"qualifiers": {},
7-
"subpath": null,
8-
"primary_language": null,
9-
"description": null,
10-
"release_date": null,
11-
"parties": [
12-
{
13-
"type": "person",
14-
"role": "owner",
15-
"name": "Holger Krekel",
16-
"email": null,
17-
"url": null
18-
}
19-
],
20-
"keywords": [],
21-
"homepage_url": "https://bitbucket.org/hpk42/apipkg",
22-
"download_url": "https://pypi.python.org/packages/94/72/fd4f2e46ce7b0d388191c819ef691c8195fab09602bbf1a2f92aa5351444/apipkg-1.4-py2.py3-none-any.whl#md5=5644eb6aff3f19e13430251a820e987f",
23-
"size": null,
24-
"sha1": null,
25-
"md5": null,
26-
"sha256": null,
27-
"sha512": null,
28-
"bug_tracking_url": null,
29-
"code_view_url": null,
30-
"vcs_url": null,
31-
"copyright": "Copyright (c) 2009 holger krekel",
32-
"license_expression": "mit",
33-
"declared_license": "mit",
34-
"notice_text": null,
35-
"root_path": null,
36-
"dependencies": [],
37-
"contains_source_code": null,
38-
"source_packages": [],
39-
"extra_data": {
40-
"about_resource": "apipkg-1.4-py2.py3-none-any.whl"
41-
},
42-
"purl": "pkg:about/apipkg@1.4",
43-
"repository_homepage_url": null,
44-
"repository_download_url": null,
45-
"api_data_url": null
46-
}
1+
[
2+
{
3+
"type": "about",
4+
"namespace": null,
5+
"name": "apipkg",
6+
"version": "1.4",
7+
"qualifiers": {},
8+
"subpath": null,
9+
"primary_language": null,
10+
"description": null,
11+
"release_date": null,
12+
"parties": [
13+
{
14+
"type": "person",
15+
"role": "owner",
16+
"name": "Holger Krekel",
17+
"email": null,
18+
"url": null
19+
}
20+
],
21+
"keywords": [],
22+
"homepage_url": "https://bitbucket.org/hpk42/apipkg",
23+
"download_url": "https://pypi.python.org/packages/94/72/fd4f2e46ce7b0d388191c819ef691c8195fab09602bbf1a2f92aa5351444/apipkg-1.4-py2.py3-none-any.whl#md5=5644eb6aff3f19e13430251a820e987f",
24+
"size": null,
25+
"sha1": null,
26+
"md5": null,
27+
"sha256": null,
28+
"sha512": null,
29+
"bug_tracking_url": null,
30+
"code_view_url": null,
31+
"vcs_url": null,
32+
"copyright": "Copyright (c) 2009 holger krekel",
33+
"license_expression": "mit",
34+
"declared_license": "mit",
35+
"notice_text": null,
36+
"root_path": null,
37+
"dependencies": [],
38+
"contains_source_code": null,
39+
"source_packages": [],
40+
"extra_data": {
41+
"about_resource": "apipkg-1.4-py2.py3-none-any.whl"
42+
},
43+
"purl": "pkg:about/apipkg@1.4",
44+
"repository_homepage_url": null,
45+
"repository_download_url": null,
46+
"api_data_url": null
47+
}
48+
]
Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
1-
{
2-
"type": "about",
3-
"namespace": null,
4-
"name": "appdirs",
5-
"version": "1.4.3",
6-
"qualifiers": {},
7-
"subpath": null,
8-
"primary_language": null,
9-
"description": null,
10-
"release_date": null,
11-
"parties": [
12-
{
13-
"type": "person",
14-
"role": "owner",
15-
"name": "ActiveState",
16-
"email": null,
17-
"url": null
18-
}
19-
],
20-
"keywords": [],
21-
"homepage_url": "https://pypi.python.org/pypi/appdirs",
22-
"download_url": "https://pypi.python.org/packages/56/eb/810e700ed1349edde4cbdc1b2a21e28cdf115f9faf263f6bbf8447c1abf3/appdirs-1.4.3-py2.py3-none-any.whl#md5=9ed4b51c9611775c3078b3831072e153",
23-
"size": null,
24-
"sha1": null,
25-
"md5": null,
26-
"sha256": null,
27-
"sha512": null,
28-
"bug_tracking_url": null,
29-
"code_view_url": null,
30-
"vcs_url": null,
31-
"copyright": "Copyright (c) 2010 ActiveState Software Inc.",
32-
"license_expression": "mit",
33-
"declared_license": "mit",
34-
"notice_text": null,
35-
"root_path": null,
36-
"dependencies": [],
37-
"contains_source_code": null,
38-
"source_packages": [],
39-
"extra_data": {
40-
"about_resource": "appdirs-1.4.3-py2.py3-none-any.whl"
41-
},
42-
"purl": "pkg:about/appdirs@1.4.3",
43-
"repository_homepage_url": null,
44-
"repository_download_url": null,
45-
"api_data_url": null
46-
}
1+
[
2+
{
3+
"type": "about",
4+
"namespace": null,
5+
"name": "appdirs",
6+
"version": "1.4.3",
7+
"qualifiers": {},
8+
"subpath": null,
9+
"primary_language": null,
10+
"description": null,
11+
"release_date": null,
12+
"parties": [
13+
{
14+
"type": "person",
15+
"role": "owner",
16+
"name": "ActiveState",
17+
"email": null,
18+
"url": null
19+
}
20+
],
21+
"keywords": [],
22+
"homepage_url": "https://pypi.python.org/pypi/appdirs",
23+
"download_url": "https://pypi.python.org/packages/56/eb/810e700ed1349edde4cbdc1b2a21e28cdf115f9faf263f6bbf8447c1abf3/appdirs-1.4.3-py2.py3-none-any.whl#md5=9ed4b51c9611775c3078b3831072e153",
24+
"size": null,
25+
"sha1": null,
26+
"md5": null,
27+
"sha256": null,
28+
"sha512": null,
29+
"bug_tracking_url": null,
30+
"code_view_url": null,
31+
"vcs_url": null,
32+
"copyright": "Copyright (c) 2010 ActiveState Software Inc.",
33+
"license_expression": "mit",
34+
"declared_license": "mit",
35+
"notice_text": null,
36+
"root_path": null,
37+
"dependencies": [],
38+
"contains_source_code": null,
39+
"source_packages": [],
40+
"extra_data": {
41+
"about_resource": "appdirs-1.4.3-py2.py3-none-any.whl"
42+
},
43+
"purl": "pkg:about/appdirs@1.4.3",
44+
"repository_homepage_url": null,
45+
"repository_download_url": null,
46+
"api_data_url": null
47+
}
48+
]

tests/packagedcode/data/plugin/help.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Package: METADATA.bzl
55

66
--------------------------------------------
77
Package: about
8-
class: packagedcode.about:AboutPackage
8+
class: packagedcode.about:Aboutfile
99
file_patterns: *.ABOUT
10+
extensions: .ABOUT
1011

1112
--------------------------------------------
1213
Package: android

tests/packagedcode/test_about.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
class TestAbout(PackageTester):
1818
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
1919

20+
def test_can_detect_aboutfile(self):
21+
test_file = self.get_test_loc('about/aboutfiles/apipkg.ABOUT')
22+
assert about.Aboutfile.is_manifest(test_file)
23+
2024
def test_parse_about_file_home_url(self):
2125
test_file = self.get_test_loc('about/aboutfiles/apipkg.ABOUT')
22-
package = about.parse(test_file)
26+
package = about.Aboutfile.recognize(test_file)
2327
expected_loc = self.get_test_loc('about/apipkg.ABOUT-expected')
24-
self.check_package(package, expected_loc, regen=False)
28+
self.check_packages(package, expected_loc, regen=False)
2529

2630
def test_parse_about_file_homepage_url(self):
2731
test_file = self.get_test_loc('about/aboutfiles/appdirs.ABOUT')
28-
package = about.parse(test_file)
32+
package = about.Aboutfile.recognize(test_file)
2933
expected_loc = self.get_test_loc('about/appdirs.ABOUT-expected')
30-
self.check_package(package, expected_loc, regen=False)
34+
self.check_packages(package, expected_loc, regen=False)

0 commit comments

Comments
 (0)