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/llnl/.*\.py$',
|
||||||
r'^lib/spack/env/cc$',
|
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
|
# rst files in documentation
|
||||||
r'^lib/spack/docs/(?!command_index|spack|llnl).*\.rst$',
|
r'^lib/spack/docs/(?!command_index|spack|llnl).*\.rst$',
|
||||||
r'^lib/spack/docs/.*\.py$',
|
r'^lib/spack/docs/.*\.py$',
|
||||||
@ -62,7 +65,7 @@
|
|||||||
r'^.github/actions/.*\.py$',
|
r'^.github/actions/.*\.py$',
|
||||||
|
|
||||||
# all packages
|
# all packages
|
||||||
r'^var/spack/repos/.*/package.py$'
|
r'^var/spack/repos/.*/package.py$',
|
||||||
]
|
]
|
||||||
|
|
||||||
#: licensed files that can have LGPL language in them
|
#: licensed files that can have LGPL language in them
|
||||||
@ -101,7 +104,18 @@ def list_files(args):
|
|||||||
# bool(value) evaluates to True
|
# bool(value) evaluates to True
|
||||||
OLD_LICENSE, SPDX_MISMATCH, GENERAL_MISMATCH = range(1, 4)
|
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):
|
class LicenseError(object):
|
||||||
@ -127,19 +141,14 @@ def error_messages(self):
|
|||||||
|
|
||||||
|
|
||||||
def _check_license(lines, path):
|
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 = []
|
found = []
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = re.sub(r'^[\s#\%\.]*', '', line)
|
line = re.sub(r'^[\s#\%\.]*', '', line)
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
for i, license_line in enumerate(license_lines):
|
for i, line_regex in enumerate(license_line_regexes):
|
||||||
if re.match(license_line, line):
|
if re.match(line_regex, line):
|
||||||
# The first line of the license contains the copyright date.
|
# 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
|
# We allow it to be out of date but print a warning if it is
|
||||||
# out of date.
|
# out of date.
|
||||||
@ -148,7 +157,7 @@ def _check_license(lines, path):
|
|||||||
tty.debug('{0}: copyright date mismatch'.format(path))
|
tty.debug('{0}: copyright date mismatch'.format(path))
|
||||||
found.append(i)
|
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
|
return
|
||||||
|
|
||||||
def old_license(line, path):
|
def old_license(line, path):
|
||||||
@ -210,6 +219,12 @@ def update_copyright_year(args):
|
|||||||
os.path.join(args.root, filename)
|
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):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
|
@ -85,6 +85,14 @@ def test_update_copyright_year(tmpdir):
|
|||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
""" % year)
|
""" % 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')
|
license('--root', str(tmpdir), 'update-copyright-year')
|
||||||
|
|
||||||
for year in years:
|
for year in years:
|
||||||
@ -92,3 +100,6 @@ def test_update_copyright_year(tmpdir):
|
|||||||
first_line = outdated.open().read().split("\n")[0]
|
first_line = outdated.open().read().split("\n")[0]
|
||||||
assert str(year) not in first_line
|
assert str(year) not in first_line
|
||||||
assert spack.cmd.license.strict_date 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