From df7698437722c45fad43384bad2cae69169d0905 Mon Sep 17 00:00:00 2001 From: Ayan Sinha Mahapatra Date: Fri, 14 Jul 2023 05:01:28 +0530 Subject: [PATCH] Add `ignored_resources` attribute in ABOUT file Reference: https://github.com/nexB/aboutcode-toolkit/issues/527 Signed-off-by: Ayan Sinha Mahapatra --- src/attributecode/model.py | 17 +++++++++++++++++ tests/test_model.py | 11 +++++++++++ .../parse/with_ignored_resources.ABOUT | 5 +++++ 3 files changed, 33 insertions(+) create mode 100644 tests/testdata/test_model/parse/with_ignored_resources.ABOUT diff --git a/src/attributecode/model.py b/src/attributecode/model.py index f49c990d..5dbbf261 100644 --- a/src/attributecode/model.py +++ b/src/attributecode/model.py @@ -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. @@ -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()), diff --git a/tests/test_model.py b/tests/test_model.py index 60b1ab4b..c51213fe 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -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) diff --git a/tests/testdata/test_model/parse/with_ignored_resources.ABOUT b/tests/testdata/test_model/parse/with_ignored_resources.ABOUT new file mode 100644 index 00000000..c71bb338 --- /dev/null +++ b/tests/testdata/test_model/parse/with_ignored_resources.ABOUT @@ -0,0 +1,5 @@ +name: elasticsearch-sidecar +about_resource: elasticsearch-sidecar +ignored_resources: + - elasticsearch-sidecar/plugins/ + - elasticsearch-sidecar/logs/