Skip to content

Commit

Permalink
Identify Creative Commons licenses by full name
Browse files Browse the repository at this point in the history
Also adds more internationalized Creative Commons variants
  • Loading branch information
rdipardo committed Aug 31, 2024
1 parent a543b3d commit bbf04c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
29 changes: 22 additions & 7 deletions rplugin/python3/cpywrite/spdx/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def license_text(self):
# full text of new licenses added since v3.11 are fetched from
# the HEAD of spdx/license-list-data; USE THEM AT YOUR OWN RISK
spdx_revision = '2e20899c0504ff6c0acfcc1b0994d7163ce46939' \
if not self.spdx_code in [
if not self.spdx_code.startswith('CC-BY') or self.spdx_code in [
'AdaCore-doc',
'ASWF-Digital-Assets-1.0',
'ASWF-Digital-Assets-1.1',
Expand All @@ -162,7 +162,6 @@ def license_text(self):
'BSD-3-Clause-No-Military-License',
'BSD-4-Clause-Shortened',
'C-UDA-1.0',
'CC-BY-SA-3.0-IGO',
'DRL-1.0',
'dtoa',
'FreeBSD-DOC',
Expand Down Expand Up @@ -243,18 +242,19 @@ def __str__(self):

if self.license_name:
name = self.license_name
full_name = search(r'[tT]he.+[lL]icense.*$', self.license_name)

if self.spdx_code.startswith('CC-BY') or in_pub_domain(self.spdx_code):
return template % name + '.'

full_name = search(r'[tT]he.+[lL]icense.*$', self.license_name)
if full_name:
name = ''.join(full_name.group().split()[1:])
if in_pub_domain(self.spdx_code):
return template % name + '.'

name = search(r'.+[lL]icense(.*[vV]ariant)?', name)
pretty_name = search(r'.+[lL]icense(.*[vV]ariant)?', name)
version = search(r'\d\.\d.*$', self.license_name)

if name:
return (template % name.group()) + \
return (template % pretty_name.group()) + \
(' Version ' + version.group() if version else '') + \
'.'

Expand Down Expand Up @@ -416,37 +416,52 @@ def _fetch_license(resource, spdx_id):
'CC-BY-1.0',
'CC-BY-2.0',
'CC-BY-2.5',
'CC-BY-2.5-AU',
'CC-BY-3.0',
'CC-BY-3.0-AT',
'CC-BY-3.0-AU',
'CC-BY-3.0-DE',
'CC-BY-3.0-IGO',
'CC-BY-3.0-NL',
'CC-BY-3.0-US',
'CC-BY-4.0',
'CC-BY-NC-1.0',
'CC-BY-NC-2.0',
'CC-BY-NC-2.5',
'CC-BY-NC-3.0',
'CC-BY-NC-3.0-DE',
'CC-BY-NC-4.0',
'CC-BY-NC-ND-1.0',
'CC-BY-NC-ND-2.0',
'CC-BY-NC-ND-2.5',
'CC-BY-NC-ND-3.0',
'CC-BY-NC-ND-3.0-DE',
'CC-BY-NC-ND-3.0-IGO',
'CC-BY-NC-ND-4.0',
'CC-BY-NC-SA-1.0',
'CC-BY-NC-SA-2.0',
'CC-BY-NC-SA-2.0-DE',
'CC-BY-NC-SA-2.0-FR',
'CC-BY-NC-SA-2.0-UK',
'CC-BY-NC-SA-2.5',
'CC-BY-NC-SA-3.0',
'CC-BY-NC-SA-3.0-DE',
'CC-BY-NC-SA-3.0-IGO',
'CC-BY-NC-SA-4.0',
'CC-BY-ND-1.0',
'CC-BY-ND-2.0',
'CC-BY-ND-2.5',
'CC-BY-ND-3.0',
'CC-BY-ND-3.0-DE',
'CC-BY-ND-4.0',
'CC-BY-SA-1.0',
'CC-BY-SA-2.0',
'CC-BY-SA-2.0-UK',
'CC-BY-SA-2.1-JP',
'CC-BY-SA-2.5',
'CC-BY-SA-3.0',
'CC-BY-SA-3.0-AT',
'CC-BY-SA-3.0-DE',
'CC-BY-SA-3.0-IGO',
'CC-BY-SA-4.0',
'CC-PDDC',
Expand Down
11 changes: 11 additions & 0 deletions test/vader/test_machine_readable_tags.vader
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,14 @@ Execute(Use :CPYwriteToggleStyle to switch off machine readable output);

Then(Assert that :CPYwriteToggleStyle switches off machine readable output);
AssertEqual 0, g:cpywrite#machine_readable

Execute(Prepend an Intl. Creative Commons license to a Cppfront header);
new! cc.h2
b cc.h2
CPYwrite CC-BY-SA-2.1-JP

Then(Cppfront header fully identifies the CC-BY-SA-2.1-JP);
AssertEqual ' * cc.h2', getline(2)
AssertEqual 2, len(getline(3)), 'Allow no trailing spaces'
AssertEqual 'Creative Commons Attribution Share Alike 2.1 Japan.', getline(6)[38:], 'Fully identify Creative Commons licenses'
AssertEqual ' */', getline(7)

0 comments on commit bbf04c3

Please sign in to comment.