spack license update-copyright-year
now updates the LICENSE-MIT
file
`spack license update-copyright-year` was updating license headers but not the MIT license file. Make it do that and add a test. Also simplify the way we bump the latest copyright year so that we only need to update it in one place.
This commit is contained in:
parent
1422bde25a
commit
e3527983ac
@ -41,6 +41,9 @@
|
||||
r'^lib/spack/llnl/.*\.py$',
|
||||
r'^lib/spack/env/cc$',
|
||||
|
||||
# special case this test data file, which has a license header
|
||||
r'^lib/spack/spack/test/data/style/broken.dummy',
|
||||
|
||||
# rst files in documentation
|
||||
r'^lib/spack/docs/(?!command_index|spack|llnl).*\.rst$',
|
||||
r'^lib/spack/docs/.*\.py$',
|
||||
@ -62,7 +65,7 @@
|
||||
r'^.github/actions/.*\.py$',
|
||||
|
||||
# all packages
|
||||
r'^var/spack/repos/.*/package.py$'
|
||||
r'^var/spack/repos/.*/package.py$',
|
||||
]
|
||||
|
||||
#: licensed files that can have LGPL language in them
|
||||
@ -101,7 +104,18 @@ def list_files(args):
|
||||
# bool(value) evaluates to True
|
||||
OLD_LICENSE, SPDX_MISMATCH, GENERAL_MISMATCH = range(1, 4)
|
||||
|
||||
strict_date = r'Copyright 2013-2021'
|
||||
#: Latest year that copyright applies. UPDATE THIS when bumping copyright.
|
||||
latest_year = 2021
|
||||
strict_date = r'Copyright 2013-%s' % latest_year
|
||||
|
||||
#: regexes for valid license lines at tops of files
|
||||
license_line_regexes = [
|
||||
r'Copyright 2013-(%d|%d) Lawrence Livermore National Security, LLC and other' % (
|
||||
latest_year - 1, latest_year # allow a little leeway: current or last year
|
||||
),
|
||||
r'Spack Project Developers\. See the top-level COPYRIGHT file for details.',
|
||||
r'SPDX-License-Identifier: \(Apache-2\.0 OR MIT\)'
|
||||
]
|
||||
|
||||
|
||||
class LicenseError(object):
|
||||
@ -127,19 +141,14 @@ def error_messages(self):
|
||||
|
||||
|
||||
def _check_license(lines, path):
|
||||
license_lines = [
|
||||
r'Copyright 2013-(?:202[01]) Lawrence Livermore National Security, LLC and other', # noqa: E501
|
||||
r'Spack Project Developers\. See the top-level COPYRIGHT file for details.', # noqa: E501
|
||||
r'SPDX-License-Identifier: \(Apache-2\.0 OR MIT\)'
|
||||
]
|
||||
|
||||
found = []
|
||||
|
||||
for line in lines:
|
||||
line = re.sub(r'^[\s#\%\.]*', '', line)
|
||||
line = line.rstrip()
|
||||
for i, license_line in enumerate(license_lines):
|
||||
if re.match(license_line, line):
|
||||
for i, line_regex in enumerate(license_line_regexes):
|
||||
if re.match(line_regex, line):
|
||||
# The first line of the license contains the copyright date.
|
||||
# We allow it to be out of date but print a warning if it is
|
||||
# out of date.
|
||||
@ -148,7 +157,7 @@ def _check_license(lines, path):
|
||||
tty.debug('{0}: copyright date mismatch'.format(path))
|
||||
found.append(i)
|
||||
|
||||
if len(found) == len(license_lines) and found == list(sorted(found)):
|
||||
if len(found) == len(license_line_regexes) and found == list(sorted(found)):
|
||||
return
|
||||
|
||||
def old_license(line, path):
|
||||
@ -210,6 +219,12 @@ def update_copyright_year(args):
|
||||
os.path.join(args.root, filename)
|
||||
)
|
||||
|
||||
# also update MIT license file at root. Don't use llns_and_other; it uses
|
||||
# a shortened version of that for better github detection.
|
||||
mit_date = strict_date.replace("Copyright", "Copyright (c)")
|
||||
mit_file = os.path.join(args.root, "LICENSE-MIT")
|
||||
fs.filter_file(r"Copyright \(c\) \d{4}-\d{4}", mit_date, mit_file)
|
||||
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument(
|
||||
|
@ -85,6 +85,14 @@ def test_update_copyright_year(tmpdir):
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
""" % year)
|
||||
|
||||
# add an old MIT license at top level
|
||||
mit_file = os.path.join(spack.paths.prefix, "LICENSE-MIT")
|
||||
test_mit_file = str(tmpdir.join("LICENSE-MIT"))
|
||||
with open(mit_file) as real:
|
||||
with open(test_mit_file, "w") as dummy:
|
||||
old_copyright = re.sub(r"\d{4}-\d{4}", "2018-2019", real.read())
|
||||
dummy.write(old_copyright)
|
||||
|
||||
license('--root', str(tmpdir), 'update-copyright-year')
|
||||
|
||||
for year in years:
|
||||
@ -92,3 +100,6 @@ def test_update_copyright_year(tmpdir):
|
||||
first_line = outdated.open().read().split("\n")[0]
|
||||
assert str(year) not in first_line
|
||||
assert spack.cmd.license.strict_date in first_line
|
||||
|
||||
mit_date = spack.cmd.license.strict_date.replace("Copyright", "Copyright (c)")
|
||||
assert mit_date in open(test_mit_file).read()
|
||||
|
Loading…
Reference in New Issue
Block a user