mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 14:24:17 +00:00
Merge pull request #1854 from PyCQA/remove-doctest-options
remove --include-in-doctest and --exclude-in-doctest
This commit is contained in:
commit
faef358748
2 changed files with 3 additions and 142 deletions
|
|
@ -98,10 +98,6 @@ Index of Options
|
||||||
|
|
||||||
- :option:`flake8 --doctests`
|
- :option:`flake8 --doctests`
|
||||||
|
|
||||||
- :option:`flake8 --include-in-doctest`
|
|
||||||
|
|
||||||
- :option:`flake8 --exclude-from-doctest`
|
|
||||||
|
|
||||||
- :option:`flake8 --benchmark`
|
- :option:`flake8 --benchmark`
|
||||||
|
|
||||||
- :option:`flake8 --bug-report`
|
- :option:`flake8 --bug-report`
|
||||||
|
|
@ -997,62 +993,6 @@ Options and their Descriptions
|
||||||
doctests = True
|
doctests = True
|
||||||
|
|
||||||
|
|
||||||
.. option:: --include-in-doctest=<paths>
|
|
||||||
|
|
||||||
:ref:`Go back to index <top>`
|
|
||||||
|
|
||||||
Specify which files are checked by PyFlakes for doctest syntax.
|
|
||||||
|
|
||||||
This is registered by the default PyFlakes plugin.
|
|
||||||
|
|
||||||
Command-line example:
|
|
||||||
|
|
||||||
.. prompt:: bash
|
|
||||||
|
|
||||||
flake8 --include-in-doctest=dir/subdir/file.py,dir/other/file.py dir/
|
|
||||||
|
|
||||||
This **can** be specified in config files.
|
|
||||||
|
|
||||||
Example config file usage:
|
|
||||||
|
|
||||||
.. code-block:: ini
|
|
||||||
|
|
||||||
include-in-doctest =
|
|
||||||
dir/subdir/file.py,
|
|
||||||
dir/other/file.py
|
|
||||||
include_in_doctest =
|
|
||||||
dir/subdir/file.py,
|
|
||||||
dir/other/file.py
|
|
||||||
|
|
||||||
|
|
||||||
.. option:: --exclude-from-doctest=<paths>
|
|
||||||
|
|
||||||
:ref:`Go back to index <top>`
|
|
||||||
|
|
||||||
Specify which files are not to be checked by PyFlakes for doctest syntax.
|
|
||||||
|
|
||||||
This is registered by the default PyFlakes plugin.
|
|
||||||
|
|
||||||
Command-line example:
|
|
||||||
|
|
||||||
.. prompt:: bash
|
|
||||||
|
|
||||||
flake8 --exclude-from-doctest=dir/subdir/file.py,dir/other/file.py dir/
|
|
||||||
|
|
||||||
This **can** be specified in config files.
|
|
||||||
|
|
||||||
Example config file usage:
|
|
||||||
|
|
||||||
.. code-block:: ini
|
|
||||||
|
|
||||||
exclude-from-doctest =
|
|
||||||
dir/subdir/file.py,
|
|
||||||
dir/other/file.py
|
|
||||||
exclude_from_doctest =
|
|
||||||
dir/subdir/file.py,
|
|
||||||
dir/other/file.py
|
|
||||||
|
|
||||||
|
|
||||||
.. option:: --benchmark
|
.. option:: --benchmark
|
||||||
|
|
||||||
:ref:`Go back to index <top>`
|
:ref:`Go back to index <top>`
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,11 @@ from __future__ import annotations
|
||||||
import argparse
|
import argparse
|
||||||
import ast
|
import ast
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
||||||
import pyflakes.checker
|
import pyflakes.checker
|
||||||
|
|
||||||
from flake8 import utils
|
|
||||||
from flake8.options.manager import OptionManager
|
from flake8.options.manager import OptionManager
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
@ -68,34 +66,12 @@ class FlakesChecker(pyflakes.checker.Checker):
|
||||||
"""Subclass the Pyflakes checker to conform with the flake8 API."""
|
"""Subclass the Pyflakes checker to conform with the flake8 API."""
|
||||||
|
|
||||||
with_doctest = False
|
with_doctest = False
|
||||||
include_in_doctest: list[str] = []
|
|
||||||
exclude_from_doctest: list[str] = []
|
|
||||||
|
|
||||||
def __init__(self, tree: ast.AST, filename: str) -> None:
|
def __init__(self, tree: ast.AST, filename: str) -> None:
|
||||||
"""Initialize the PyFlakes plugin with an AST tree and filename."""
|
"""Initialize the PyFlakes plugin with an AST tree and filename."""
|
||||||
filename = utils.normalize_path(filename)
|
super().__init__(
|
||||||
with_doctest = self.with_doctest
|
tree, filename=filename, withDoctest=self.with_doctest
|
||||||
included_by = [
|
)
|
||||||
include
|
|
||||||
for include in self.include_in_doctest
|
|
||||||
if include != "" and filename.startswith(include)
|
|
||||||
]
|
|
||||||
if included_by:
|
|
||||||
with_doctest = True
|
|
||||||
|
|
||||||
for exclude in self.exclude_from_doctest:
|
|
||||||
if exclude != "" and filename.startswith(exclude):
|
|
||||||
with_doctest = False
|
|
||||||
overlapped_by = [
|
|
||||||
include
|
|
||||||
for include in included_by
|
|
||||||
if include.startswith(exclude)
|
|
||||||
]
|
|
||||||
|
|
||||||
if overlapped_by:
|
|
||||||
with_doctest = True
|
|
||||||
|
|
||||||
super().__init__(tree, filename=filename, withDoctest=with_doctest)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_options(cls, parser: OptionManager) -> None:
|
def add_options(cls, parser: OptionManager) -> None:
|
||||||
|
|
@ -113,24 +89,6 @@ class FlakesChecker(pyflakes.checker.Checker):
|
||||||
parse_from_config=True,
|
parse_from_config=True,
|
||||||
help="also check syntax of the doctests",
|
help="also check syntax of the doctests",
|
||||||
)
|
)
|
||||||
parser.add_option(
|
|
||||||
"--include-in-doctest",
|
|
||||||
default="",
|
|
||||||
dest="include_in_doctest",
|
|
||||||
parse_from_config=True,
|
|
||||||
comma_separated_list=True,
|
|
||||||
normalize_paths=True,
|
|
||||||
help="Run doctests only on these files",
|
|
||||||
)
|
|
||||||
parser.add_option(
|
|
||||||
"--exclude-from-doctest",
|
|
||||||
default="",
|
|
||||||
dest="exclude_from_doctest",
|
|
||||||
parse_from_config=True,
|
|
||||||
comma_separated_list=True,
|
|
||||||
normalize_paths=True,
|
|
||||||
help="Skip these files when running doctests",
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_options(cls, options: argparse.Namespace) -> None:
|
def parse_options(cls, options: argparse.Namespace) -> None:
|
||||||
|
|
@ -139,43 +97,6 @@ class FlakesChecker(pyflakes.checker.Checker):
|
||||||
cls.builtIns = cls.builtIns.union(options.builtins)
|
cls.builtIns = cls.builtIns.union(options.builtins)
|
||||||
cls.with_doctest = options.doctests
|
cls.with_doctest = options.doctests
|
||||||
|
|
||||||
if options.include_in_doctest or options.exclude_from_doctest:
|
|
||||||
LOG.warning(
|
|
||||||
"--include-in-doctest / --exclude-from-doctest will be "
|
|
||||||
"removed in a future version. see PyCQA/flake8#1747"
|
|
||||||
)
|
|
||||||
|
|
||||||
included_files = []
|
|
||||||
for included_file in options.include_in_doctest:
|
|
||||||
if included_file == "":
|
|
||||||
continue
|
|
||||||
if not included_file.startswith((os.sep, "./", "~/")):
|
|
||||||
included_files.append(f"./{included_file}")
|
|
||||||
else:
|
|
||||||
included_files.append(included_file)
|
|
||||||
cls.include_in_doctest = utils.normalize_paths(included_files)
|
|
||||||
|
|
||||||
excluded_files = []
|
|
||||||
for excluded_file in options.exclude_from_doctest:
|
|
||||||
if excluded_file == "":
|
|
||||||
continue
|
|
||||||
if not excluded_file.startswith((os.sep, "./", "~/")):
|
|
||||||
excluded_files.append(f"./{excluded_file}")
|
|
||||||
else:
|
|
||||||
excluded_files.append(excluded_file)
|
|
||||||
cls.exclude_from_doctest = utils.normalize_paths(excluded_files)
|
|
||||||
|
|
||||||
inc_exc = set(cls.include_in_doctest).intersection(
|
|
||||||
cls.exclude_from_doctest
|
|
||||||
)
|
|
||||||
if inc_exc:
|
|
||||||
raise ValueError(
|
|
||||||
f"{inc_exc!r} was specified in both the "
|
|
||||||
f"include-in-doctest and exclude-from-doctest "
|
|
||||||
f"options. You are not allowed to specify it in "
|
|
||||||
f"both for doctesting."
|
|
||||||
)
|
|
||||||
|
|
||||||
def run(self) -> Generator[tuple[int, int, str, type[Any]], None, None]:
|
def run(self) -> Generator[tuple[int, int, str, type[Any]], None, None]:
|
||||||
"""Run the plugin."""
|
"""Run the plugin."""
|
||||||
for message in self.messages:
|
for message in self.messages:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue