Skip to content

Commit cc5572c

Browse files
committed
Fixed #395 Add support for package_url field
* Introduce a PackageUrlField class in model.py * Update pacakgeurl_python to version 0.9.0 * Update SPEC to v3.1.5 (support `package_url`)
1 parent 6a46119 commit cc5572c

11 files changed

+64
-17
lines changed

SPECIFICATION.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ABOUT File Specification v3.1.4
1+
ABOUT File Specification v3.1.5
22

33

44
Purpose
@@ -284,6 +284,8 @@ Optional Information fields
284284

285285
- changelog_file: Changelog file for the component.
286286

287+
- package_url: Package URL for the package.
288+
287289
- notes: Notes and comments about the component.
288290

289291

docs/CHANGELOG.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-xx-xx
2+
Release 5.1.0
3+
4+
* Add support for `package_url` #396
5+
16
2020-08-11
27
Release 5.0.0
38

@@ -16,7 +21,6 @@
1621
* Fix the missing `multi_sort` filter for Jinja2
1722
* Update help text for `--vartext`
1823

19-
2024
2019-10-17
2125
Release 4.0.1
2226

docs/UsingAboutCodetoDocumentYourSoftwareAssets.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ You should start with a software inventory of your codebase in spreadsheet forma
8585
<td>URL to the homepage for this component</td>
8686
<td>Optional</td>
8787
</tr>
88+
<tr>
89+
<td>package_url</td>
90+
<td>Package URL for this component (See https://github.com/package-url/purl-spec for SPEC)</td>
91+
<td>Optional</td>
92+
</tr>
8893
<tr>
8994
<td>notes</td>
9095
<td>notes text</td>
132 Bytes
Binary file not shown.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def read(*names, **kwargs):
7979

8080
'boolean.py >= 3.5, < 4.0',
8181
'license_expression >= 0.94',
82+
'packageurl_python >= 0.9.0',
8283
],
8384
extras_require={
8485
":python_version < '3.6'": ['backports.csv'],

src/attributecode/model.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
from attributecode.util import ungroup_licenses
7575
from attributecode.util import unique
7676

77+
from packageurl import PackageURL
78+
7779
genereated_tk_version = "# Generated with AboutCode Toolkit Version %s \n\n" % __version__
7880

7981
class Field(object):
@@ -351,6 +353,32 @@ def __eq__(self, other):
351353
if sval == oval:
352354
return True
353355

356+
class PackageUrlField(StringField):
357+
"""
358+
A Package URL field. The validated value is a purl.
359+
"""
360+
def _validate(self, *args, **kwargs):
361+
"""
362+
Check that Package URL is valid. Return a list of errors.
363+
"""
364+
errors = super(PackageUrlField, self)._validate(*args, ** kwargs)
365+
name = self.name
366+
val = self.value
367+
if not self.is_valid_purl(val):
368+
msg = (u'Field %(name)s: Invalid Package URL: %(val)s' % locals())
369+
errors.append(Error(WARNING, msg))
370+
return errors
371+
372+
@staticmethod
373+
def is_valid_purl(purl):
374+
"""
375+
Return True if a Package URL is valid.
376+
"""
377+
try:
378+
return bool(PackageURL.from_string(purl))
379+
except:
380+
return False
381+
354382
class UrlListField(ListField):
355383
"""
356384
A URL field. The validated value is a list of URLs.
@@ -717,6 +745,7 @@ def set_standard_fields(self):
717745
('download_url', UrlField()),
718746
('description', StringField()),
719747
('homepage_url', UrlField()),
748+
('package_url', PackageUrlField()),
720749
('notes', StringField()),
721750

722751
('license_expression', StringField()),

tests/test_model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def test_Field_init(self):
118118
model.BooleanField()
119119
model.PathField()
120120
model.FileTextField()
121+
model.PackageUrlField()
121122

122123
def test_empty_Field_has_no_content(self):
123124
field = model.Field()
@@ -167,6 +168,12 @@ def test_TextField_loads_file(self):
167168
expected = {'license.LICENSE': 'some license text'}
168169
assert expected == field.value
169170

171+
def test_PackageUrlField_is_valid_url(self):
172+
assert model.PackageUrlField.is_valid_purl('pkg:pypi/[email protected]')
173+
174+
def test_PackageUrlField_is_valid_url_no_version(self):
175+
assert model.PackageUrlField.is_valid_purl('pkg:pypi/saneyaml')
176+
170177
def test_UrlField_is_valid_url(self):
171178
assert model.UrlField.is_valid_url('http://www.google.com')
172179

-5.6 KB
Binary file not shown.

thirdparty/packageurl_python-0.7.0-py2.py3-none-any.whl.ABOUT

Lines changed: 0 additions & 15 deletions
This file was deleted.
15.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)