tahoe-lafs/misc/build_helpers/run-deprecations.py
Brian Warner 14c513db8a tox -e deprecations: add helper script to make it work
Tox doesn't run shell pipelines, and is unhappy about running tools that
it didn't install itself (including non-python things like "make"). So
this adds misc/build_helpers/run-deprecations.py, a python script that
runs a given command (i.e. trial) and writes stdout into a separate file
where the buildbot can see it, and counts the "DeprecationWarning" lines
from the file to decide the returncode.

This ought to improve the status display on the buildbot "test
deprecations" step.
2016-04-06 08:29:48 -10:00

69 lines
2.0 KiB
Python

import sys, os, subprocess
from twisted.python.procutils import which
from twisted.python import usage
# run the command with python's deprecation warnings turned on, capturing
# stderr. When done, scan stderr for warnings, write them to a separate
# logfile (so the buildbot can see them), and return rc=1 if there were any.
class Options(usage.Options):
optParameters = [
["stderr", None, None, "file to write stderr into at end of test run"],
]
def parseArgs(self, command, *args):
self["command"] = command
self["args"] = list(args)
description = """Run as:
PYTHONWARNINGS=default::DeprecationWarning python run-deprecations.py [--stderr=STDERRFILE] COMMAND ARGS..
"""
config = Options()
config.parseOptions()
command = config["command"]
if "/" in command:
# don't search
exe = command
else:
executables = which(command)
if not executables:
raise ValueError("unable to find '%s' in PATH (%s)" %
(command, os.environ.get("PATH")))
exe = executables[0]
pw = os.environ.get("PYTHONWARNINGS")
DDW = "default::DeprecationWarning"
if pw != DDW:
print "note: $PYTHONWARNINGS is '%s', not the expected %s" % (pw, DDW)
print "note: stderr is being captured, and will be emitted at the end"
# stdout goes directly to the parent, so test progress can be watched in real
# time. But subprocess.Popen() doesn't give us any good way of seeing it
p = subprocess.Popen([exe] + config["args"], stderr=subprocess.PIPE)
stderr = p.communicate()[1]
rc = p.returncode
count = 0
if config["stderr"]:
with open(config["stderr"], "wb") as f:
print >>f, stderr,
if stderr:
print >>sys.stderr, "--"
print >>sys.stderr, "Captured stderr follows:"
for line in stderr.splitlines():
if "DeprecationWarning" in line:
count += 1
print >>sys.stderr, line
print >>sys.stderr, "--"
if count:
print "ERROR: %d deprecation warnings found" % count
sys.exit(1)
print "no deprecation warnings"
sys.exit(rc)