From 3d624ec784efc31da8f3417e5d1c91afec8c4e2c Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 2 Aug 2019 18:28:30 -0600 Subject: [PATCH 1/4] news fragment --- newsfragments/3232.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3232.minor diff --git a/newsfragments/3232.minor b/newsfragments/3232.minor new file mode 100644 index 000000000..e69de29bb From 856b3782eabf257b786e90a47b874bfc24543843 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 2 Aug 2019 18:28:36 -0600 Subject: [PATCH 2/4] add a --package option to run-deprecations so we can restrict to our own errors --- misc/build_helpers/run-deprecations.py | 31 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/misc/build_helpers/run-deprecations.py b/misc/build_helpers/run-deprecations.py index 6c76bcd69..1c7b10c4b 100644 --- a/misc/build_helpers/run-deprecations.py +++ b/misc/build_helpers/run-deprecations.py @@ -1,6 +1,6 @@ from __future__ import print_function -import sys, os, io +import sys, os, io, re from twisted.internet import reactor, protocol, task, defer from twisted.python.procutils import which from twisted.python import usage @@ -12,6 +12,7 @@ from twisted.python import usage class Options(usage.Options): optParameters = [ ["warnings", None, None, "file to write warnings into at end of test run"], + ["package", None, None, "Python package to which to restrict warning collection"] ] def parseArgs(self, command, *args): @@ -19,7 +20,7 @@ class Options(usage.Options): self["args"] = list(args) description = """Run as: -PYTHONWARNINGS=default::DeprecationWarning python run-deprecations.py [--warnings=STDERRFILE] COMMAND ARGS.. +PYTHONWARNINGS=default::DeprecationWarning python run-deprecations.py [--warnings=STDERRFILE] [--package=PYTHONPACKAGE ] COMMAND ARGS.. """ class RunPP(protocol.ProcessProtocol): @@ -34,6 +35,26 @@ class RunPP(protocol.ProcessProtocol): rc = reason.value.exitCode self.d.callback((signal, rc)) + +def make_matcher(options): + # A deprecation warning line looks something like this: + # + # somepath/foo/bar/baz.py:43: DeprecationWarning: Foo is deprecated, try bar instead. + # + # Sadly there is no guarantee warnings begin at the beginning of a line + # since they are written to output without coordination with whatever + # other Python code is running in the process. + pattern = r".*\.py[oc]?:\d+:" # (Pending)?DeprecationWarning: .*" + if options["package"]: + pattern = r".*/{}/".format( + re.escape(options["package"]), + ) + pattern + expression = re.compile(pattern) + def match(line): + return expression.match(line) is not None + return match + + @defer.inlineCallbacks def run_command(main): config = Options() @@ -63,6 +84,8 @@ def run_command(main): reactor.spawnProcess(pp, exe, [exe] + config["args"], env=None) (signal, rc) = yield pp.d + match = make_matcher(config) + # maintain ordering, but ignore duplicates (for some reason, either the # 'warnings' module or twisted.python.deprecate isn't quashing them) already = set() @@ -75,12 +98,12 @@ def run_command(main): pp.stdout.seek(0) for line in pp.stdout.readlines(): - if "DeprecationWarning" in line: + if match(line): add(line) # includes newline pp.stderr.seek(0) for line in pp.stderr.readlines(): - if "DeprecationWarning" in line: + if match(line): add(line) if warnings: From bb385d45f70036722ab6f6e7a41ff0ed5d56d084 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 2 Aug 2019 18:29:04 -0600 Subject: [PATCH 3/4] teach tox about the new --package option --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 6164edd5e..e165ed168 100644 --- a/tox.ini +++ b/tox.ini @@ -97,7 +97,7 @@ commands = setenv = PYTHONWARNINGS=default::DeprecationWarning commands = - python misc/build_helpers/run-deprecations.py --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata} + python misc/build_helpers/run-deprecations.py --package allmydata --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata} [testenv:upcoming-deprecations] setenv = @@ -109,7 +109,7 @@ deps = git+https://github.com/warner/foolscap commands = flogtool --version - python misc/build_helpers/run-deprecations.py --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata} + python misc/build_helpers/run-deprecations.py --package allmydata --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata} [testenv:checkmemory] commands = From 9788857df69b0d616a1e4c0f8be1a845cc279e3d Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 7 Aug 2019 15:57:06 -0400 Subject: [PATCH 4/4] Turn the comment into a docstring --- misc/build_helpers/run-deprecations.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/misc/build_helpers/run-deprecations.py b/misc/build_helpers/run-deprecations.py index 1c7b10c4b..3972d5c89 100644 --- a/misc/build_helpers/run-deprecations.py +++ b/misc/build_helpers/run-deprecations.py @@ -37,13 +37,21 @@ class RunPP(protocol.ProcessProtocol): def make_matcher(options): - # A deprecation warning line looks something like this: - # - # somepath/foo/bar/baz.py:43: DeprecationWarning: Foo is deprecated, try bar instead. - # - # Sadly there is no guarantee warnings begin at the beginning of a line - # since they are written to output without coordination with whatever - # other Python code is running in the process. + """ + Make a function that matches a line with a relevant deprecation. + + A deprecation warning line looks something like this:: + + somepath/foo/bar/baz.py:43: DeprecationWarning: Foo is deprecated, try bar instead. + + Sadly there is no guarantee warnings begin at the beginning of a line + since they are written to output without coordination with whatever other + Python code is running in the process. + + :return: A one-argument callable that accepts a string and returns + ``True`` if it contains an interesting warning and ``False`` + otherwise. + """ pattern = r".*\.py[oc]?:\d+:" # (Pending)?DeprecationWarning: .*" if options["package"]: pattern = r".*/{}/".format(