Skip to content

Commit

Permalink
Merge pull request #1854 from PyCQA/remove-doctest-options
Browse files Browse the repository at this point in the history
remove --include-in-doctest and --exclude-in-doctest
  • Loading branch information
asottile committed Oct 6, 2023
2 parents fbcde84 + b3e2515 commit faef358
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 142 deletions.
60 changes: 0 additions & 60 deletions docs/source/user/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ Index of Options

- :option:`flake8 --doctests`

- :option:`flake8 --include-in-doctest`

- :option:`flake8 --exclude-from-doctest`

- :option:`flake8 --benchmark`

- :option:`flake8 --bug-report`
Expand Down Expand Up @@ -997,62 +993,6 @@ Options and their Descriptions
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

:ref:`Go back to index <top>`
Expand Down
85 changes: 3 additions & 82 deletions src/flake8/plugins/pyflakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import argparse
import ast
import logging
import os
from typing import Any
from typing import Generator

import pyflakes.checker

from flake8 import utils
from flake8.options.manager import OptionManager

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,34 +66,12 @@ class FlakesChecker(pyflakes.checker.Checker):
"""Subclass the Pyflakes checker to conform with the flake8 API."""

with_doctest = False
include_in_doctest: list[str] = []
exclude_from_doctest: list[str] = []

def __init__(self, tree: ast.AST, filename: str) -> None:
"""Initialize the PyFlakes plugin with an AST tree and filename."""
filename = utils.normalize_path(filename)
with_doctest = 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)
super().__init__(
tree, filename=filename, withDoctest=self.with_doctest
)

@classmethod
def add_options(cls, parser: OptionManager) -> None:
Expand All @@ -113,24 +89,6 @@ def add_options(cls, parser: OptionManager) -> None:
parse_from_config=True,
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
def parse_options(cls, options: argparse.Namespace) -> None:
Expand All @@ -139,43 +97,6 @@ def parse_options(cls, options: argparse.Namespace) -> None:
cls.builtIns = cls.builtIns.union(options.builtins)
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]:
"""Run the plugin."""
for message in self.messages:
Expand Down

0 comments on commit faef358

Please sign in to comment.