Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def read(*names, **kwargs):
'click',
'scancode-toolkit >= 3.0',
'unicodecsv',
'license-expression==0.99;python_version=="2.7"',
'license-expression==1.2;python_version=="3.6"',
],

entry_points={
Expand Down
10 changes: 10 additions & 0 deletions src/deltacode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from collections import OrderedDict

import json
from license_expression import Licensing, LicenseSymbol


class Scan(object):
Expand Down Expand Up @@ -252,6 +253,15 @@ def __init__(self, dictionary={}):
self.short_name = dictionary.get('short_name')
self.category = dictionary.get('category')
self.owner = dictionary.get('owner')
self.simplify_expression()

def simplify_expression(self):
licensing = Licensing()
try:
short_name = licensing.parse(self.short_name)
self.short_name = str(short_name.simplify())
except:
pass

def to_dict(self):
"""
Expand Down
16 changes: 8 additions & 8 deletions tests/test_deltacode.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def test_score_copyright_and_license_info_added(self):
OrderedDict([
('key', 'gpl-1.0-plus'),
('score', 20.0),
('short_name', 'GPL 1.0 or later'),
('short_name', 'GPL 1.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def test_score_copyright_and_license_info_removed(self):
OrderedDict([
('key', 'gpl-1.0-plus'),
('score', 20.0),
('short_name', 'GPL 1.0 or later'),
('short_name', 'GPL 1.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def test_score_copyright_info_added_license_info_removed(self):
OrderedDict([
('key', 'gpl-3.0-plus'),
('score', 100.0),
('short_name', 'GPL 3.0 or later'),
('short_name', 'GPL 3.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand Down Expand Up @@ -1110,7 +1110,7 @@ def test_score_license_info_added_copyright_info_removed(self):
OrderedDict([
('key', 'gpl-3.0-plus'),
('score', 100.0),
('short_name', 'GPL 3.0 or later'),
('short_name', 'GPL 3.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand Down Expand Up @@ -1156,7 +1156,7 @@ def test_score_copyright_change_no_license_change(self):
OrderedDict([
('key', 'gpl-3.0-plus'),
('score', 100.0),
('short_name', 'GPL 3.0 or later'),
('short_name', 'GPL 3.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand All @@ -1165,7 +1165,7 @@ def test_score_copyright_change_no_license_change(self):
OrderedDict([
('key', 'gpl-3.0-plus'),
('score', 100.0),
('short_name', 'GPL 3.0 or later'),
('short_name', 'GPL 3.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand Down Expand Up @@ -1209,7 +1209,7 @@ def test_score_license_change_no_copyright_change(self):
OrderedDict([
('key', 'gpl-3.0-plus'),
('score', 100.0),
('short_name', 'GPL 3.0 or later'),
('short_name', 'GPL 3.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand All @@ -1218,7 +1218,7 @@ def test_score_license_change_no_copyright_change(self):
OrderedDict([
('key', 'gpl-1.0-plus'),
('score', 20.0),
('short_name', 'GPL 1.0 or later'),
('short_name', 'GPL 1.0 OR later'),
('category', 'Copyleft'),
('owner', "Free Software Foundation (FSF)")
])
Expand Down
81 changes: 81 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import pytest

from click.testing import CliRunner
from collections import OrderedDict

from commoncode.testcase import FileBasedTesting
from deltacode import DeltaCode
Expand Down Expand Up @@ -406,6 +407,86 @@ def test_License_to_dict_simple(self):
with pytest.raises(AttributeError):
assert result.spdx_license_key == "Apache-2.0"

def test_Dual_Licensing1(self):
data = {
"key": "classpath-exception-2.0",
"score": 55.0,
"name": "Classpath exception to GPL 2.0 or later",
"short_name": "Classpath exception to GPL 2.0 or later",
"category": "Copyleft Limited",
"is_exception": "true",
"owner": "Free Software Foundation (FSF)",
"homepage_url": "http://www.gnu.org/software/classpath/",
"text_url": "http://www.gnu.org/software/classpath/license.html",
"reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:classpath-exception-2.0",
"spdx_license_key": "Classpath-exception-2.0",
"spdx_url": "https://spdx.org/licenses/Classpath-exception-2.0",
"start_line": 1,
"end_line": 2,
"matched_rule": {
"identifier": "gpl-2.0_with_classpath-exception-2.0_8.RULE",
"license_expression": "gpl-2.0 WITH classpath-exception-2.0",
"licenses": [
"gpl-2.0",
"classpath-exception-2.0"
],
"is_license_text": "false",
"is_license_notice": "false",
"is_license_reference": "true",
"is_license_tag": "false",
"matcher": "2-aho",
"rule_length": 10,
"matched_length": 10,
"match_coverage": 100.0,
"rule_relevance": 55
}
}

expected = {
"key": "classpath-exception-2.0",
"score": 55.0,
"short_name": "Classpath exception to GPL 2.0 OR later",
"category": "Copyleft Limited",
"owner": "Free Software Foundation (FSF)"

}

result = models.License(data).to_dict()
assert result == expected

def test_Dual_Licensing2(self):
data = {
"key": "GPL-2.0 or LGPL-2.1 and mit",
"score": 80.0,
"short_name": "GPL-2.0 or LGPL-2.1 and mit",
"category": "Permissive",
"owner": "Apache Software Foundation",
"homepage_url": "http://www.apache.org/licenses/",
"text_url": "http://www.apache.org/licenses/LICENSE-2.0",
"reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0",
"spdx_license_key": "Apache-2.0",
"spdx_url": "https://spdx.org/licenses/Apache-2.0",
"start_line": 3,
"end_line": 3,
"matched_rule": {
"identifier": "apache-2.0_57.RULE",
"license_choice": False,
"licenses": [
"apache-2.0"
]
}
}

expected = {
"key": "GPL-2.0 or LGPL-2.1 and mit",
"score": 55.0,
"short_name": "GPL-2.0 or LGPL-2.1 and mit",
"category": "Copyleft Limited",
"owner": "Free Software Foundation (FSF)"
}
results = models.License(data).to_dict()
return results == expected

def test_License_to_dict_empty(self):
result = models.License().to_dict()

Expand Down
Binary file added thirdparty/boolean.py-3.7-py2.py3-none-any.whl
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions thirdparty/license_expression-1.2-py2.py3-none-any.whl.ABOUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
about_resource: license_expression-0.99-py2.py3-none-any.whl
attribute: true
checksum_md5: cff177fd902ec3ee425fc2db26974aaa
checksum_sha1: 8d89733bf0012122d557b1b8a6c79a70fa742c46
contact: http://www.nexb.com/contactus.html
copyright: Copyright (c) 2017 nexB Inc. and others.
description: Utility library to parse, normalize and compare License expressions for
Python using a boolean logic engine. For expressions using SPDX or any other license
id scheme.
download_url: https://files.pythonhosted.org/packages/8a/8e/f9786e4f61f5626d34e9a826790035817ff8c6b8100f0bd019a5eed00631/license_expression-0.99-py2.py3-none-any.whl
homepage_url: https://github.com/nexB/license-expression
license_expression: apache-2.0
license_file: apache-2.0.LICENSE
name: license-expression
notice_file: license_expression-0.99-py2.py3-none-any.whl.NOTICE
notice_url: https://github.com/nexB/license-expression/blob/master/NOTICE
owner: nexB
owner_url: http://www.nexb.com/
version: '1.2'
26 changes: 26 additions & 0 deletions thirdparty/license_expression-1.2-py2.py3-none-any.whl.NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Software license
================

license-expression is a free software tool from nexB Inc. and others.
Visit https://github.com/nexB/license-expression for support and download.

Copyright (c) 2016 nexB Inc. and others. All rights reserved.
http://nexb.com and http://aboutcode.org

This software is licensed under the Apache License version 2.0.

You may not use this software except in compliance with the License.
You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.


Third-party software licenses
=============================

license-expression embeds third-party free and open source software packages under
various licenses. The origin and license of these packages is documented by .ABOUT
files. The corresponding source code for pre-compiled third-party software is
available in the thirdparty directory.