PRESUBMIT.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Copyright (c) 2012 Google Inc. 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. """Top-level presubmit script for GYP.
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
  6. for more details about the presubmit API built into gcl.
  7. """
  8. PYLINT_BLACKLIST = [
  9. # TODO: fix me.
  10. # From SCons, not done in google style.
  11. 'test/lib/TestCmd.py',
  12. 'test/lib/TestCommon.py',
  13. 'test/lib/TestGyp.py',
  14. ]
  15. PYLINT_DISABLED_WARNINGS = [
  16. # TODO: fix me.
  17. # Many tests include modules they don't use.
  18. 'W0611',
  19. # Possible unbalanced tuple unpacking with sequence.
  20. 'W0632',
  21. # Attempting to unpack a non-sequence.
  22. 'W0633',
  23. # Include order doesn't properly include local files?
  24. 'F0401',
  25. # Some use of built-in names.
  26. 'W0622',
  27. # Some unused variables.
  28. 'W0612',
  29. # Operator not preceded/followed by space.
  30. 'C0323',
  31. 'C0322',
  32. # Unnecessary semicolon.
  33. 'W0301',
  34. # Unused argument.
  35. 'W0613',
  36. # String has no effect (docstring in wrong place).
  37. 'W0105',
  38. # map/filter on lambda could be replaced by comprehension.
  39. 'W0110',
  40. # Use of eval.
  41. 'W0123',
  42. # Comma not followed by space.
  43. 'C0324',
  44. # Access to a protected member.
  45. 'W0212',
  46. # Bad indent.
  47. 'W0311',
  48. # Line too long.
  49. 'C0301',
  50. # Undefined variable.
  51. 'E0602',
  52. # Not exception type specified.
  53. 'W0702',
  54. # No member of that name.
  55. 'E1101',
  56. # Dangerous default {}.
  57. 'W0102',
  58. # Cyclic import.
  59. 'R0401',
  60. # Others, too many to sort.
  61. 'W0201', 'W0232', 'E1103', 'W0621', 'W0108', 'W0223', 'W0231',
  62. 'R0201', 'E0101', 'C0321',
  63. # ************* Module copy
  64. # W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect
  65. 'W0104',
  66. ]
  67. def _LicenseHeader(input_api):
  68. # Accept any year number from 2009 to the current year.
  69. current_year = int(input_api.time.strftime('%Y'))
  70. allowed_years = (str(s) for s in reversed(xrange(2009, current_year + 1)))
  71. years_re = '(' + '|'.join(allowed_years) + ')'
  72. # The (c) is deprecated, but tolerate it until it's removed from all files.
  73. return (
  74. r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
  75. r'.*? Use of this source code is governed by a BSD-style license that '
  76. r'can be\n'
  77. r'.*? found in the LICENSE file\.\n'
  78. ) % {
  79. 'year': years_re,
  80. }
  81. def CheckChangeOnUpload(input_api, output_api):
  82. report = []
  83. report.extend(input_api.canned_checks.PanProjectChecks(
  84. input_api, output_api, license_header=_LicenseHeader(input_api)))
  85. return report
  86. def CheckChangeOnCommit(input_api, output_api):
  87. report = []
  88. report.extend(input_api.canned_checks.PanProjectChecks(
  89. input_api, output_api, license_header=_LicenseHeader(input_api)))
  90. report.extend(input_api.canned_checks.CheckTreeIsOpen(
  91. input_api, output_api,
  92. 'http://gyp-status.appspot.com/status',
  93. 'http://gyp-status.appspot.com/current'))
  94. import os
  95. import sys
  96. old_sys_path = sys.path
  97. try:
  98. sys.path = ['pylib', 'test/lib'] + sys.path
  99. blacklist = PYLINT_BLACKLIST
  100. if sys.platform == 'win32':
  101. blacklist = [os.path.normpath(x).replace('\\', '\\\\')
  102. for x in PYLINT_BLACKLIST]
  103. report.extend(input_api.canned_checks.RunPylint(
  104. input_api,
  105. output_api,
  106. black_list=blacklist,
  107. disabled_warnings=PYLINT_DISABLED_WARNINGS))
  108. finally:
  109. sys.path = old_sys_path
  110. return report
  111. TRYBOTS = [
  112. 'linux_try',
  113. 'mac_try',
  114. 'win_try',
  115. ]
  116. def GetPreferredTryMasters(_, change):
  117. return {
  118. 'client.gyp': { t: set(['defaulttests']) for t in TRYBOTS },
  119. }