Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank lines removed between Python function and special keywords #38

Closed
enixmail opened this issue Apr 29, 2020 · 8 comments
Closed

Blank lines removed between Python function and special keywords #38

enixmail opened this issue Apr 29, 2020 · 8 comments
Assignees

Comments

@enixmail
Copy link

Note: this was ran from commit bbceeeb

It appears that blanks line are removed between the end of a Python function and special Snakemake keywords.

Given this Snakefile:

from os.path import exists
from os import mkdir


def foo():
    print("Hello World!")


workdir: "data"


localrules: run_all


onstart:
    if not exists("logs"):
        mkdir("logs")


rule run_all:
    output:
        my_output="output.txt",
    shell:
        "touch {output.my_output}"


onsuccess:
    print("Workflow finished, no error")


onerror:
    print("An error occurred")

snakefmt formats it this way:

from os.path import exists
from os import mkdir


def foo():
    print("Hello World!")
workdir: "data"
localrules:
    run_all,
onstart:
    if not exists("logs"):
        mkdir("logs")


rule run_all:
    output:
        my_output="output.txt",
    shell:
        "touch {output.my_output}"


onsuccess:
    print("Workflow finished, no error")
onerror:
    print("An error occurred")

Shouldn't the 2 blank lines separating the foo() function and the workdir keyword be kept?

Also, should the special handlers onstart, onsuccess and onerror be treated like rules and have 2 blank lines before and after?

@johanneskoester
Copy link
Contributor

johanneskoester commented Apr 30, 2020

Yes, please ensure two blank lines between every toplevel item.

@johanneskoester
Copy link
Contributor

cc @mbhall88 @bricoletc

@bricoletc
Copy link
Collaborator

great spot, i'd noticed this too and unhappy with it.

@johanneskoester are you saying there should be two blank lines before workdir but also between workdir and localrules?

@bricoletc bricoletc self-assigned this Apr 30, 2020
@mbhall88
Copy link
Member

mbhall88 commented May 1, 2020

I disagree that there should be two lines between a python function and workdir. Python functions, by convention, should have one line spacing and workdir feels to be more like a normal variable assignment, so

from os.path import exists
from os import mkdir


def foo():
    print("Hello World!")


workdir: "data"


something else

Should be

from os.path import exists
from os import mkdir


def foo():
    print("Hello World!")

workdir: "data"

something else

@enixmail
Copy link
Author

enixmail commented May 1, 2020

PEP8 states clearly "Surround top-level function and class definitions with two blank lines" and "Method definitions inside a class are surrounded by a single blank line". In the example above we are talking about a top level function, so I believe 2 blank lines are required between the end of the foo() function and the workdir directive.

from os.path import exists
from os import mkdir


def foo():
    print("Hello World!")


workdir: "data"

...

@mbhall88
Copy link
Member

mbhall88 commented May 1, 2020

Right you are.

@johanneskoester
Copy link
Contributor

Yes, I agree, two blank lines feel right.

bricoletc added a commit that referenced this issue May 5, 2020
* Triple quoted string formatting only on parameter values (#39)
* Top-level elements trigger two newlines for spacing (#38)
	Elements are python code and snakemake keywords
  With simplified, and added, unit tests
@bricoletc
Copy link
Collaborator

Great. Thanks a lot for bringing this up @enixmail !
Running from 9919e4b the diff from the snakefile you gave at the top of this issue is:

- localrules: run_all
?            --------
+ localrules:
+     run_all,

So the double spacing you suggested is in place.

I'll keep this open for now as it might fuel more discussion.

bricoletc added a commit that referenced this issue May 10, 2020
* Triple quoted string formatting only on parameter values (#39)
* Top-level elements trigger two newlines for spacing (#38)
	Elements are python code and snakemake keywords
  With simplified, and added, unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants