-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters