From c3574e44932947c43c9b06273749598d265c68c8 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Tue, 6 Mar 2018 15:55:32 -0600 Subject: [PATCH] makes copyright year optional Signed-off-by: Mike Brown --- hack/boilerplate/boilerplate.Dockerfile.txt | 2 +- hack/boilerplate/boilerplate.Makefile.txt | 2 +- hack/boilerplate/boilerplate.go.txt | 2 +- hack/boilerplate/boilerplate.py | 21 +++++++++++++-------- hack/boilerplate/boilerplate.py.txt | 2 +- hack/boilerplate/boilerplate.sh.txt | 2 +- hack/boilerplate/test/fail.go | 2 +- hack/boilerplate/test/fail.py | 2 +- hack/boilerplate/test/pass.go | 2 +- hack/boilerplate/test/pass.py | 2 +- 10 files changed, 22 insertions(+), 17 deletions(-) diff --git a/hack/boilerplate/boilerplate.Dockerfile.txt b/hack/boilerplate/boilerplate.Dockerfile.txt index f7b7dee73..d9eb35eea 100644 --- a/hack/boilerplate/boilerplate.Dockerfile.txt +++ b/hack/boilerplate/boilerplate.Dockerfile.txt @@ -1,4 +1,4 @@ -# Copyright YEAR AUTHORS. +# Copyright AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/hack/boilerplate/boilerplate.Makefile.txt b/hack/boilerplate/boilerplate.Makefile.txt index f7b7dee73..d9eb35eea 100644 --- a/hack/boilerplate/boilerplate.Makefile.txt +++ b/hack/boilerplate/boilerplate.Makefile.txt @@ -1,4 +1,4 @@ -# Copyright YEAR AUTHORS. +# Copyright AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/hack/boilerplate/boilerplate.go.txt b/hack/boilerplate/boilerplate.go.txt index 4c70526f8..0e2abce97 100644 --- a/hack/boilerplate/boilerplate.go.txt +++ b/hack/boilerplate/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright YEAR AUTHORS. +Copyright AUTHORS. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py index 6d45827ab..6e7572e7d 100755 --- a/hack/boilerplate/boilerplate.py +++ b/hack/boilerplate/boilerplate.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # Copyright 2015 The Kubernetes Authors. -# Copyright 2018 The Containerd Authors. +# Copyright The Containerd Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -102,19 +102,22 @@ def file_passes(filename, refs, regexs): return False p = regexs["year"] - found = 0 + foundyear = 0 for d in ref: if p.search(d): - found = 1 + foundyear = 1 break - if found == 0: - print('File %s is missing the year' % filename, file=verbose_out) - return False - # Replace all occurrences of the regex "CURRENT_YEAR|...|2016|2015|2014" with "YEAR" + # if YEAR is found date is a requirement and should be in the range + # new rule is if YEAR is not found date is optional p = regexs["date"] for i, d in enumerate(data): (data[i], found) = p.subn('YEAR', d) + # remove the year and extra space when year is optional + if foundyear == 0: + p = regexs["yearsp"] + for i, d in enumerate(data): + (data[i], found) = p.subn('', d) p = regexs["authors"] found = 0 @@ -210,6 +213,7 @@ def get_regexs(): regexs = {} # Search for "YEAR" which exists in the boilerplate, but shouldn't in the real thing regexs["year"] = re.compile( 'YEAR' ) + regexs["yearsp"] = re.compile( 'YEAR ' ) # dates can be 2014, 2015, 2016, ..., CURRENT_YEAR, company holder names can be anything years = range(2014, date.today().year + 1) regexs["date"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), years)) ) @@ -220,7 +224,8 @@ def get_regexs(): regexs["authors"] = re.compile( 'AUTHORS' ) authors = [ 'The Kubernetes Authors', 'The Containerd Authors', 'The containerd Authors' ] regexs["auth"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), authors)) ) - regexs["copyright"] = re.compile( 'Copyright YEAR AUTHORS' ) + copyrightLines = [ 'Copyright YEAR AUTHORS', 'Copyright AUTHORS' ] + regexs["copyright"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), copyrightLines)) ) return regexs def main(): diff --git a/hack/boilerplate/boilerplate.py.txt b/hack/boilerplate/boilerplate.py.txt index f7b7dee73..d9eb35eea 100644 --- a/hack/boilerplate/boilerplate.py.txt +++ b/hack/boilerplate/boilerplate.py.txt @@ -1,4 +1,4 @@ -# Copyright YEAR AUTHORS. +# Copyright AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/hack/boilerplate/boilerplate.sh.txt b/hack/boilerplate/boilerplate.sh.txt index f7b7dee73..d9eb35eea 100644 --- a/hack/boilerplate/boilerplate.sh.txt +++ b/hack/boilerplate/boilerplate.sh.txt @@ -1,4 +1,4 @@ -# Copyright YEAR AUTHORS. +# Copyright AUTHORS. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/hack/boilerplate/test/fail.go b/hack/boilerplate/test/fail.go index 59e79d659..0f5549ad9 100644 --- a/hack/boilerplate/test/fail.go +++ b/hack/boilerplate/test/fail.go @@ -1,5 +1,5 @@ /* -Copyright 2014 The Kubernetes Authors. +Copyright The Kubernetes Authors. fail diff --git a/hack/boilerplate/test/fail.py b/hack/boilerplate/test/fail.py index cbdd06ff8..93ab146c6 100644 --- a/hack/boilerplate/test/fail.py +++ b/hack/boilerplate/test/fail.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2015 The Kubernetes Authors. +# Copyright The Kubernetes Authors. # # failed # diff --git a/hack/boilerplate/test/pass.go b/hack/boilerplate/test/pass.go index 6aa631178..340abae03 100644 --- a/hack/boilerplate/test/pass.go +++ b/hack/boilerplate/test/pass.go @@ -1,5 +1,5 @@ /* -Copyright 2014 The Kubernetes Authors. +Copyright The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/hack/boilerplate/test/pass.py b/hack/boilerplate/test/pass.py index 5b7ce29a2..2e77a1bf3 100644 --- a/hack/boilerplate/test/pass.py +++ b/hack/boilerplate/test/pass.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2015 The Kubernetes Authors. +# Copyright The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.