PRESUBMIT.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 CheckChangeOnUpload(input_api, output_api):
  68. report = []
  69. report.extend(input_api.canned_checks.PanProjectChecks(
  70. input_api, output_api))
  71. return report
  72. def CheckChangeOnCommit(input_api, output_api):
  73. report = []
  74. # Accept any year number from 2009 to the current year.
  75. current_year = int(input_api.time.strftime('%Y'))
  76. allowed_years = (str(s) for s in reversed(xrange(2009, current_year + 1)))
  77. years_re = '(' + '|'.join(allowed_years) + ')'
  78. # The (c) is deprecated, but tolerate it until it's removed from all files.
  79. license = (
  80. r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
  81. r'.*? Use of this source code is governed by a BSD-style license that '
  82. r'can be\n'
  83. r'.*? found in the LICENSE file\.\n'
  84. ) % {
  85. 'year': years_re,
  86. }
  87. report.extend(input_api.canned_checks.PanProjectChecks(
  88. input_api, output_api, license_header=license))
  89. report.extend(input_api.canned_checks.CheckTreeIsOpen(
  90. input_api, output_api,
  91. 'http://gyp-status.appspot.com/status',
  92. 'http://gyp-status.appspot.com/current'))
  93. import os
  94. import sys
  95. old_sys_path = sys.path
  96. try:
  97. sys.path = ['pylib', 'test/lib'] + sys.path
  98. blacklist = PYLINT_BLACKLIST
  99. if sys.platform == 'win32':
  100. blacklist = [os.path.normpath(x).replace('\\', '\\\\')
  101. for x in PYLINT_BLACKLIST]
  102. report.extend(input_api.canned_checks.RunPylint(
  103. input_api,
  104. output_api,
  105. black_list=blacklist,
  106. disabled_warnings=PYLINT_DISABLED_WARNINGS))
  107. finally:
  108. sys.path = old_sys_path
  109. return report
  110. TRYBOTS = [
  111. 'linux_try',
  112. 'mac_try',
  113. 'win_try',
  114. ]
  115. def GetPreferredTryMasters(_, change):
  116. return {
  117. 'client.gyp': { t: set(['defaulttests']) for t in TRYBOTS },
  118. }