8000 Add --exclude by hauntsaninja · Pull Request #9992 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add --exclude #9992

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

Merged
merged 22 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix logic
  • Loading branch information
hauntsaninja committed Jan 29, 2021
commit ede5ac80b60c9fbcb5dc3ea4cb3844e73dcdf56b
2 changes: 1 addition & 1 deletion mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def check_follow_imports(choice: str) -> str:
'custom_typing_module': str,
'custom_typeshed_dir': expand_path,
'mypy_path': lambda s: [expand_path(p.strip()) for p in re.split('[,:]', s)],
'ignore_path': lambda s: [expand_path(p.strip()) for p in s.split(',')],
'ignore_path': lambda s: [expand_path(p.strip()).replace("/", os.sep) for p in s.split(",")],
'files': split_and_match_files,
'quickstart_file': expand_path,
'junit_xml': expand_path,
Expand Down
4 changes: 2 additions & 2 deletions mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import List, Sequence, Set, Tuple, Optional
from typing_extensions import Final

from mypy.modulefinder import BuildSource, PYTHON_EXTENSIONS, mypy_path
from mypy.modulefinder import BuildSource, PYTHON_EXTENSIONS, mypy_path, matches_ignore_pattern
from mypy.fscache import FileSystemCache
from mypy.options import Options

Expand Down Expand Up @@ -111,7 +111,7 @@ def find_sources_in_dir(self, path: str) -> List[BuildSource]:
):
continue
subpath = os.path.join(path, name)
if any(subpath.endswith(pattern.rstrip("/")) for pattern in self.ignore_path):
if any(matches_ignore_pattern(subpath, pattern) for pattern in self.ignore_path):
continue

if self.fscache.isdir(subpath):
Expand Down
2 changes: 2 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,8 @@ def set_strict_flags() -> None:
if options.logical_deps:
options.cache_fine_grained = True

options.ignore_path = [p.replace("/", os.sep) for p in options.ignore_path]

# Set target.
if special_opts.modules + special_opts.packages:
options.build_type = BuildType.MODULE
Expand Down
11 changes: 10 additions & 1 deletion mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def find_modules_recursive(self, module: str) -> List[BuildSource]:
continue
subpath = os.path.join(package_path, name)
if self.options and any(
subpath.endswith(pattern.rstrip("/")) for pattern in self.options.ignore_path
matches_ignore_pattern(subpath, pattern) for pattern in self.options.ignore_path
):
continue

Expand All @@ -475,6 +475,15 @@ def find_modules_recursive(self, module: str) -> List[BuildSource]:
return sources


def matches_ignore_pattern(path: str, pattern: str) -> bool:
path_components = path.split(os.sep)
pattern_components = pattern.split(os.sep)
return all(
path == pattern
for path, pattern in zip(revers 4F08 ed(path_components), reversed(pattern_components))
)


def verify_module(fscache: FileSystemCache, id: str, path: str, prefix: str) -> bool:
"""Check that all packages containing id have a __init__ file."""
if path.endswith(('__init__.py', '__init__.pyi')):
Expand Down
0