Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: PRESUBMIT.py

Issue 2981033002: Fix copyright header presubmit (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2017 The LUCI Authors.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 #
3 # that can be found in the LICENSE file. 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
4 14
5 """Top-level presubmit script. 15 """Top-level presubmit script.
6 16
7 See https://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for 17 See https://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into depot_tools. 18 details on the presubmit API built into depot_tools.
9 """ 19 """
10 20
11 import os 21 import os
22 import re
12 import sys 23 import sys
13 24
14 25
15 def PreCommitGo(input_api, output_api, pcg_mode): 26 def PreCommitGo(input_api, output_api, pcg_mode):
16 """Run go-specific checks via pre-commit-go (pcg) if it's in PATH.""" 27 """Run go-specific checks via pre-commit-go (pcg) if it's in PATH."""
17 if input_api.is_committing: 28 if input_api.is_committing:
18 error_type = output_api.PresubmitError 29 error_type = output_api.PresubmitError
19 else: 30 else:
20 error_type = output_api.PresubmitPromptWarning 31 error_type = output_api.PresubmitPromptWarning
21 32
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 69
59 output = [] 70 output = []
60 output += input_api.RunTests([input_api.Command( 71 output += input_api.RunTests([input_api.Command(
61 name='web presubmit', 72 name='web presubmit',
62 cmd=[ 73 cmd=[
63 input_api.python_executable, 74 input_api.python_executable,
64 input_api.os_path.join('web', 'web.py'), 75 input_api.os_path.join('web', 'web.py'),
65 'presubmit', 76 'presubmit',
66 ], 77 ],
67 kwargs={}, 78 kwargs={},
68 message=output_api.PresubmitError, 79 message=error_type,
69 )]) 80 )])
70 return output 81 return output
71 82
72 83
84 COPYRIGHT_TEMPLATE = """
85 Copyright YEARPATTERN The LUCI Authors.
86
87 Licensed under the Apache License, Version 2.0 (the "License");
88 you may not use this file except in compliance with the License.
89 You may obtain a copy of the License at
90
91 http://www.apache.org/licenses/LICENSE-2.0
92
93 Unless required by applicable law or agreed to in writing, software
94 distributed under the License is distributed on an "AS IS" BASIS,
95 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 See the License for the specific language governing permissions and
97 limitations under the License.
98 """.strip()
99
73 def header(input_api): 100 def header(input_api):
74 """Returns the expected license header regexp for this project.""" 101 """Returns the expected license header regexp for this project."""
75 current_year = int(input_api.time.strftime('%Y')) 102 current_year = int(input_api.time.strftime('%Y'))
76 allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1))) 103 allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1)))
77 years_re = '(' + '|'.join(allowed_years) + ')' 104 years_re = '(' + '|'.join(allowed_years) + ')'
78 license_header = ( 105 lines = [
79 r'.*? Copyright %(year)s The LUCI Authors\. ' 106 ('.*? ' + re.escape(line)) if line else '.*?'
80 r'All rights reserved\.\n' 107 for line in COPYRIGHT_TEMPLATE.splitlines()
81 r'.*? Use of this source code is governed under the Apache License, ' 108 ]
82 r'Version 2\.0\n' 109 lines[0] = lines[0].replace('YEARPATTERN', years_re)
Ryan Tseng 2017/07/15 01:08:23 lol
83 r'.*? that can be found in the LICENSE file\.(?: \*/)?\n' 110 return '\n'.join(lines) + '(?: \*/)?\n'
84 ) % {
85 'year': years_re,
86 }
87 return license_header
88 111
89 112
90 def source_file_filter(input_api): 113 def source_file_filter(input_api):
91 """Returns filter that selects source code files only.""" 114 """Returns filter that selects source code files only."""
92 bl = list(input_api.DEFAULT_BLACK_LIST) + [ 115 bl = list(input_api.DEFAULT_BLACK_LIST) + [
93 r'.+/bootstrap/.*', # third party 116 r'.+/bootstrap/.*', # third party
94 r'.+/jquery/.*', # third party 117 r'.+/jquery/.*', # third party
95 r'.+/pb\.discovery\.go$', 118 r'.+/pb\.discovery\.go$',
96 r'.+/pb\.discovery_test\.go$', 119 r'.+/pb\.discovery_test\.go$',
97 r'.+\.pb\.go$', 120 r'.+\.pb\.go$',
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 results = CommonChecks(input_api, output_api) 159 results = CommonChecks(input_api, output_api)
137 results.extend(input_api.canned_checks.CheckChangeHasDescription( 160 results.extend(input_api.canned_checks.CheckChangeHasDescription(
138 input_api, output_api)) 161 input_api, output_api))
139 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( 162 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription(
140 input_api, output_api)) 163 input_api, output_api))
141 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( 164 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles(
142 input_api, output_api)) 165 input_api, output_api))
143 results.extend(PreCommitGo( 166 results.extend(PreCommitGo(
144 input_api, output_api, ['continuous-integration'])) 167 input_api, output_api, ['continuous-integration']))
145 return results 168 return results
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698