Skip to content

Commit

Permalink
Update cpan package building functions #74
Browse files Browse the repository at this point in the history
    * Update test expectations

Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed May 11, 2023
1 parent bc66f39 commit dfb7c2b
Show file tree
Hide file tree
Showing 7 changed files with 2,545 additions and 194 deletions.
19 changes: 9 additions & 10 deletions minecode/mappers/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ def build_packages_from_release_json(metadata, uri=None):
if not name:
continue

extracted_license_statement = [l for l in release.get('license', []) if l and l.strip()]

common_data = dict(
type='cpan',
name=name,
description=release.get('abstract'),
version=release.get('version'),
download_url=release.get('download_url'),
declared_license='\n'.join([l for l in release.get('license', []) if l and l.strip()]),
extracted_license_statement=extracted_license_statement,
# the date format passing is like:
# "2014-04-20T21:30:13"
release_date=parse_date(release.get('date'))
Expand All @@ -80,9 +82,9 @@ def build_packages_from_release_json(metadata, uri=None):
# like perl_5. The license here under resources section is the
# url of license for example: http://dev.perl.org/licenses/ So
# it's useful to collect both information...
license_url = '\n'.join([l for l in resources.get('license', []) if l and l.strip()])
license_url = [l for l in resources.get('license', []) if l and l.strip()]
if license_url:
common_data['declared_license'] = '\n'.join([common_data['declared_license'], license_url])
common_data['extracted_license_statement'].extend(license_url)

vcs_tool, vcs_repo = get_vcs_repo1(resources)
if vcs_tool and vcs_repo:
Expand Down Expand Up @@ -151,16 +153,13 @@ def build_packages_from_metafile(metadata, uri=None, purl=None):
content = saneyaml.load(metadata)

licenses_content = content.get('license')
asserted_licenses = []
extracted_license_statement = []
if licenses_content:
if isinstance(licenses_content, (list,)):
for lic in licenses_content:
asserted_licenses.append(lic)
extracted_license_statement.append(lic)
else:
asserted_licenses.append(licenses_content)
declared_license = None
if asserted_licenses:
declared_license = '\n'.join(asserted_licenses)
extracted_license_statement.append(licenses_content)

keywords_content = content.get('keywords', [])

Expand All @@ -179,7 +178,7 @@ def build_packages_from_metafile(metadata, uri=None, purl=None):
description=content.get('abstract', name),
version=content.get('version'),
download_url=download_url,
declared_license=declared_license,
extracted_license_statement=extracted_license_statement,
vcs_url=vcs_repo,
keywords=keywords_content,
)
Expand Down
30 changes: 28 additions & 2 deletions minecode/tests/testfiles/cpan/expected_json_cpanmapper.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,34 @@
"code_view_url":null,
"vcs_url":"git+git://github.com/Abigail/Regexp--Common.git",
"copyright":null,
"license_expression":null,
"declared_license":"mit",
"holder":null,
"declared_license_expression":"mit",
"declared_license_expression_spdx":"MIT",
"license_detections":[
{
"license_expression":"mit",
"matches":[
{
"score":100.0,
"start_line":1,
"end_line":1,
"matched_length":1,
"match_coverage":100.0,
"matcher":"1-spdx-id",
"license_expression":"mit",
"rule_identifier":"spdx-license-identifier-mit-1b937028f397e2c5fe4eb6a0abd781ab80f9eeff",
"rule_relevance":100,
"rule_url":null,
"matched_text":"mit"
}
],
"identifier":"mit-704ced38-ea60-e53b-6c20-390fe781b1c3"
}
],
"other_license_expression":null,
"other_license_expression_spdx":null,
"other_license_detections":[],
"extracted_license_statement":"['mit']",
"notice_text":null,
"source_packages":[],
"file_references":[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
"code_view_url":null,
"vcs_url":null,
"copyright":null,
"license_expression":null,
"declared_license":null,
"holder":null,
"declared_license_expression":null,
"declared_license_expression_spdx":null,
"license_detections":[],
"other_license_expression":null,
"other_license_expression_spdx":null,
"other_license_detections":[],
"extracted_license_statement":null,
"notice_text":null,
"source_packages":[],
"file_references":[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
"code_view_url":null,
"vcs_url":"git+git://github.com/Abigail/test--regexp.git",
"copyright":null,
"license_expression":null,
"declared_license":null,
"holder":null,
"declared_license_expression":null,
"declared_license_expression_spdx":null,
"license_detections":[],
"other_license_expression":null,
"other_license_expression_spdx":null,
"other_license_detections":[],
"extracted_license_statement":null,
"notice_text":null,
"source_packages":[],
"file_references":[],
Expand Down
Loading

0 comments on commit dfb7c2b

Please sign in to comment.