Skip to content

Commit 0d294bf

Browse files
authored
Merge pull request #3197 from nexB/fix-license-dump
Update license db generation
2 parents 0aa964e + 567e9ff commit 0d294bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+63
-1543
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ License detection:
175175

176176
- See https://github.com/nexB/scancode-toolkit/issues/3049
177177

178-
- There is a new ``--get-license-data`` scancode command line option to export
178+
- There is a new console script ``scancode-license-data`` to export
179179
license data in JSON, YAML and HTML, with indexes and a static website for use
180180
in the licensedb web site. This becomes the API way to getr scancode license
181181
data.

setup-mini.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ packages =
147147
console_scripts =
148148
scancode = scancode.cli:scancode
149149
scancode-reindex-licenses = licensedcode.reindex:reindex_licenses
150+
scancode-license-data = licensedcode.license_db:dump_scancode_license_data
150151

151152
# These are configurations for ScanCode plugins as setuptools entry points.
152153
# Each plugin entry hast this form:

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ packages =
147147
console_scripts =
148148
scancode = scancode.cli:scancode
149149
scancode-reindex-licenses = licensedcode.reindex:reindex_licenses
150+
scancode-license-data = licensedcode.license_db:dump_scancode_license_data
150151

151152
# These are configurations for ScanCode plugins as setuptools entry points.
152153
# Each plugin entry hast this form:

src/licensedcode/cache.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ def load_or_build(
182182
# TODO: handle unable to lock in a nicer way
183183
raise
184184

185+
@property
186+
def has_additional_licenses(self):
187+
cache = get_cache()
188+
if cache.additional_license_directory or cache.additional_license_plugins:
189+
return True
190+
185191

186192
def build_index(
187193
licenses_db=None,

src/licensedcode/license_db.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
from os.path import join
3232
from distutils.dir_util import copy_tree
3333

34+
import click
3435
import saneyaml
36+
37+
from commoncode.cliutils import MISC_GROUP
38+
from commoncode.cliutils import PluggableCommandLineOption
3539
from jinja2 import Environment, FileSystemLoader
3640
from licensedcode.models import load_licenses
3741
from licensedcode.models import licenses_data_dir
@@ -126,13 +130,16 @@ def generate_details(output_path, environment, licenses, test=False):
126130
127131
``test`` is to generate a stable output for testing only
128132
"""
133+
from licensedcode.cache import get_cache
134+
include_builtin = get_cache().has_additional_licenses
135+
129136
if test:
130137
base_context_mapping = base_context_test
131138
else:
132139
base_context_mapping = base_context
133140
license_details_template = environment.get_template("license_details.html")
134141
for lic in licenses.values():
135-
license_data = lic.to_dict(include_text=True)
142+
license_data = lic.to_dict(include_text=False, include_builtin=include_builtin)
136143
html = license_details_template.render(
137144
**base_context_mapping,
138145
license=lic,
@@ -200,19 +207,40 @@ def generate(
200207
return count
201208

202209

203-
def dump_license_data(ctx, param, value):
210+
def scancode_license_data(path):
204211
"""
205-
Dump license data from scancode licenses to the directory ``value`` passed
212+
Dump license data from scancode licenses to the directory ``path`` passed
206213
in from command line.
207214
208215
Dumps data in JSON, YAML and HTML formats and also dumps the .LICENSE file
209216
with the license text and the data as YAML frontmatter.
210217
"""
211-
if not value or ctx.resilient_parsing:
212-
return
213-
214-
import click
215-
click.secho(f'Dumping license data to: {value}', err=True)
216-
count = generate(build_location=value)
218+
click.secho(f'Dumping license data to: {path}', err=True)
219+
count = generate(build_location=path)
217220
click.secho(f'Done dumping #{count} licenses.', err=True)
218-
ctx.exit(0)
221+
222+
223+
@click.command(name='scancode-license-data')
224+
@click.option(
225+
'--path',
226+
type=click.Path(exists=False, writable=True, file_okay=False, resolve_path=True, path_type=str),
227+
metavar='DIR',
228+
help='Dump the license data in this directory in the LicenseDB format and exit. '
229+
'Creates the directory if it does not exist. ',
230+
help_group=MISC_GROUP,
231+
cls=PluggableCommandLineOption,
232+
)
233+
@click.help_option('-h', '--help')
234+
def dump_scancode_license_data(
235+
path,
236+
*args,
237+
**kwargs,
238+
):
239+
"""
240+
Dump scancode license data in various formats, and the licenseDB static website at `path`.
241+
"""
242+
scancode_license_data(path=path)
243+
244+
245+
if __name__ == '__main__':
246+
dump_scancode_license_data()

src/licensedcode/plugin_license.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
from functools import partial
1313

1414
import attr
15-
import click
1615
from commoncode.cliutils import PluggableCommandLineOption
1716
from commoncode.cliutils import SCAN_GROUP
1817
from commoncode.cliutils import SCAN_OPTIONS_GROUP
19-
from commoncode.cliutils import MISC_GROUP
2018
from plugincode.scan import ScanPlugin
2119
from plugincode.scan import scan_impl
2220

@@ -33,7 +31,6 @@
3331
from licensedcode.detection import LicenseDetectionFromResult
3432
from licensedcode.detection import LicenseMatchFromResult
3533
from licensedcode.detection import UniqueDetection
36-
from licensedcode.license_db import dump_license_data
3734
from packagedcode.utils import combine_expressions
3835
from scancode.api import SCANCODE_LICENSEDB_URL
3936

@@ -121,19 +118,7 @@ class LicenseScanner(ScanPlugin):
121118
required_options=['license'],
122119
help='[EXPERIMENTAL] Detect unknown licenses. ',
123120
help_group=SCAN_OPTIONS_GROUP,
124-
),
125-
126-
# TODO: consider creating a separate comamnd line option exe instead
127-
PluggableCommandLineOption(
128-
('--dump-license-data',),
129-
type=click.Path(exists=False, readable=True, file_okay=False, resolve_path=True, path_type=str),
130-
metavar='DIR',
131-
callback=dump_license_data,
132-
help='Dump the license data in this directory in the LicenseDB format and exit. '
133-
'Creates the directory if it does not exist. ',
134-
help_group=MISC_GROUP,
135-
is_eager=True,
136-
),
121+
)
137122
]
138123

139124
def is_enabled(self, license, **kwargs): # NOQA
@@ -176,20 +161,17 @@ def process_codebase(self, codebase, **kwargs):
176161
cche = cache.get_cache()
177162

178163
cle = codebase.get_or_create_current_header()
179-
has_additional_licenses = False
180164

181165
if cche.additional_license_directory:
182166
cle.extra_data['additional_license_directory'] = cche.additional_license_directory
183-
has_additional_licenses = True
184167

185168
if cche.additional_license_plugins:
186169
cle.extra_data['additional_license_plugins'] = cche.additional_license_plugins
187-
has_additional_licenses = True
188170

189-
if TRACE and has_additional_licenses:
171+
if TRACE and cche.has_additional_licenses:
190172
logger_debug(
191173
f'add_referenced_filenames_license_matches: additional_licenses',
192-
f'has_additional_licenses: {has_additional_licenses}\n',
174+
f'has_additional_licenses: {cche.has_additional_licenses}\n',
193175
f'additional_license_directory: {cche.additional_license_directory}\n',
194176
f'additional_license_plugins : {cche.additional_license_plugins}'
195177
)

src/licensedcode/templates/footer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
</p>
99
<p>Designed and built by <a href="https://www.nexb.com/" target="_blank">nexB</a>. Licensed under the <a href="cc-by-4.0.html">Creative Commons Attribution License 4.0 (CC-BY-4.0)</a>.</p>
1010
<p>Generated with <a href="https://github.com/nexB/scancode-toolkit" target="_blank">ScanCode toolkit</a> {{ scancode_version }} on {{ now }}.</p>
11+
<p>This is updated daily automatically with latest updates from the develop branch of scancode-toolkit, if any.</p>
1112
</footer>
1213
</div>

tests/licensedcode/data/license_db/license_dump/bash-exception-gpl.html

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@
106106

107107
</dd>
108108

109-
<dt style="">is_builtin</dt>
110-
<dd>
111-
112-
True
113-
114-
</dd>
115-
116109
<dt style="">is_exception</dt>
117110
<dd>
118111

@@ -136,19 +129,6 @@
136129

137130
</dd>
138131

139-
<dt style="">text</dt>
140-
<dd>
141-
142-
The Free Software Foundation has exempted Bash from the requirement of
143-
Paragraph 2c of the General Public License. This is to say, there is
144-
no requirement for Bash to print a notice when it is started
145-
interactively in the usual way. We made this exception because users
146-
and standards expect shells not to print such messages. This
147-
exception applies to any program that serves as a shell and that is
148-
based primarily on Bash as opposed to other GNU software.
149-
150-
</dd>
151-
152132
</dl>
153133
<div class="text-bold">license_text</div>
154134
<pre id="license-text" class="code mt-1" style="white-space: pre-wrap;"><code>The Free Software Foundation has exempted Bash from the requirement of

tests/licensedcode/data/license_db/license_dump/bash-exception-gpl.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
"category": "Copyleft",
66
"owner": "Free Software Foundation (FSF)",
77
"notes": "this used with GPL 1.0 and 2.0. It was removed from the V3 text https://git.savannah.gnu.org/cgit/bash.git/commit/COPYING?id=3185942a5234e26ab13fa02f9c51d340cec514f8",
8-
"is_builtin": true,
98
"is_exception": true,
109
"spdx_license_key": "LicenseRef-scancode-bash-exception-gpl-2.0",
1110
"text_urls": [
1211
"https://git.savannah.gnu.org/cgit/bash.git/plain/COPYING?h=bash-3.0-rc1&id=dd9e6dfa23d0dae4888f11fb8c6a27bc36d1b283"
13-
],
14-
"text": "The Free Software Foundation has exempted Bash from the requirement of\nParagraph 2c of the General Public License. This is to say, there is\nno requirement for Bash to print a notice when it is started\ninteractively in the usual way. We made this exception because users\nand standards expect shells not to print such messages. This\nexception applies to any program that serves as a shell and that is\nbased primarily on Bash as opposed to other GNU software."
12+
]
1513
}

tests/licensedcode/data/license_db/license_dump/bash-exception-gpl.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@ name: Bash exception to GPL
44
category: Copyleft
55
owner: Free Software Foundation (FSF)
66
notes: this used with GPL 1.0 and 2.0. It was removed from the V3 text https://git.savannah.gnu.org/cgit/bash.git/commit/COPYING?id=3185942a5234e26ab13fa02f9c51d340cec514f8
7-
is_builtin: yes
87
is_exception: yes
98
spdx_license_key: LicenseRef-scancode-bash-exception-gpl-2.0
109
text_urls:
1110
- https://git.savannah.gnu.org/cgit/bash.git/plain/COPYING?h=bash-3.0-rc1&id=dd9e6dfa23d0dae4888f11fb8c6a27bc36d1b283
12-
text: |
13-
The Free Software Foundation has exempted Bash from the requirement of
14-
Paragraph 2c of the General Public License. This is to say, there is
15-
no requirement for Bash to print a notice when it is started
16-
interactively in the usual way. We made this exception because users
17-
and standards expect shells not to print such messages. This
18-
exception applies to any program that serves as a shell and that is
19-
based primarily on Bash as opposed to other GNU software.

0 commit comments

Comments
 (0)