Skip to content

Commit

Permalink
Add is_notice flag to the --classify option, issue aboutcode-org#3822
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Kumar <[email protected]>
  • Loading branch information
aayushkdev committed Feb 11, 2025
1 parent e795bc6 commit 49e93f0
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/summarycode/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def get_relative_path(root_path, path):
'readme',
)

NOTICE_STARTS_ENDS = (
"notice",
)

def check_resource_name_start_and_end(resource, STARTS_ENDS):
"""
Expand All @@ -111,6 +114,7 @@ def set_classification_flags(resource,
_LEGAL=LEGAL_STARTS_ENDS,
_MANIF=MANIFEST_ENDS,
_README=README_STARTS_ENDS,
_NOTICE=NOTICE_STARTS_ENDS,
):
"""
Set classification flags on the `resource` Resource
Expand All @@ -119,8 +123,9 @@ def set_classification_flags(resource,

resource.is_legal = is_legal = check_resource_name_start_and_end(resource, _LEGAL)
resource.is_readme = is_readme = check_resource_name_start_and_end(resource, _README)
resource.is_notice = is_notice = check_resource_name_start_and_end(resource, _NOTICE)
# FIXME: this will never be picked up as this is NOT available in a pre-scan plugin
has_package_data = bool(getattr(resource, 'package_data', False))
resource.is_manifest = is_manifest = path.endswith(_MANIF) or has_package_data
resource.is_key_file = (resource.is_top_level and (is_readme or is_legal or is_manifest))
resource.is_key_file = (resource.is_top_level and (is_readme or is_legal or is_manifest or is_notice))
return resource
5 changes: 4 additions & 1 deletion src/summarycode/classify_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ class FileClassifier(PostScanPlugin):

('is_key_file',
Boolean(help='True if this file is "top-level" file and either a '
'legal, readme or manifest file.')),
'legal, notice, readme or manifest file.')),

('is_notice',
Boolean(help='True if this file is likely a notice file')),

# ('is_doc',
# Boolean(help='True if this file is likely a documentation file.')),
Expand Down
12 changes: 11 additions & 1 deletion tests/summarycode/data/classify/cli.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 8,
"dirs_count": 1,
"size_count": 0,
Expand Down Expand Up @@ -53,6 +54,7 @@
"is_readme": true,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -82,6 +84,7 @@
"is_readme": true,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -111,6 +114,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -140,6 +144,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -169,6 +174,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 2,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -198,6 +204,7 @@
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -227,6 +234,7 @@
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -256,6 +264,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -285,10 +294,11 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
}
]
}
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
17 changes: 16 additions & 1 deletion tests/summarycode/data/classify/with_package_data.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 7,
"dirs_count": 7,
"size_count": 31701,
Expand Down Expand Up @@ -288,6 +289,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 5,
"dirs_count": 3,
"size_count": 27441,
Expand Down Expand Up @@ -321,6 +323,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -354,6 +357,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -437,6 +441,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -470,6 +475,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 2,
"dirs_count": 2,
"size_count": 15229,
Expand Down Expand Up @@ -503,6 +509,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 2,
"dirs_count": 1,
"size_count": 15229,
Expand Down Expand Up @@ -536,6 +543,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 2,
"dirs_count": 0,
"size_count": 15229,
Expand Down Expand Up @@ -614,6 +622,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -832,6 +841,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -865,6 +875,7 @@
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"is_notice": false,
"files_count": 2,
"dirs_count": 2,
"size_count": 4260,
Expand Down Expand Up @@ -898,6 +909,7 @@
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"is_notice": false,
"files_count": 2,
"dirs_count": 1,
"size_count": 4260,
Expand Down Expand Up @@ -931,6 +943,7 @@
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"is_notice": false,
"files_count": 2,
"dirs_count": 0,
"size_count": 4260,
Expand Down Expand Up @@ -964,6 +977,7 @@
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -997,10 +1011,11 @@
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"is_notice": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
}
]
}
}
11 changes: 11 additions & 0 deletions tests/summarycode/test_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ def test_set_classification_flags_is_package_data_file(self):
set_classification_flags(res)
assert res.is_manifest


def test_set_classification_flags_is_notice(self):
test_dir = self.get_test_loc('classify/notice')
codebase = Codebase(
test_dir, resource_attributes=FileClassifier.resource_attributes)
for res in codebase.walk():
if not res.is_file:
continue
set_classification_flags(res)
assert res.is_notice

def test_classify_cli_option(self):
test_dir = self.get_test_loc('classify/cli')
result_file = self.get_temp_file('json')
Expand Down

0 comments on commit 49e93f0

Please sign in to comment.