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
rename --ignore-path to --exclude
  • Loading branch information
hauntsaninja committed Feb 2, 2021
commit 32c7f7c432910e37f1cc41d9b16c2b409cfd86c0
4 changes: 2 additions & 2 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ for full details, see :ref:`running-mypy`.
Asks mypy to type check the provided string as a program.


.. option:: --ignore-path
.. option:: --exclude

Asks mypy to ignore a given file name, directory name or subpath while
Asks mypy to exclude a given file name, directory name or subpath while
recursively discovering files to check. This flag may be repeated multiple
times.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ section of the command line docs.

This option may only be set in the global section (``[mypy]``).

.. confval:: ignore_path
.. confval:: exclude

:type: comma-separated list of strings

Expand Down
2 changes: 1 addition & 1 deletion docs/source/running_mypy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ to modules to type check.

- Mypy will recursively discover and check all files ending in ``.py`` or
``.pyi`` in directory paths provided, after accounting for
:option:`--ignore-path <mypy --ignore-path>`.
:option:`--exclude <mypy --exclude>`.

- For each file to be checked, mypy will attempt to associate the file (e.g.
``project/foo/bar/baz.py``) with a fully qualified module name (e.g.
Expand Down
2 changes: 1 addition & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
)
manager.errors.report(
-1, -1,
"Are you missing an __init__.py? Alternatively, consider using --ignore-path to "
"Are you missing an __init__.py? Alternatively, consider using --exclude to "
"avoid checking one of them.",
severity='note'
)
Expand Down
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(",")],
'exclude': lambda s: [expand_path(p.strip()) for p in s.split(",")],
'files': split_and_match_files,
'quickstart_file': expand_path,
'junit_xml': expand_path,
Expand Down
6 changes: 3 additions & 3 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, matches_ignore_pattern
from mypy.modulefinder import BuildSource, PYTHON_EXTENSIONS, mypy_path, matches_exclude_pattern
from mypy.fscache import FileSystemCache
from mypy.options import Options

Expand Down Expand Up @@ -91,7 +91,7 @@ def __init__(self, fscache: FileSystemCache, options: Options) -> None:
self.fscache = fscache
self.explicit_package_bases = get_explicit_package_bases(options)
self.namespace_packages = options.namespace_packages
self.ignore_path = options.ignore_path
self.exclude = options.exclude

def is_explicit_package_base(self, path: str) -> bool:
assert self.explicit_package_bases
Expand All @@ -111,7 +111,7 @@ def find_sources_in_dir(self, path: str) -> List[BuildSource]:
):
continue
subpath = os.path.join(path, name)
if any(matches_ignore_pattern(subpath, pattern) for pattern in self.ignore_path):
if any(matches_exclude_pattern(subpath, pattern) for pattern in self.exclude):
continue

if self.fscache.isdir(subpath):
Expand Down
2 changes: 1 addition & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def add_invertible_flag(flag: str,
'--explicit-package-bases', action='store_true',
help="Use current directory and MYPYPATH to determine module names of files passed")
code_group.add_argument(
"--ignore-path",
"--exclude",
metavar="PATH",
action="append",
default=[],
Expand Down
4 changes: 2 additions & 2 deletions 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(
matches_ignore_pattern(subpath, pattern) for pattern in self.options.ignore_path
matches_exclude_pattern(subpath, pattern) for pattern in self.options.exclude
):
continue

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


def matches_ignore_pattern(path: str, pattern: str) -> bool:
def matches_exclude_pattern(path: str, pattern: str) -> bool:
path = os.path.splitdrive(path)[1]
path_components = path.split(os.sep)
pattern_components = pattern.replace(os.sep, "/").split("/")
Expand Down
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self) -> None:
# top-level __init__.py to your packages.
self.explicit_package_bases = False
# File names, directory names or subpaths to avoid checking
self.ignore_path = [] # type: List[str]
self.exclude = [] # type: List[str]

# disallow_any options
self.disallow_any_generics = False
Expand Down
14 changes: 7 additions & 7 deletions mypy/test/test_find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_find_sources_namespace_multi_dir(self) -> None:
finder = SourceFinder(FakeFSCache({"/a/pkg/a.py", "/b/pkg/b.py"}), options)
assert find_sources(finder, "/") == [("pkg.a", "/a"), ("pkg.b", "/b")]

def test_find_sources_ignore_path(self) -> None:
def test_find_sources_exclude(self) -> None:
options = Options()
options.namespace_packages = True

Expand All @@ -270,7 +270,7 @@ def test_find_sources_ignore_path(self) -> None:
}

# file name
options.ignore_path = ["f.py"]
options.exclude = ["f.py"]
finder = SourceFinder(FakeFSCache(files), options)
assert find_sources(finder, "/") == [
("a2", "/pkg"),
Expand All @@ -279,7 +279,7 @@ def test_find_sources_ignore_path(self) -> None:
]

# directory name
options.ignore_path = ["a1"]
options.exclude = ["a1"]
finder = SourceFinder(FakeFSCache(files), options)
assert find_sources(finder, "/") == [
("a2", "/pkg"),
Expand All @@ -288,15 +288,15 @@ def test_find_sources_ignore_path(self) -> None:
]

# paths
options.ignore_path = ["/pkg/a1"]
options.exclude = ["/pkg/a1"]
finder = SourceFinder(FakeFSCache(files), options)
assert find_sources(finder, "/") == [
("a2", "/pkg"),
("a2.b.c.d.e", "/pkg"),
("a2.b.f", "/pkg"),
]

options.ignore_path = ["b/c"]
options.exclude = ["b/c"]
finder = SourceFinder(FakeFSCache(files), options)
assert find_sources(finder, "/") == [
("a2", "/pkg"),
Expand All @@ -305,7 +305,7 @@ def test_find_sources_ignore_path(self) -> None:
]

# nothing should be ignored as a result of this
options.ignore_path = [
options.exclude = [
"/pkg/a", "2", "1", "pk", "kg", "g.py", "bc", "/b", "/xxx/pkg/a2/b/f.py"
"xxx/pkg/a2/b/f.py"
]
Expand All @@ -320,7 +320,7 @@ def test_find_sources_ignore_path(self) -> None:
"pkg/a2/b/c/d/e.py",
"pkg/a2/b/f.py",
}
options.ignore_path = [
options.exclude = [
"/pkg/a", "2", "1", "pk", "kg", "g.py", "bc", "/b", "/xxx/pkg/a2/b/f.py",
"xxx/pkg/a2/b/f.py", "/pkg/a1", "/pkg/a2"
]
Expand Down
2 changes: 1 addition & 1 deletion mypy_self_check.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pretty = True
always_false = MYPYC
plugins = misc/proper_plugin.py
python_version = 3.5
ignore_path = mypy/typeshed
exclude = mypy/typeshed
4 changes: 2 additions & 2 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ undef
undef
[out]
dir/a.py: error: Duplicate module named 'a' (also at 'dir/subdir/a.py')
dir/a.py: note: Are you missing an __init__.py? Alternatively, consider using --ignore-path to avoid checking one of them.
dir/a.py: note: Are you missing an __init__. 6B8E py? Alternatively, consider using --exclude to avoid checking one of them.
== Return code: 2

[case testCmdlineNonPackageSlash]
Expand Down Expand Up @@ -125,7 +125,7 @@ mypy: can't decode file 'a.py': unknown encoding: uft-8
# type: ignore
[out]
two/mod/__init__.py: error: Duplicate module named 'mod' (also at 'one/mod/__init__.py')
two/mod/__init__.py: note: Are you missing an __init__.py? Alternatively, consider using --ignore-path to avoid checking one of them.
two/mod/__init__.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
== Return code: 2

[case testFlagsFile]
Expand Down
0