Skip to content

Commit 3bcfdfb

Browse files
authored
Merge pull request #3397 from nexB/3396-update-get-license-detections-and-expression
3396 update get license detections and expression
2 parents fef2408 + e833792 commit 3bcfdfb

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ testing =
136136
pytest-rerunfailures
137137

138138
docs =
139-
Sphinx >= 4.3.0
139+
Sphinx == 5.3.0
140140
sphinx_rtd_theme >= 0.5.1
141141
docutils < 0.17
142142
doc8

src/packagedcode/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,16 @@ def get_license_detections_and_expression(self):
869869
if not self.extracted_license_statement:
870870
return [], None
871871

872-
return get_license_detections_and_expression(
873-
extracted_license_statement=self.extracted_license_statement,
872+
if self.datasource_id:
874873
default_relation_license=get_default_relation_license(
875874
datasource_id=self.datasource_id,
876-
),
875+
)
876+
else:
877+
default_relation_license = 'AND'
878+
879+
return get_license_detections_and_expression(
880+
extracted_license_statement=self.extracted_license_statement,
881+
default_relation_license=default_relation_license
877882
)
878883

879884

tests/packagedcode/test_package_models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,20 @@ def test_package_adder(package_uid, resource, codebase):
225225
for package_uid in for_packages:
226226
normalized_package_uid = purl_with_fake_uuid(package_uid)
227227
assert normalized_package_uid == test_package_uid
228+
229+
def test_create_package_not_handled_by_packagedcode(self):
230+
extracted_license_statement = [
231+
'gpl',
232+
'GNU General Public License version 2.0 (GPLv2)',
233+
]
234+
package = PackageData(
235+
type='sourceforge',
236+
name='openstunts',
237+
copyright='Copyright (c) openstunts project',
238+
extracted_license_statement=extracted_license_statement,
239+
)
240+
# Test generated fields
241+
assert package.purl == 'pkg:sourceforge/openstunts'
242+
assert package.holder == 'openstunts project'
243+
assert package.declared_license_expression == 'gpl-1.0-plus AND gpl-2.0'
244+
assert package.declared_license_expression_spdx == 'GPL-1.0-or-later AND GPL-2.0-only'

0 commit comments

Comments
 (0)