Skip to content

Commit 9ae5653

Browse files
committed
Refine holder detection
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent b665ade commit 9ae5653

24 files changed

Lines changed: 238 additions & 264 deletions

src/packagedcode/models.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ class PackageData(IdentifiablePackageData):
609609
label='Copyright',
610610
help='Copyright statements for this package. Typically one per line.')
611611

612+
holder = String(
613+
label='Holder',
614+
help='Holders for this package. Typically one per line.')
615+
612616
declared_license_expression = String(
613617
label='license expression',
614618
help='The license expression for this package typically derived '
@@ -711,34 +715,45 @@ class PackageData(IdentifiablePackageData):
711715
repr=True,
712716
)
713717

714-
holder= String(
715-
label='Holder',
716-
help='Holder for this package. Typically one per line.')
717718

718719
def __attrs_post_init__(self, *args, **kwargs):
719720
self.populate_license_fields()
720721
self.populate_holder_field()
721722

722723
def populate_holder_field(self):
723-
if self.copyright:
724-
from cluecode.copyrights import CopyrightDetector
724+
if not self.copyright:
725+
return
725726

727+
from cluecode.copyrights import CopyrightDetector
728+
729+
numbered_lines = list(enumerate(self.copyright.split("\n"), start=1))
730+
detector = CopyrightDetector()
731+
holders = list(
732+
detector.detect(
733+
numbered_lines,
734+
include_copyrights=False,
735+
include_holders=True,
736+
include_authors=False,
737+
)
738+
)
739+
# If no holder detected, prefix each copyright statement with `Copyright`
740+
if not holders:
726741
numbered_lines = [
727-
(count, value) for count, value in enumerate(self.copyright.split("\n"), start=1)
742+
(count, f"Copyright {value}") for count, value in numbered_lines
728743
]
729-
detector = CopyrightDetector()
730-
holder_list = list(
744+
holders = list(
731745
detector.detect(
732746
numbered_lines,
733747
include_copyrights=False,
734748
include_holders=True,
735749
include_authors=False,
736750
)
737751
)
738-
if holder_list:
739-
self.holder = "\n".join(
740-
[holder_detection.holder for holder_detection in holder_list]
741-
)
752+
# If still no holder, then populate holder with copyright field
753+
self.holder = (
754+
"\n".join([holder_detection.holder for holder_detection in holders])
755+
or self.copyright
756+
)
742757

743758
def populate_license_fields(self):
744759
"""

tests/packagedcode/data/debian/copyright/debian-2019-11-15/main/a/asterisk/stable_copyright-detailed.expected.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ other_license_expression: gpl-2.0 AND gpl-2.0 AND gpl-2.0 AND fsf-free AND autoc
6565
AND brian-clapper AND lgpl-2.1 AND gpl-2.0 AND lgpl-2.0-plus AND mit-0 AND mit AND gpl-2.0
6666
AND gpl-2.0 AND gpl-2.0 AND gpl-1.0-plus
6767
other_license_expression_spdx: GPL-2.0-only AND GPL-2.0-only AND GPL-2.0-only AND FSFUL AND
68-
Autoconf-exception-generic AND GPL-2.0-or-later AND NTP AND GPL-2.0-only AND GPL-2.0-only
69-
AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only AND GPL-1.0-or-later AND LicenseRef-scancode-unknown
70-
AND BSD-4-Clause-UC AND GPL-2.0-only AND LicenseRef-scancode-free-unknown AND TU-Berlin-1.0
71-
AND BSD-3-Clause AND BSD-3-Clause AND BSD-4-Clause AND GPL-2.0-or-later AND LicenseRef-scancode-public-domain
72-
AND LicenseRef-scancode-unknown AND LicenseRef-scancode-public-domain AND GPL-2.0-only AND
73-
GPL-2.0-or-later AND LicenseRef-scancode-public-domain AND LicenseRef-scancode-other-permissive
68+
LicenseRef-scancode-autoconf-simple-exception-2.0 AND GPL-2.0-or-later AND NTP AND GPL-2.0-only
69+
AND GPL-2.0-only AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only AND GPL-1.0-or-later
70+
AND LicenseRef-scancode-unknown AND BSD-4-Clause-UC AND GPL-2.0-only AND LicenseRef-scancode-free-unknown
71+
AND TU-Berlin-1.0 AND BSD-3-Clause AND BSD-3-Clause AND BSD-4-Clause AND GPL-2.0-or-later
72+
AND LicenseRef-scancode-public-domain AND LicenseRef-scancode-unknown AND LicenseRef-scancode-public-domain
73+
AND GPL-2.0-only AND GPL-2.0-or-later AND LicenseRef-scancode-public-domain AND LicenseRef-scancode-other-permissive
7474
AND (MIT AND GPL-2.0-only) AND GPL-2.0-or-later AND GPL-2.0-or-later AND LicenseRef-scancode-other-permissive
7575
AND (BSD-4-Clause-UC AND ISC AND GPL-2.0-only) AND GPL-2.0-only AND BSD-4-Clause-UC AND Bison-exception-2.2
7676
AND GPL-3.0-or-later AND BSD-3-Clause AND GPL-2.0-only AND GPL-2.0-only AND GPL-1.0-or-later

tests/packagedcode/data/debian/copyright/debian-2019-11-15/main/c/clamav/stable_copyright-detailed.expected.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ other_license_expression: (gpl-2.0 AND gpl-2.0) AND gpl-2.0 AND (gpl-2.0 AND ope
5656
other_license_expression_spdx: (GPL-2.0-only AND GPL-2.0-only) AND GPL-2.0-only AND (GPL-2.0-only
5757
AND LicenseRef-scancode-openssl-exception-gpl-3.0-plus AND GPL-2.0-only) AND GPL-2.0-only
5858
AND (GPL-2.0-or-later AND GPL-2.0-or-later) AND GPL-2.0-only AND (GPL-2.0-or-later AND GPL-2.0-or-later)
59-
AND GPL-2.0-only AND (GPL-2.0-or-later AND Autoconf-exception-generic AND GPL-2.0-only) AND
60-
GPL-2.0-only AND (GPL-3.0-or-later WITH LicenseRef-scancode-autoconf-simple-exception AND
61-
GPL-3.0-only) AND GPL-3.0-only AND (GPL-2.0-or-later WITH Libtool-exception AND GPL-2.0-only)
59+
AND GPL-2.0-only AND (GPL-2.0-or-later AND LicenseRef-scancode-autoconf-simple-exception-2.0
60+
AND GPL-2.0-only) AND GPL-2.0-only AND (GPL-3.0-or-later WITH LicenseRef-scancode-autoconf-simple-exception
61+
AND GPL-3.0-only) AND GPL-3.0-only AND (GPL-2.0-or-later WITH Libtool-exception AND GPL-2.0-only)
6262
AND GPL-2.0-only AND (LGPL-2.0-or-later WITH Libtool-exception AND LGPL-2.0-or-later) AND
6363
LGPL-2.0-or-later AND (LGPL-2.1-only AND LGPL-2.1-only) AND ((LGPL-2.1-only AND LGPL-2.1-only)
6464
AND BSD-3-Clause) AND MIT AND (X11 AND LicenseRef-scancode-public-domain) AND MIT AND BSD-2-Clause

tests/packagedcode/data/debian/copyright/debian-2019-11-15/main/g/golang-1.11/stable_copyright-detailed.expected.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ other_license_expression_spdx: (BSD-3-Clause AND LicenseRef-scancode-google-pate
3434
AND MIT AND (BSD-3-Clause AND LicenseRef-scancode-google-patent-license-golang) AND (BSD-3-Clause
3535
AND LicenseRef-scancode-google-patent-license-golang) AND (BSD-3-Clause AND LicenseRef-scancode-google-patent-license-golang)
3636
AND BSD-2-Clause AND (BSD-3-Clause AND LicenseRef-scancode-google-patent-license-golang) AND
37-
(BSD-3-Clause AND LicenseRef-scancode-google-patent-license-golang) AND SunPro AND LicenseRef-scancode-mpeg-ssg
38-
AND LicenseRef-scancode-other-permissive AND (Apache-2.0 AND Apache-2.0) AND BSD-2-Clause-Views
39-
AND CC-BY-3.0 AND CC-BY-3.0 AND BSD-3-Clause AND (BSD-3-Clause AND LicenseRef-scancode-google-patent-license-golang)
37+
(BSD-3-Clause AND LicenseRef-scancode-google-patent-license-golang) AND LicenseRef-scancode-sunpro
38+
AND LicenseRef-scancode-mpeg-ssg AND LicenseRef-scancode-other-permissive AND (Apache-2.0
39+
AND Apache-2.0) AND BSD-2-Clause-Views AND CC-BY-3.0 AND CC-BY-3.0 AND BSD-3-Clause AND (BSD-3-Clause
40+
AND LicenseRef-scancode-google-patent-license-golang)
4041
license_detections: []
4142
other_license_detections:
4243
- license_expression: other-permissive

tests/packagedcode/data/debian/copyright/debian-2019-11-15/main/o/openldap/stable_copyright-detailed.expected.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ declared_license_expression: openldap-2.8 AND openldap-2.8 AND mit AND fsf-unlim
66
declared_license_expression_spdx: OLDAP-2.8 AND OLDAP-2.8 AND MIT AND FSFULLRWD AND Spencer-94
77
AND LicenseRef-scancode-ibm-dhcp AND LicenseRef-scancode-ietf AND ISC AND LicenseRef-scancode-other-permissive
88
AND LicenseRef-scancode-other-permissive AND NTP AND LicenseRef-scancode-other-permissive
9-
AND Spencer-94 AND OLDAP-2.8 AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND BSD-4-Clause-UC AND
10-
BSD-4-Clause-UC AND BSD-4.3RENO
9+
AND Spencer-94 AND OLDAP-2.8 AND LicenseRef-scancode-bsla AND BSD-4-Clause-UC AND BSD-4-Clause-UC
10+
AND BSD-4-Clause-UC AND LicenseRef-scancode-bsd-original-uc-1986
1111
other_license_expression:
1212
other_license_expression_spdx:
1313
license_detections:

0 commit comments

Comments
 (0)