Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if source looks like a package add it to source_pkgs #1030

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions coverage/inorout.py
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on python3.8 _IS_PKG_RE is

re.compile(r"\A(((?!False|None|True|and|as|assert|async|await|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\w+)\.?)+\Z")

Copy link
Contributor Author

@graingert graingert Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit like:

all(s.isidentifier() and not keyword.iskeyword(s) for s in v.split("."))

but s.isidentifier() is not on python2 and the RE is faster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nedbat something like this?

Suggested change
_IS_PKG_RE = re.compile(
# a dot delimited string of names that are not keywords
_module_name_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 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)
Expand Down