From 9f0bde77876bf47d9e3f04f26e23cf074e19bb41 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 4 Sep 2020 22:27:07 +0100 Subject: [PATCH 1/2] if a run:source value looks like a package add it to source_pkgs even if it's a dir too --- coverage/inorout.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/coverage/inorout.py b/coverage/inorout.py index ec5f2c1ac..945f9fe94 100644 --- a/coverage/inorout.py +++ b/coverage/inorout.py @@ -7,10 +7,12 @@ import atexit import inspect import itertools +import keyword import os import platform import re import sys +import tokenize import traceback from coverage import env @@ -108,6 +110,14 @@ def module_has_file(mod): return os.path.exists(mod__file__) +_IS_PKG_RE = re.compile( + r"\A(((?!keywords){tokenize.Name})\.?)+\Z".format( + tokenize=tokenize, + keywords="|".join(re.escape(kw) for kw in keyword.kwlist), + ) +) + + class InOrOut(object): """Machinery for determining what files to measure.""" @@ -133,10 +143,11 @@ def __init__(self, warn, debug): def configure(self, config): """Apply the configuration to get ready for decision-time.""" for src in config.source or []: - if os.path.isdir(src): - self.source.append(canonical_filename(src)) - else: + src_is_dir = os.path.isdir(src) + if not src_is_dir or _IS_PKG_RE.match(src): self.source_pkgs.append(src) + if src_is_dir: + self.source.append(canonical_filename(src)) self.source_pkgs_unmatched = self.source_pkgs[:] self.omit = prep_patterns(config.run_omit) From 74bc438d80c6424742a06073c93143909c1eb67c Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 4 Sep 2020 22:37:05 +0100 Subject: [PATCH 2/2] Update coverage/inorout.py --- coverage/inorout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coverage/inorout.py b/coverage/inorout.py index 945f9fe94..1722af396 100644 --- a/coverage/inorout.py +++ b/coverage/inorout.py @@ -111,7 +111,7 @@ def module_has_file(mod): _IS_PKG_RE = re.compile( - r"\A(((?!keywords){tokenize.Name})\.?)+\Z".format( + r"\A(((?!{keywords}){tokenize.Name})\.?)+\Z".format( tokenize=tokenize, keywords="|".join(re.escape(kw) for kw in keyword.kwlist), )