Skip to content

Commit

Permalink
if source looks like a package add it to source_pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Sep 4, 2020
1 parent c315908 commit 1cf0480
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions coverage/inorout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""

Expand All @@ -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 _IS_PKG_RE.match(src):
self.source_pkgs.append(src)
if os.path.isdir(src):
self.source.append(canonical_filename(src))
else:
self.source_pkgs.append(src)

self.source_pkgs_unmatched = self.source_pkgs[:]

self.omit = prep_patterns(config.run_omit)
Expand Down

0 comments on commit 1cf0480

Please sign in to comment.