Skip to content

Commit

Permalink
fix: line spacing after snakemake keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Nov 8, 2022
1 parent 596bf6e commit beca978
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
30 changes: 3 additions & 27 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion snakefmt/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, snakefile: TokenIterator):
self.snakefile: TokenIterator = snakefile
self.from_python: bool = False
self.last_recognised_keyword: str = ""
self.last_line_is_snakecode = False

status = self.syntax.get_next_queriable(self.snakefile)
self.buffer = status.buffer
Expand Down Expand Up @@ -75,6 +76,7 @@ def __init__(self, snakefile: TokenIterator):
)
self.syntax.code_indent = None
status = self.process_keyword(status, self.from_python)
self.last_line_is_snakecode = True
else:
if not self.syntax.accepts_python_code and not comment_start(keyword):
raise SyntaxError(
Expand All @@ -89,13 +91,18 @@ def __init__(self, snakefile: TokenIterator):
self.syntax.code_indent = status.indent
status = self.syntax.get_next_queriable(self.snakefile)
self.buffer += status.buffer
if self.from_python and status.indent == 0:
if (
self.from_python
and status.indent == 0
and not self.last_line_is_snakecode
):
# This flushes any nested python code following a
# nested snakemake keyword
self.flush_buffer(
from_python=True, in_global_context=self.in_global_context
)
self.from_python = False
self.last_line_is_snakecode = False
self.syntax.cur_indent = status.indent
self.flush_buffer(
from_python=self.from_python,
Expand Down

0 comments on commit beca978

Please sign in to comment.