Skip to content

Commit

Permalink
Merge pull request #2875 from nexB/2861-license-clarity-update
Browse files Browse the repository at this point in the history
Improve license clarity scoring
  • Loading branch information
pombredanne authored Mar 9, 2022
2 parents e080f83 + f998e21 commit 86c7db5
Show file tree
Hide file tree
Showing 66 changed files with 2,929 additions and 3,562 deletions.
202 changes: 131 additions & 71 deletions CHANGELOG.rst

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions src/summarycode/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def process_codebase(self, codebase, classify, **kwargs):
has_package_data = hasattr(codebase.root, 'package_data')
if not has_package_data:
# FIXME: this is not correct... we may still have cases where this
# is wrong: e.g. a META-INF directory and we may not have a package
# is wrong: e.g. a META-INF directory and we may not have a package
return


Expand Down Expand Up @@ -286,7 +286,7 @@ def process_codebase(self, codebase, classify, **kwargs):
'/setup.cfg': 'pypi',
'/setup.py': 'pypi',
'/PKG-INFO': 'pypi',
'/pyproject.toml': 'pypi',
'/pyproject.toml': 'pypi',
'.spec': 'rpm',
'/cargo.toml': 'rust',
'.spdx': 'spdx',
Expand All @@ -310,18 +310,32 @@ def process_codebase(self, codebase, classify, **kwargs):
)


def check_resource_name_start_and_end(resource, STARTS_ENDS):
"""
Return True if `resource.name` or `resource.base_name` begins or ends with
an element of `STARTS_ENDS`
"""
name = resource.name.lower()
base_name = resource.base_name.lower()
return (
name.startswith(STARTS_ENDS)
or name.endswith(STARTS_ENDS)
or base_name.startswith(STARTS_ENDS)
or base_name.endswith(STARTS_ENDS)
)


def set_classification_flags(resource,
_LEGAL=LEGAL_STARTS_ENDS,
_MANIF=MANIFEST_ENDS,
_README=README_STARTS_ENDS):
"""
Set classification flags on the `resource` Resource
"""
name = resource.name.lower()
path = resource.path.lower()

resource.is_legal = is_legal = name.startswith(_LEGAL) or name.endswith(_LEGAL)
resource.is_readme = is_readme = name.startswith(_README) or name.endswith(_README)
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_manifest = is_manifest = path.endswith(_MANIF)
resource.is_key_file = (resource.is_top_level
and (is_readme or is_legal or is_manifest))
Expand Down
Loading

0 comments on commit 86c7db5

Please sign in to comment.