Skip to content

Commit 541ab2a

Browse files
authored
Merge pull request #255 from SergeyKanzhelev/removeYear
removed year from boilerplates, allow 2014-2025 years in existing cop…
2 parents 8d4d789 + 9d9e206 commit 541ab2a

10 files changed

Lines changed: 46 additions & 32 deletions

hack/verify_boilerplate.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ def get_refs():
7676

7777
return refs
7878

79-
# given the file contents, return true if the file appears to be generated
80-
def is_generated(data):
81-
if re.search(r"^// Code generated by .*\. DO NOT EDIT\.$", data, re.MULTILINE):
82-
return True
83-
return False
84-
8579

8680
def file_passes(filename, refs, regexs): # pylint: disable=too-many-locals
8781
try:
@@ -123,22 +117,10 @@ def file_passes(filename, refs, regexs): # pylint: disable=too-many-locals
123117
# trim our file to the same number of lines as the reference file
124118
data = data[:len(ref)]
125119

126-
# check if we encounter a 'YEAR' placeholder if the file is generated
127-
if is_generated(file_data):
128-
for i, line in enumerate(data):
129-
if "Copyright YEAR" in line:
130-
return False
131-
return True
132-
133-
year = regexs["year"]
134-
for datum in data:
135-
if year.search(datum):
136-
return False
137-
138-
# Replace all occurrences of the regex "2017|2016|2015|2014" with "YEAR"
120+
# Replace all occurrences of the regex "Copyright 2017 |Copyright " with "Copyright "
139121
when = regexs["date"]
140122
for idx, datum in enumerate(data):
141-
(data[idx], found) = when.subn('YEAR', datum)
123+
(data[idx], found) = when.subn('Copyright ', datum)
142124
if found != 0:
143125
break
144126

@@ -211,16 +193,13 @@ def get_files(extensions):
211193

212194

213195
def get_dates():
214-
years = datetime.datetime.now().year
215-
return '(%s)' % '|'.join((str(year) for year in range(2014, years + 1)))
196+
return '((201[4-9]|202[0-5]) )?'
216197

217198

218199
def get_regexs():
219200
regexs = {}
220-
# Search for "YEAR" which exists in the boilerplate, but shouldn't in the real thing
221-
regexs["year"] = re.compile('YEAR')
222-
# dates can be any year between 2014 and the current year, company holder names can be anything
223-
regexs["date"] = re.compile(get_dates())
201+
# dates can be any year between 2014 and 2025, company holder names can be anything
202+
regexs["date"] = re.compile(r'Copyright ' + get_dates())
224203
# strip // +build \n\n build constraints
225204
regexs["go_build_constraints"] = re.compile(r"^(//( \+build|go:build).*\n)+\n",
226205
re.MULTILINE)

hack/verify_boilerplate_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self):
5353
expected = '\n'.join(verify_boilerplate.nonconforming_lines([
5454
'./fail.go',
5555
'./fail.py',
56+
'./fail_2026.go',
5657
])) + '\n' # add trailing newline
5758

5859
self.assertEqual(output, expected)

verify/boilerplate/boilerplate.Dockerfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright YEAR The Kubernetes Authors.
1+
# Copyright The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

verify/boilerplate/boilerplate.Makefile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright YEAR The Kubernetes Authors.
1+
# Copyright The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

verify/boilerplate/boilerplate.bzl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright YEAR The Kubernetes Authors.
1+
# Copyright The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

verify/boilerplate/boilerplate.go.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright YEAR The Kubernetes Authors.
2+
Copyright The Kubernetes Authors.
33

44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

verify/boilerplate/boilerplate.py.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright YEAR The Kubernetes Authors.
1+
# Copyright The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

verify/boilerplate/boilerplate.sh.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright YEAR The Kubernetes Authors.
1+
# Copyright The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright 2026 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package test
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package test

0 commit comments

Comments
 (0)