PRESUBMIT.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. """Enforces json format.
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
  6. for more details on the presubmit API built into depot_tools.
  7. """
  8. PRESUBMIT_VERSION = '2.0.0'
  9. USE_PYTHON3 = True
  10. _IGNORE_FREEZE_FOOTER = 'Ignore-Freeze'
  11. # The time module's handling of timezones is abysmal, so the boundaries are
  12. # precomputed in UNIX time
  13. _FREEZE_START = 1639641600 # 2021/12/16 00:00 -0800
  14. _FREEZE_END = 1641196800 # 2022/01/03 00:00 -0800
  15. def CheckFreeze(input_api, output_api):
  16. if _FREEZE_START <= input_api.time.time() < _FREEZE_END:
  17. footers = input_api.change.GitFootersFromDescription()
  18. if _IGNORE_FREEZE_FOOTER not in footers:
  19. def convert(t):
  20. ts = input_api.time.localtime(t)
  21. return input_api.time.strftime('%Y/%m/%d %H:%M %z', ts)
  22. return [
  23. output_api.PresubmitError(
  24. 'There is a prod freeze in effect from {} until {},'
  25. ' files in //testing/buildbot cannot be modified'.format(
  26. convert(_FREEZE_START), convert(_FREEZE_END)))
  27. ]
  28. return []
  29. def CheckSourceSideSpecs(input_api, output_api):
  30. return input_api.RunTests([
  31. input_api.Command(name='check source side specs',
  32. cmd=[
  33. input_api.python3_executable,
  34. 'generate_buildbot_json.py', '--check', '--verbose'
  35. ],
  36. kwargs={},
  37. message=output_api.PresubmitError),
  38. ])
  39. def CheckTests(input_api, output_api):
  40. glob = input_api.os_path.join(input_api.PresubmitLocalPath(), '*test.py')
  41. tests = input_api.canned_checks.GetUnitTests(input_api,
  42. output_api,
  43. input_api.glob(glob),
  44. run_on_python2=False,
  45. run_on_python3=True,
  46. skip_shebang_check=True)
  47. return input_api.RunTests(tests)
  48. def CheckManageJsonFiles(input_api, output_api):
  49. return input_api.RunTests([
  50. input_api.Command(
  51. name='manage JSON files',
  52. cmd=[input_api.python3_executable, 'manage.py', '--check'],
  53. kwargs={},
  54. message=output_api.PresubmitError),
  55. ])