forked from youtube/cobalt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRESUBMIT.py
102 lines (80 loc) · 3.72 KB
/
PRESUBMIT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
USE_PYTHON3 = True
_IGNORE_FREEZE_FOOTER = 'Ignore-Freeze'
# The time module's handling of timezones is abysmal, so the boundaries are
# precomputed in UNIX time
_FREEZE_START = 1671177600 # 2022/12/16 00:00 -0800
_FREEZE_END = 1672646400 # 2023/01/02 00:00 -0800
def CheckFreeze(input_api, output_api):
if _FREEZE_START <= input_api.time.time() < _FREEZE_END:
footers = input_api.change.GitFootersFromDescription()
if _IGNORE_FREEZE_FOOTER not in footers:
def convert(t):
ts = input_api.time.localtime(t)
return input_api.time.strftime('%Y/%m/%d %H:%M %z', ts)
# Don't report errors when on the presubmit --all bot or when testing
# with presubmit --files.
if input_api.no_diffs:
report_type = output_api.PresubmitPromptWarning
else:
report_type = output_api.PresubmitError
return [
report_type('There is a prod freeze in effect from {} until {},'
' files in //tools/mb cannot be modified'.format(
convert(_FREEZE_START), convert(_FREEZE_END)))
]
return []
def CheckTests(input_api, output_api):
glob = input_api.os_path.join(input_api.PresubmitLocalPath(), '*_test.py')
tests = input_api.canned_checks.GetUnitTests(input_api,
output_api,
input_api.glob(glob),
run_on_python2=False,
run_on_python3=True,
skip_shebang_check=True)
return input_api.RunTests(tests)
def _CommonChecks(input_api, output_api):
tests = []
# Run Pylint over the files in the directory.
tests.extend(
input_api.canned_checks.GetPylint(
input_api,
output_api,
version='2.7',
# pylint complains about Checkfreeze not being defined, its probably
# finding a different PRESUBMIT.py. Note that this warning only
# appears if the number of Pylint jobs is greater than one.
files_to_skip=['PRESUBMIT_test.py'],
# Disabling this warning because this pattern involving ToSrcRelPath
# seems intrinsic to how mb_unittest.py is implemented.
disabled_warnings=[
'attribute-defined-outside-init',
]))
# Run the MB unittests.
tests.extend(
input_api.canned_checks.GetUnitTestsInDirectory(input_api,
output_api,
'.',
[r'^.+_unittest\.py$'],
run_on_python2=False,
run_on_python3=True,
skip_shebang_check=True))
# Validate the format of the mb_config.pyl file.
cmd = [input_api.python3_executable, 'mb.py', 'validate']
kwargs = {'cwd': input_api.PresubmitLocalPath()}
tests.append(
input_api.Command(name='mb_validate',
cmd=cmd,
kwargs=kwargs,
message=output_api.PresubmitError))
results = []
results.extend(input_api.RunTests(tests))
results.extend(CheckFreeze(input_api, output_api))
results.extend(CheckTests(input_api, output_api))
return results
def CheckChangeOnUpload(input_api, output_api):
return _CommonChecks(input_api, output_api)
def CheckChangeOnCommit(input_api, output_api):
return _CommonChecks(input_api, output_api)