Skip to content

Commit

Permalink
Remove debug printing and try to make ruff happy
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Sep 19, 2023
1 parent 2063191 commit eb4f15e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions sphinx_gallery/block_parser.py
Expand Up @@ -74,7 +74,6 @@ def __init__(self, source_file, gallery_conf):

comment_start = "|".join(self.allowed_comments)
allowed_special = "|".join(allowed_special)
print(f"{source_file=}; {comment_start=!r}")
if allowed_special:
self.start_special = re.compile(
f"(?:(?:{comment_start}) ?%% ?|{allowed_special})(.*)"
Expand Down Expand Up @@ -137,8 +136,10 @@ def split_code_and_text_blocks(self, source_file, return_node=False):

def _get_content_lines(self, content):
"""
Combine individual tokens into lines, using the first non-whitespace
token (if any) as the characteristic token type for the line
Combine individual tokens into lines.
Use the first non-whitespace token (if any) as the characteristic token type for
the line.
"""
current_line = []
line_token = pygments.token.Whitespace
Expand All @@ -165,18 +166,16 @@ def _get_content_lines(self, content):

def _get_blocks(self, content):
"""
Generate a sequence of (label, content, line_number) tuples based on the lines
in `content`.
"""
Generate a sequence of "blocks" from the lines in ``content``.
Each block is a tuple of (label, content, line_number), matching the format
ultimately returned by `split_code_and_text_blocks`.
"""
start_text = self.continue_text # No special delimiter needed for first block
needs_multiline_cleanup = False

def cleanup_multiline(lines):
nonlocal needs_multiline_cleanup
print("Cleaining up multiline block:")
print("\n".join(lines))
print("^^^^^^^^^^^^^^^^^^^^^^^^^^")
first_line = 1 if start_text == self.continue_text else 0
longest = max(len(line) for line in lines)
matched = False
Expand Down Expand Up @@ -247,8 +246,8 @@ def finalize_block(mode, block):
elif mode == "text" and token in COMMENT_TYPES:
# Continuation of a text block
if self.start_special.search(text):
print(f"Ignoring: {text!r}")
# Starting a new text block now is just a continuation of the existing one
# Starting a new text block now is just a continuation of the
# existing one
pass
elif token == pygments.token.Comment.Multiline:
if m := self.multiline_end.search(text):
Expand All @@ -273,8 +272,10 @@ def finalize_block(mode, block):

def _split_content(self, content):
"""
Split the input content into blocks and return a tuple of (file_conf, blocks, None)
that corresponds to the return values of ``split_code_and_text_blocks``.
Split the input content into blocks.
Return a tuple of (file_conf, blocks, None) that corresponds to the return
values of ``split_code_and_text_blocks``.
"""
file_conf = self.extract_file_config(content)
blocks = list(self._get_blocks(content))
Expand Down

0 comments on commit eb4f15e

Please sign in to comment.