Skip to content

Commit

Permalink
Add ignored_resources attribute in ABOUT file
Browse files Browse the repository at this point in the history
Reference: #527
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Jul 13, 2023
1 parent e9d0af3 commit df76984
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/attributecode/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,22 @@ def _validate(self, *args, **kwargs):
return errors


class IgnoredResourcesField(PathField):
"""
Special field for ignored_resources. self.ignored_paths contains a list of
path patterns (glob patterns) which are not part of the summarization provided
by the ABOUT file.
"""

def __init__(self, *args, ** kwargs):
super(AboutResourceField, self).__init__(*args, ** kwargs)
self.resolved_paths = []

def _validate(self, *args, **kwargs):
errors = super(AboutResourceField, self)._validate(*args, ** kwargs)
return errors


class FileTextField(PathField):
"""
A path field pointing to one or more text files such as license files.
Expand Down Expand Up @@ -764,6 +780,7 @@ def set_standard_fields(self):
"""
self.fields = dict([
('about_resource', AboutResourceField(required=True)),
('ignored_resources', AboutResourceField()),
('name', SingleLineField(required=True)),
('version', SingleLineField()),

Expand Down
11 changes: 11 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,17 @@ def test_About_with_existing_about_resource_has_no_error(self):
# this means we have a location
self.assertNotEqual([], result)

def test_About_loads_ignored_resources_field(self):
# fields in this file are not in the standard order
test_file = get_test_loc('test_model/parse/with_ignored_resources.ABOUT')
a = model.About(test_file)
#assert [] == a.errors

expected = ['about_resource', 'ignored_resources', 'name']
result = [f.name for f in a.all_fields() if f.present]
assert expected == result


def test_About_has_errors_when_about_resource_is_missing(self):
test_file = get_test_loc('test_gen/parser_tests/.ABOUT')
a = model.About(test_file)
Expand Down
5 changes: 5 additions & 0 deletions tests/testdata/test_model/parse/with_ignored_resources.ABOUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: elasticsearch-sidecar
about_resource: elasticsearch-sidecar
ignored_resources:
- elasticsearch-sidecar/plugins/
- elasticsearch-sidecar/logs/

0 comments on commit df76984

Please sign in to comment.