Skip to content

Commit

Permalink
fix: handle decorators after snakecode (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Mar 15, 2023
1 parent b5aa660 commit 32d6c53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion snakefmt/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def get_next_queriable(self, snakefile: TokenIterator) -> Status:
else:
buffer += TAB * self.effective_indent

if token.type == tokenize.NAME and self.queriable:
if (token.type == tokenize.NAME or token.string == "@") and self.queriable:
self.queriable = False
return Status(
token, block_indent, self.cur_indent, buffer, False, pythonable
Expand Down
16 changes: 16 additions & 0 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ def test_line_wrapped_python_code_inside_rule(self):

assert actual == expected

def test_decorator_is_handled_correctly(self):
"""https://github.com/snakemake/snakefmt/issues/144"""
snakecode = (
"# comment\n"
"rule foo:\n"
f"{TAB * 1}run:\n"
f'{TAB * 2}print("")\n\n\n'
"@contextlib.contextmanager\n"
"def f(wildcards):\n"
f"{TAB * 1}pass\n"
)
formatter = setup_formatter(snakecode)

actual = formatter.get_formatted()
assert actual == snakecode


class TestComplexPythonFormatting:
"""
Expand Down

0 comments on commit 32d6c53

Please sign in to comment.