Skip to content

Commit

Permalink
tox -e deprecations: add helper script to make it work
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
warner committed Apr 6, 2016
1 parent ce54868 commit 14c513d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
68 changes: 68 additions & 0 deletions misc/build_helpers/run-deprecations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ passenv = USERPROFILE HOMEDRIVE HOMEPATH
setenv =
PYTHONWARNINGS=default::DeprecationWarning
commands =
trial --rterrors {posargs:allmydata}
python misc/build_helpers/run-deprecations.py --stderr=_trial_temp/stderr.log trial --rterrors {posargs:allmydata}

[testenv:checkmemory]
commands =
Expand Down

0 comments on commit 14c513d

Please sign in to comment.