From 18f7ecbc364a2e95def74d6e7546e920cc38e238 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 14 Jun 2015 09:41:01 -0400 Subject: Debugging plugin wrappers --- coverage/plugin.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'coverage/plugin.py') diff --git a/coverage/plugin.py b/coverage/plugin.py index 6648d7a..3fbb43a 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -3,8 +3,10 @@ import os import re +from coverage import files from coverage.misc import _needs_to_implement + # TODO: document that the plugin objects may be decorated with attributes with # named "_coverage_*". @@ -25,7 +27,7 @@ class CoveragePlugin(object): """ - def __init__(self, options): + def __init__(self, options=None): """ When the plugin is constructed, it will be passed a dictionary of plugin-specific options read from the .coveragerc configuration file. @@ -36,7 +38,7 @@ class CoveragePlugin(object): .coveragerc configuration file. """ - self.options = options + self.options = options or {} def file_tracer(self, filename): # pylint: disable=unused-argument """Return a FileTracer object for a file. @@ -175,6 +177,9 @@ class FileReporter(object): " filename={self.filename!r}>".format(self=self) ) + def relative_filename(self): + return files.relative_filename(self.filename) + # Annoying comparison operators. Py3k wants __lt__ etc, and Py2k needs all # of them defined. @@ -247,6 +252,8 @@ class FileReporter(object): For example, the file a/b/c.py will return 'a_b_c_py' + You should not need to override this method. + """ - name = os.path.splitdrive(self.name)[1] + name = os.path.splitdrive(self.relative_filename())[1] return re.sub(r"[\\/.:]", "_", name) -- cgit v1.2.1 From 94287179f87bb02dbf4c189ad52f7416b4dc83f1 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 3 Jul 2015 14:00:37 -0400 Subject: Add some docstrings --- coverage/plugin.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'coverage/plugin.py') diff --git a/coverage/plugin.py b/coverage/plugin.py index 3fbb43a..678d297 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -171,11 +171,7 @@ class FileReporter(object): self.filename = filename def __repr__(self): - return ( - # pylint: disable=redundant-keyword-arg - "<{self.__class__.__name__}" - " filename={self.filename!r}>".format(self=self) - ) + return "<{0.__class__.__name__} filename={0.filename!r}>".format(self) def relative_filename(self): return files.relative_filename(self.filename) -- cgit v1.2.1 From 4c3f5a33a2ae10376ba1312d299ad087a716a943 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 5 Jul 2015 11:21:26 -0400 Subject: Constructing the plugin is the plugin's business --- coverage/plugin.py | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'coverage/plugin.py') diff --git a/coverage/plugin.py b/coverage/plugin.py index 678d297..44dab55 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -27,19 +27,6 @@ class CoveragePlugin(object): """ - def __init__(self, options=None): - """ - When the plugin is constructed, it will be passed a dictionary of - plugin-specific options read from the .coveragerc configuration file. - The base class stores these on the `self.options` attribute. - - Arguments: - options (dict): The plugin-specific options read from the - .coveragerc configuration file. - - """ - self.options = options or {} - def file_tracer(self, filename): # pylint: disable=unused-argument """Return a FileTracer object for a file. -- cgit v1.2.1 From dc0d0c613de54cd5af74a1d3ac9d86235dc0aee9 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 24 Jul 2015 10:43:46 -0400 Subject: Add license mention to the top of all files. #313. --- coverage/plugin.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'coverage/plugin.py') diff --git a/coverage/plugin.py b/coverage/plugin.py index 44dab55..c039f81 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -1,3 +1,6 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + """Plugin interfaces for coverage.py""" import os -- cgit v1.2.1 From fd2284632777a235ac663b7b9912246b30bc538b Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 26 Jul 2015 06:56:58 -0400 Subject: Get rid of napoleon style docstrings, they don't format nicely. --- coverage/plugin.py | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'coverage/plugin.py') diff --git a/coverage/plugin.py b/coverage/plugin.py index c039f81..62cc6dc 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -42,14 +42,12 @@ class CoveragePlugin(object): trace the file or not. Be prepared for `filename` to refer to all kinds of files that have nothing to do with your plugin. - Arguments: - filename (str): The path to the file being considered. This is the - absolute real path to the file. If you are comparing to other - paths, be sure to take this into account. + `filename` is a string, the path to the file being considered. This is + the absolute real path to the file. If you are comparing to other + paths, be sure to take this into account. - Returns: - FileTracer: the :class:`FileTracer` object to use to trace - `filename`, or None if this plugin cannot trace this file. + Returns a :class:`FileTracer` object to use to trace `filename`, or + None if this plugin cannot trace this file. """ return None @@ -91,8 +89,7 @@ class FileTracer(object): to own the mapping from Python execution back to whatever source filename was originally the source of the code. - Returns: - The filename to credit with this execution. + Returns the filename to credit with this execution. """ _needs_to_implement(self, "source_filename") @@ -102,13 +99,12 @@ class FileTracer(object): FileTracers can provide dynamically determined filenames by implementing dynamic_source_filename. Invoking that function is - expensive. To determine whether to invoke it, coverage.py uses - the result of this function to know if it needs to bother invoking + expensive. To determine whether to invoke it, coverage.py uses the + result of this function to know if it needs to bother invoking :meth:`dynamic_source_filename`. - Returns: - boolean: True if :meth:`dynamic_source_filename` should be called - to get dynamic source filenames. + Returns true if :meth:`dynamic_source_filename` should be called to get + dynamic source filenames. """ return False @@ -122,9 +118,8 @@ class FileTracer(object): This function will not be invoked if :meth:`has_dynamic_source_filename` returns False. - Returns: - The source filename for this frame, or None if this frame shouldn't - be measured. + Returns the source filename for this frame, or None if this frame + shouldn't be measured. """ return None @@ -142,13 +137,6 @@ class FileTracer(object): from the source file were executed. Return (-1, -1) in this case to tell coverage.py that no lines should be recorded for this frame. - Arguments: - frame: the call frame to examine. - - Returns: - int, int: a pair of line numbers, the start and end lines - executed in the source, inclusive. - """ lineno = frame.f_lineno return lineno, lineno -- cgit v1.2.1 From 9559181fa49011bc94e51c967010e2cb49714d15 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 1 Aug 2015 12:42:04 -0400 Subject: Plugins can get built-in python reporting. --- coverage/plugin.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'coverage/plugin.py') diff --git a/coverage/plugin.py b/coverage/plugin.py index 62cc6dc..5b0479c 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -157,18 +157,18 @@ class FileReporter(object): # Annoying comparison operators. Py3k wants __lt__ etc, and Py2k needs all # of them defined. + def __eq__(self, other): + return isinstance(other, FileReporter) and self.filename == other.filename + + def __ne__(self, other): + return not (self == other) + def __lt__(self, other): return self.filename < other.filename def __le__(self, other): return self.filename <= other.filename - def __eq__(self, other): - return self.filename == other.filename - - def __ne__(self, other): - return self.filename != other.filename - def __gt__(self, other): return self.filename > other.filename -- cgit v1.2.1