Skip to content

python: reformatted all python scripts with black#322

Merged
sduehr merged 1 commit intobareos:masterfrom
astoorangi:python-reformatting
Nov 28, 2019
Merged

python: reformatted all python scripts with black#322
sduehr merged 1 commit intobareos:masterfrom
astoorangi:python-reformatting

Conversation

@astoorangi
Copy link
Contributor

No description provided.

@astoorangi
Copy link
Contributor Author

Should I reformat all python scripts in the repository or just the templates for the plugins?

@joergsteffens
Copy link
Member

Replacing all single quotes (') by double quotes (") is neither required nor helpful.
I've used yapf to reformat some Python scripts in the past, and yagf formats the code differently to black. We should use only one tool for the reformatting.

I also do not like the changes of python-bareos, as some of the changes make the code less readable and there are some outstanding PRs for that code, so this PR would prevent that the other PRs can be merged.

@pstorz
Copy link
Member

pstorz commented Nov 12, 2019

I think having a common code formatter makes sense.
We have very good experiences doing this on the c and c++ source code.

@sduehr
Copy link
Member

sduehr commented Nov 13, 2019

I was skeptical first, I've always used flake8 and fixed the code manually.
Quick comparision of the yapf and black result for a simple example:

def myfunc(templatefile, path, enable, password, client_name, bareos_gid):
    with open(templatefile, 'r') as f:
        content = f.read()

    t = string.Template(content)
    with os.fdopen(os.open(path, os.O_CREAT | os.O_WRONLY, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP), 'w') as f:
        f.write(t.substitute(enable=enable, password=password, client_name=client_name))
    os.chown(path, -1, bareos_gid)

yapf result:

def myfunc(templatefile, path, enable, password, client_name, bareos_gid):
    with open(templatefile, 'r') as f:
        content = f.read()

    t = string.Template(content)
    with os.fdopen(
            os.open(path, os.O_CREAT | os.O_WRONLY,
                    stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP), 'w') as f:
        f.write(
            t.substitute(enable=enable,
                         password=password,
                         client_name=client_name))
    os.chown(path, -1, bareos_gid)

black result:

def myfunc(templatefile, path, enable, password, client_name, bareos_gid):
    with open(templatefile, "r") as f:
        content = f.read()

    t = string.Template(content)
    with os.fdopen(
        os.open(
            path, os.O_CREAT | os.O_WRONLY, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP
        ),
        "w",
    ) as f:
        f.write(t.substitute(enable=enable, password=password, client_name=client_name))
    os.chown(path, -1, bareos_gid)

I think the black result looks better, in this example it's more obvious that the "w" is a parameter of os.fdopen() and not os.open().

As of https://github.com/psf/black#strings there are some good reasons to standardize on double quotes, however, we could use black --skip-string-normalization first.

I also like that as of https://github.com/psf/black#line-length black defaults to 88 characters per line, personally I'd prefer even longer lines, but there are good reasons to agree on something below 100.

@astoorangi
Copy link
Contributor Author

I also think we should have a formatting standard, I would prefer black for its consistency. Therefore I think the standardization of the quotes makes sense, the reasoning of black for double quotes sounds plausible to me.

@joergsteffens
Copy link
Member

Hi @astoorangi, after some internal discussion, we decided to use the Python formatter black from now on for all Python code in Bareos.
However, I would prefer if you do this pull request again, containing only the code in core, vmware and webui.
I'll take care about the remaining code as soon as #314 is merged.

@astoorangi
Copy link
Contributor Author

Also in docs and regress are some Python scripts (docs/manuals/scripts|source/* and regress/starttime|endtime). Should I reformat them or do you want to do that, @joergsteffens ?

@joergsteffens joergsteffens marked this pull request as ready for review November 28, 2019 09:59
@joergsteffens joergsteffens self-requested a review November 28, 2019 09:59
Copy link
Member

@joergsteffens joergsteffens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me.

@joergsteffens joergsteffens removed their assignment Nov 28, 2019
@joergsteffens joergsteffens requested a review from sduehr November 28, 2019 10:00
@sduehr sduehr merged commit 0ea8d3d into bareos:master Nov 28, 2019
bruno-at-bareos added a commit to bruno-at-bareos/bareos that referenced this pull request Apr 23, 2025
mt-st is no more a default for numerous Linux distributions,
we want to check which mt version is in used on all Linux
platform.

Fix internal issue bareos#322

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
bruno-at-bareos added a commit to bruno-at-bareos/bareos that referenced this pull request Apr 23, 2025
mt-st is no more a default for numerous Linux distributions,
we want to check which mt version is in used on all Linux
platform.

Fix internal issue bareos#322

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
(cherry picked from commit e03daa9)
bruno-at-bareos added a commit to bruno-at-bareos/bareos that referenced this pull request Apr 30, 2025
mt-st is no more a default for numerous Linux distributions,
we want to check which mt version is in used on all Linux
platform. Adapt comment for Linux accordingly.

Fix internal issue bareos#322

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
bruno-at-bareos added a commit to bruno-at-bareos/bareos that referenced this pull request Apr 30, 2025
mt-st is no more a default for numerous Linux distributions,
we want to check which mt version is in used on all Linux
platform. Adapt comment for Linux accordingly.

Fix internal issue bareos#322

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
(cherry picked from commit 4a380cd)
BareosBot pushed a commit to bruno-at-bareos/bareos that referenced this pull request May 14, 2025
mt-st is no more a default for numerous Linux distributions,
we want to check which mt version is in used on all Linux
platform. Adapt comment for Linux accordingly.

Fix internal issue bareos#322

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
BareosBot pushed a commit to bruno-at-bareos/bareos that referenced this pull request May 14, 2025
mt-st is no more a default for numerous Linux distributions,
we want to check which mt version is in used on all Linux
platform. Adapt comment for Linux accordingly.

Fix internal issue bareos#322

Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
(cherry picked from commit 4a380cd)
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

Successfully merging this pull request may close these issues.

4 participants