Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Unified Diff: presubmit_support.py

Issue 6854022: Inhibit python subprocess from generating .pyc files anymore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_support.py
diff --git a/presubmit_support.py b/presubmit_support.py
index 1e16758b02c0786f124b4bc9faebfed2e7c723ea..c3604cf69408da369eedb3951071b59cd2970ae8 100755
--- a/presubmit_support.py
+++ b/presubmit_support.py
@@ -1035,72 +1035,80 @@ def DoPresubmitChecks(change,
A PresubmitOutput object. Use output.should_continue() to figure out
if there were errors or warnings and the caller should abort.
"""
- output = PresubmitOutput(input_stream, output_stream)
- if committing:
- output.write("Running presubmit commit checks ...\n")
- else:
- output.write("Running presubmit upload checks ...\n")
- 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)
+ old_environ = os.environ
+ try:
+ # Make sure python subprocesses won't generate .pyc files.
+ os.environ = os.environ.copy()
+ os.environ['PYTHONDONTWRITEBYTECODE'] = '1'
- errors = []
- notifications = []
- warnings = []
- for result in results:
- if result.fatal:
- errors.append(result)
- elif result.should_prompt:
- warnings.append(result)
+ output = PresubmitOutput(input_stream, output_stream)
+ if committing:
+ output.write("Running presubmit commit checks ...\n")
else:
- notifications.append(result)
-
- output.write('\n')
- for name, items in (('Messages', notifications),
- ('Warnings', warnings),
- ('ERRORS', errors)):
- if items:
- output.write('** Presubmit %s **\n' % name)
- for item in items:
- item.handle(output)
- output.write('\n')
+ output.write("Running presubmit upload checks ...\n")
+ 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 = []
+ 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
- if total_time > 1.0:
- output.write("Presubmit checks took %.1fs to calculate.\n\n" % total_time)
+ output.write('\n')
+ for name, items in (('Messages', notifications),
+ ('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:
- 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()
-
- 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
+ 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
+ finally:
+ os.environ = old_environ
def ScanSubDirs(mask, recursive):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698