Skip to content

Commit c118f91

Browse files
committed
Check Resource basename when classifying #2861
* The classify plugin was determining the types of key files by checking the start or end of file names to see if they are a special type of file. However, the code checked the full filename with extension. This would cause us to not classify certain key files properly. Signed-off-by: Jono Yang <[email protected]>
1 parent a65472a commit c118f91

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/summarycode/classify.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def process_codebase(self, codebase, classify, **kwargs):
172172
has_package_manifests = hasattr(codebase.root, 'package_manifests')
173173
if not has_package_manifests:
174174
# FIXME: this is not correct... we may still have cases where this
175-
# is wrong: e.g. a META-INF directory and we may not have a package
175+
# is wrong: e.g. a META-INF directory and we may not have a package
176176
return
177177

178178

@@ -286,7 +286,7 @@ def process_codebase(self, codebase, classify, **kwargs):
286286
'/setup.cfg': 'pypi',
287287
'/setup.py': 'pypi',
288288
'/PKG-INFO': 'pypi',
289-
'/pyproject.toml': 'pypi',
289+
'/pyproject.toml': 'pypi',
290290
'.spec': 'rpm',
291291
'/cargo.toml': 'rust',
292292
'.spdx': 'spdx',
@@ -310,18 +310,32 @@ def process_codebase(self, codebase, classify, **kwargs):
310310
)
311311

312312

313+
def check_resource_name_start_and_end(resource, STARTS_ENDS):
314+
"""
315+
Return True if `resource.name` or `resource.base_name` begins or ends with
316+
an element of `STARTS_ENDS`
317+
"""
318+
name = resource.name.lower()
319+
base_name = resource.base_name.lower()
320+
return (
321+
name.startswith(STARTS_ENDS)
322+
or name.endswith(STARTS_ENDS)
323+
or base_name.startswith(STARTS_ENDS)
324+
or base_name.endswith(STARTS_ENDS)
325+
)
326+
327+
313328
def set_classification_flags(resource,
314329
_LEGAL=LEGAL_STARTS_ENDS,
315330
_MANIF=MANIFEST_ENDS,
316331
_README=README_STARTS_ENDS):
317332
"""
318333
Set classification flags on the `resource` Resource
319334
"""
320-
name = resource.name.lower()
321335
path = resource.path.lower()
322336

323-
resource.is_legal = is_legal = name.startswith(_LEGAL) or name.endswith(_LEGAL)
324-
resource.is_readme = is_readme = name.startswith(_README) or name.endswith(_README)
337+
resource.is_legal = is_legal = check_resource_name_start_and_end(resource, _LEGAL)
338+
resource.is_readme = is_readme = check_resource_name_start_and_end(resource, _README)
325339
resource.is_manifest = is_manifest = path.endswith(_MANIF)
326340
resource.is_key_file = (resource.is_top_level
327341
and (is_readme or is_legal or is_manifest))

tests/summarycode/data/classify/legal/mit-license.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)