Commit ea7c855b authored by maruel@chromium.org's avatar maruel@chromium.org

Inhibit python subprocess from generating .pyc files anymore.

This would case a failure when:
- a .py file is moved
- *.pyc is in svn:ignore, causing the .pyc to not be deleted.
- the new .py modifies its API.
- another .py imports the old .py and uses the new API.

R=dpranke@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/6854022

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@81942 0039d316-1c4b-4281-b951-d872f2087c98
parent 0d5ef24c
...@@ -1035,72 +1035,80 @@ def DoPresubmitChecks(change, ...@@ -1035,72 +1035,80 @@ def DoPresubmitChecks(change,
A PresubmitOutput object. Use output.should_continue() to figure out A PresubmitOutput object. Use output.should_continue() to figure out
if there were errors or warnings and the caller should abort. if there were errors or warnings and the caller should abort.
""" """
output = PresubmitOutput(input_stream, output_stream) old_environ = os.environ
if committing: try:
output.write("Running presubmit commit checks ...\n") # Make sure python subprocesses won't generate .pyc files.
else: os.environ = os.environ.copy()
output.write("Running presubmit upload checks ...\n") os.environ['PYTHONDONTWRITEBYTECODE'] = '1'
start_time = time.time()
presubmit_files = ListRelevantPresubmitFiles(change.AbsoluteLocalPaths(True),
change.RepositoryRoot())
if not presubmit_files and verbose:
output.write("Warning, no presubmit.py found.\n")
results = []
executer = PresubmitExecuter(change, committing, tbr, rietveld, verbose)
if default_presubmit:
if verbose:
output.write("Running default presubmit script.\n")
fake_path = os.path.join(change.RepositoryRoot(), 'PRESUBMIT.py')
results += executer.ExecPresubmitScript(default_presubmit, fake_path)
for filename in presubmit_files:
filename = os.path.abspath(filename)
if verbose:
output.write("Running %s\n" % filename)
# Accept CRLF presubmit script.
presubmit_script = gclient_utils.FileRead(filename, 'rU')
results += executer.ExecPresubmitScript(presubmit_script, filename)
errors = [] output = PresubmitOutput(input_stream, output_stream)
notifications = [] if committing:
warnings = [] output.write("Running presubmit commit checks ...\n")
for result in results:
if result.fatal:
errors.append(result)
elif result.should_prompt:
warnings.append(result)
else: else:
notifications.append(result) output.write("Running presubmit upload checks ...\n")
start_time = time.time()
output.write('\n') presubmit_files = ListRelevantPresubmitFiles(
for name, items in (('Messages', notifications), change.AbsoluteLocalPaths(True), change.RepositoryRoot())
('Warnings', warnings), if not presubmit_files and verbose:
('ERRORS', errors)): output.write("Warning, no presubmit.py found.\n")
if items: results = []
output.write('** Presubmit %s **\n' % name) executer = PresubmitExecuter(change, committing, tbr, rietveld, verbose)
for item in items: if default_presubmit:
item.handle(output) if verbose:
output.write('\n') output.write("Running default presubmit script.\n")
fake_path = os.path.join(change.RepositoryRoot(), 'PRESUBMIT.py')
results += executer.ExecPresubmitScript(default_presubmit, fake_path)
for filename in presubmit_files:
filename = os.path.abspath(filename)
if verbose:
output.write("Running %s\n" % filename)
# Accept CRLF presubmit script.
presubmit_script = gclient_utils.FileRead(filename, 'rU')
results += executer.ExecPresubmitScript(presubmit_script, filename)
errors = []
notifications = []
warnings = []
for result in results:
if result.fatal:
errors.append(result)
elif result.should_prompt:
warnings.append(result)
else:
notifications.append(result)
total_time = time.time() - start_time output.write('\n')
if total_time > 1.0: for name, items in (('Messages', notifications),
output.write("Presubmit checks took %.1fs to calculate.\n\n" % total_time) ('Warnings', warnings),
('ERRORS', errors)):
if items:
output.write('** Presubmit %s **\n' % name)
for item in items:
item.handle(output)
output.write('\n')
total_time = time.time() - start_time
if total_time > 1.0:
output.write("Presubmit checks took %.1fs to calculate.\n\n" % total_time)
if not errors:
if not warnings:
output.write('Presubmit checks passed.\n')
elif may_prompt:
output.prompt_yes_no('There were presubmit warnings. '
'Are you sure you wish to continue? (y/N): ')
else:
output.fail()
if not errors: global _ASKED_FOR_FEEDBACK
if not warnings: # Ask for feedback one time out of 5.
output.write('Presubmit checks passed.\n') if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK):
elif may_prompt: output.write("Was the presubmit check useful? Please send feedback "
output.prompt_yes_no('There were presubmit warnings. ' "& hate mail to maruel@chromium.org!\n")
'Are you sure you wish to continue? (y/N): ') _ASKED_FOR_FEEDBACK = True
else: return output
output.fail() finally:
os.environ = old_environ
global _ASKED_FOR_FEEDBACK
# Ask for feedback one time out of 5.
if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK):
output.write("Was the presubmit check useful? Please send feedback "
"& hate mail to maruel@chromium.org!\n")
_ASKED_FOR_FEEDBACK = True
return output
def ScanSubDirs(mask, recursive): def ScanSubDirs(mask, recursive):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment