Skip to content

Commit cadcc7c

Browse files
committed
Improve documented versions in the license dump
* Add a better version in scancode-config, using git describe * Add SPDX license list version to the HTML footer Reference: #3200 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 3e1084d commit cadcc7c

File tree

3 files changed

+76
-52
lines changed

3 files changed

+76
-52
lines changed

src/licensedcode/license_db.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
1-
# SPDX-License-Identifier: CC-BY-4.0 AND Apache-2.0
21
#
3-
# https://github.com/nexB/scancode-licensedb
4-
# Copyright 2020 nexB Inc. and others.
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
53
# ScanCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/scancode-toolkit for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
68
#
7-
# ScanCode LicenseDB data is licensed under the Creative Commons Attribution
8-
# License 4.0 (CC-BY-4.0).
9-
# Some licenses, such as the GNU GENERAL PUBLIC LICENSE, are subject to other licenses.
10-
# See the corresponding license text for the specific license conditions.
11-
#
12-
# ScanCode LicenseDB software is licensed under the Apache License version 2.0.
13-
# You may not use this software except in compliance with the License.
14-
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
15-
# Unless required by applicable law or agreed to in writing, software distributed
16-
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17-
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
18-
# specific language governing permissions and limitations under the License.
19-
#
20-
# ScanCode LicenseDB is generated with ScanCode Toolkit. The database and its contents
21-
# are provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
22-
# either express or implied.
23-
# No content from ScanCode LicenseDB should be considered or used as legal advice.
24-
# Consult an attorney for any legal advice.
259

2610
import os
2711
import json
@@ -40,7 +24,7 @@
4024
from licensedcode.models import load_licenses
4125
from licensedcode.models import licenses_data_dir
4226
from scancode_config import __version__ as scancode_version
43-
27+
from scancode_config import spdx_license_list_version
4428

4529
TEMPLATES_DIR = os.path.join(dirname(__file__), 'templates')
4630
STATIC_DIR = os.path.join(dirname(__file__), 'static')
@@ -51,18 +35,19 @@ def write_file(path, filename, content):
5135

5236

5337
def now():
54-
return datetime.now().strftime("%b %d, %Y")
55-
38+
return datetime.utcnow().strftime('%Y-%m-%dT')
5639

5740
base_context = {
5841
"scancode_version": scancode_version,
5942
"now": now(),
43+
"spdx_license_list_version": spdx_license_list_version,
6044
}
6145

6246

6347
base_context_test = {
6448
"scancode_version": "32.0.0b1",
6549
"now": "Dec 22, 2022",
50+
"spdx_license_list_version": "3.19",
6651
}
6752

6853

src/licensedcode/templates/footer.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
<a href="https://github.com/nexB/scancode-licensedb" target="_blank">GitHub</a> ·
77
<a href="https://www.aboutcode.org/" target="_blank">AboutCode</a>
88
</p>
9-
<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>
10-
<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>
9+
<p>Designed and built by <a href="https://www.nexb.com/" target="_blank">nexB</a>.
10+
Licensed under the <a href="cc-by-4.0.html">Creative Commons Attribution License 4.0 (CC-BY-4.0)</a>.</p>
11+
<p>Generated with <a href="https://github.com/nexB/scancode-toolkit" target="_blank">ScanCode toolkit</a>
12+
{{ scancode_version }} on {{ now }}.</p>
13+
<p>SPDX Licenses list version: {{ spdx_license_list_version }}</p>
14+
1215
</footer>
1316
</div>

src/scancode_config.py

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,43 +70,80 @@ def _create_dir(location):
7070
################################################################################
7171
# INVARIABLE INSTALLATION-SPECIFIC, BUILT-IN LOCATIONS AND FLAGS
7272
################################################################################
73-
# these are guaranteed to be there and are entirely based on and relative to the
73+
# These are guaranteed to be there and are entirely based on and relative to the
7474
# current installation location. This is where the source code and static data
7575
# lives.
7676

7777

78-
# in case package is not installed or we do not have setutools/pkg_resources
79-
# on hand fall back to this version
80-
__version__ = '32.0.0rc1'
78+
system_temp_dir = tempfile.gettempdir()
79+
scancode_src_dir = dirname(__file__)
80+
scancode_root_dir = dirname(scancode_src_dir)
8181

82-
# used to warn user when the version is out of date
83-
__release_date__ = datetime.datetime(2023, 1, 3)
82+
# USAGE MODE FLAG. If we have a .git dir, we are a git clone and developing
83+
_SCANCODE_DEV_MODE = os.path.exists(join(scancode_root_dir, '.git'))
8484

85-
# See https://github.com/nexB/scancode-toolkit/issues/2653 for more information
86-
# on the data format version
87-
__output_format_version__ = '3.0.0'
85+
# There are multiple cases for versions, depending on where we come from:
86+
__version__ = ''
8887

89-
#
90-
spdx_license_list_version = '3.19'
88+
# 1. - a git clone: we can use git describe which take consider the closest tag
89+
# "git describe --dirty > SCANCODE_VERSION"
90+
# This is the common case when we develop, including dump the latestlicense db
91+
if _SCANCODE_DEV_MODE:
9192

92-
try:
93-
from pkg_resources import get_distribution, DistributionNotFound
93+
from subprocess import check_output
94+
from subprocess import STDOUT
95+
from subprocess import CalledProcessError
96+
97+
# this may fail with exceptions
98+
cmd = 'git', 'describe',
9499
try:
95-
__version__ = get_distribution('scancode-toolkit').version
96-
except DistributionNotFound:
100+
output = check_output(cmd, stderr=STDOUT)
101+
__version__ = output.decode('utf-8').strip()
102+
except (Exception, CalledProcessError) as e:
97103
pass
98-
except ImportError:
99-
pass
100104

101-
system_temp_dir = tempfile.gettempdir()
102-
scancode_src_dir = dirname(__file__)
103-
scancode_root_dir = dirname(scancode_src_dir)
105+
# 2. - the scancode-tool binary or sources app archives: with a SCANCODE_VERSION
106+
# file containing the git tag of the release with "git describe --tags > SCANCODE_VERSION"
107+
# - a tarball without an updated .VERSION, we cannot tell anything and we will use importlib metadata
108+
# - a wheel or sdist in which case we use the importlib metadata
109+
# we use importlib metadata in all these cases
110+
if not __version__:
111+
try:
112+
from importlib_metadata import version
113+
__version__ = version('scancode-toolkit')
114+
except Exception:
115+
pass
104116

105-
################################################################################
106-
# USAGE MODE FLAGS
107-
################################################################################
117+
# 3. - a tarball or zip archive from git with a .VERSION file with var substitution:
118+
# .VERSION will contain:
119+
# refs=HEAD -> fix-license-dump
120+
# commit=5ccc92e69cffb503e9bedc7fce5a1dbb0fd851da
121+
# abbrev_commit=5ccc92e69c
122+
# committer_date=2023-01-16
123+
# git_describe=v31.2.3-328-g5ccc92e69c
124+
# otherwise it contains:
125+
# refs=$Format:%D$
126+
# commit=$Format:%H$
127+
# abbrev_commit=$Format:%h$
128+
# committer_date=$Format:%cs$
129+
# git_describe=$Format:%(describe)$
130+
# NOTE: we do not handle this for now
131+
132+
# 4. hardcoded This is the default, fallback version in case package is not installed or we
133+
# do not have a proper version otherwise.
134+
if not __version__:
135+
__version__ = '32.0.0rc1'
136+
137+
#######################
138+
# used to warn user when the version is out of date
139+
__release_date__ = datetime.datetime(2023, 1, 15)
108140

109-
_SCANCODE_DEV_MODE = os.path.exists(join(scancode_root_dir, '.git'))
141+
# See https://github.com/nexB/scancode-toolkit/issues/2653 for more information
142+
# on the data format version
143+
__output_format_version__ = '3.0.0'
144+
145+
#
146+
spdx_license_list_version = '3.19'
110147

111148
################################################################################
112149
# USAGE MODE-, INSTALLATION- and IMPORT- and RUN-SPECIFIC DIRECTORIES
@@ -171,6 +208,5 @@ def _create_dir(location):
171208
_prefix = 'scancode-tk-' + __version__ + '-'
172209
scancode_temp_dir = tempfile.mkdtemp(prefix=_prefix, dir=__scancode_temp_base_dir)
173210

174-
175211
# Used for tests to regenerate fixtures with regen=True
176212
REGEN_TEST_FIXTURES = os.getenv('SCANCODE_REGEN_TEST_FIXTURES', False)

0 commit comments

Comments
 (0)