Skip to content

Commit

Permalink
Merge pull request #142 from adamtheturtle/logging-skip
Browse files Browse the repository at this point in the history
Only log verbose message if the example will not be skipped
  • Loading branch information
adamtheturtle authored Oct 12, 2024
2 parents 9152aa6 + aa2493c commit d2270ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
Next
----

* Only log ``--verbose`` messages when the relevant example will be run and is not a skip directive.

2024.10.11
----------

Expand Down
13 changes: 11 additions & 2 deletions src/doccmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from beartype import beartype
from pygments.lexers import get_all_lexers
from sybil import Sybil
from sybil.evaluators.skip import Skipper
from sybil.parsers.myst import CodeBlockParser as MystCodeBlockParser
from sybil.parsers.rest import CodeBlockParser as RestCodeBlockParser
from sybil_extras.evaluators.shell_evaluator import ShellCommandEvaluator
Expand All @@ -25,6 +26,7 @@
)

if TYPE_CHECKING:
from sybil.parsers.abstract.skip import AbstractSkipParser
from sybil.typing import Parser

try:
Expand Down Expand Up @@ -105,7 +107,7 @@ def _run_args_against_docs(
)

skip_markers = {*skip_markers, "all"}
skip_parsers: Sequence[Parser] = []
skip_parsers: Sequence[AbstractSkipParser] = []

for skip_marker in skip_markers:
skip_directive = rf"skip doccmd\[{skip_marker}\]"
Expand All @@ -125,7 +127,14 @@ def _run_args_against_docs(
sybil = Sybil(parsers=parsers)
document = sybil.parse(path=file_path)
for example in document.examples():
if verbose:
if (
verbose
and not isinstance(example.region.evaluator, Skipper)
and not any(
skip_parser.skipper.state_for(example=example).remove
for skip_parser in skip_parsers
)
):
command_str = shlex.join(
split_command=[str(item) for item in args],
)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_doccmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,17 @@ def test_verbose(tmp_path: Path) -> None:
x = 2 + 2
assert x == 4
.. skip doccmd[all]: next
.. code-block:: python
x = 3 + 3
assert x == 6
.. code-block:: shell
echo 1
"""
rst_file.write_text(data=content, encoding="utf-8")
arguments = [
Expand Down

0 comments on commit d2270ef

Please sign in to comment.