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

[INFRA] Several style fixes (Flake8) for Python code in the repo #872

Merged
merged 2 commits into from
Sep 28, 2021

Conversation

DimitriPapadopoulos
Copy link
Collaborator

The first commit fixes an actual error.

The second commit is about style. I agree style is a question of taste, on the other hand using the standard style does help later maintenance of the code, by other programmers.

Copy link
Collaborator

@Remi-Gau Remi-Gau left a comment

Choose a reason for hiding this comment

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

OK with me.

Tempted to add some flake8 check into CI to be honest.

Would be tempted to push for using Black but I don't want to start a linter war.

@sappelhoff
Copy link
Member

Tempted to add some flake8 check into CI to be honest.

+1, that'd be more efficient

Would be tempted to push for using Black but I don't want to start a linter war.

+1 for black :-)

Copy link
Member

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

@DimitriPapadopoulos could you please elaborate on what error you fixed, and what the situation was BEFORE versus AFTER the fix? Preferably with screenshots and/or lines of code? :-)

@DimitriPapadopoulos
Copy link
Collaborator Author

I seem to recall haven't fixed all flake8 issues, only those that I felt were the most relevant for readability. So why not add flake8 to CI, but perhaps disable a few errors - or not.

I find black really too intrusive - besides there are forks such as oitnb for that very reason (for example accept 'string' instead of "string").

@DimitriPapadopoulos
Copy link
Collaborator Author

DimitriPapadopoulos commented Sep 13, 2021

BEFORE (111 issues)

./tools/pull_files.py:16:80: E501 line too long (106 > 79 characters)
./tools/pull_files.py:23:80: E501 line too long (95 > 79 characters)
./tools/pull_files.py:39:80: E501 line too long (98 > 79 characters)
./tools/no-bad-latin.py:3:80: E501 line too long (100 > 79 characters)
./tools/no-bad-latin.py:28:80: E501 line too long (81 > 79 characters)
./tools/no-bad-latin.py:36:1: W191 indentation contains tabs
./tools/no-bad-latin.py:36:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:38:1: W191 indentation contains tabs
./tools/no-bad-latin.py:39:1: W191 indentation contains tabs
./tools/no-bad-latin.py:41:1: W191 indentation contains tabs
./tools/no-bad-latin.py:42:1: W191 indentation contains tabs
./tools/no-bad-latin.py:43:1: W191 indentation contains tabs
./tools/no-bad-latin.py:44:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:51:1: W191 indentation contains tabs
./tools/no-bad-latin.py:51:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:52:1: W191 indentation contains tabs
./tools/no-bad-latin.py:53:1: W191 indentation contains tabs
./tools/no-bad-latin.py:55:1: W191 indentation contains tabs
./tools/no-bad-latin.py:56:1: W191 indentation contains tabs
./tools/no-bad-latin.py:57:1: W191 indentation contains tabs
./tools/no-bad-latin.py:58:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:64:1: W191 indentation contains tabs
./tools/no-bad-latin.py:64:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:66:1: W191 indentation contains tabs
./tools/no-bad-latin.py:67:1: W191 indentation contains tabs
./tools/no-bad-latin.py:68:1: W191 indentation contains tabs
./tools/no-bad-latin.py:68:3: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:70:1: W191 indentation contains tabs
./tools/no-bad-latin.py:71:1: W191 indentation contains tabs
./tools/no-bad-latin.py:72:1: W191 indentation contains tabs
./tools/no-bad-latin.py:73:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:77:80: E501 line too long (103 > 79 characters)
./tools/no-bad-latin.py:85:1: W191 indentation contains tabs
./tools/no-bad-latin.py:85:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:87:1: W191 indentation contains tabs
./tools/no-bad-latin.py:88:1: W191 indentation contains tabs
./tools/no-bad-latin.py:90:1: W191 indentation contains tabs
./tools/no-bad-latin.py:91:1: W191 indentation contains tabs
./tools/no-bad-latin.py:92:1: W191 indentation contains tabs
./tools/no-bad-latin.py:92:3: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:93:1: W191 indentation contains tabs
./tools/no-bad-latin.py:93:5: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:94:1: W191 indentation contains tabs
./tools/no-bad-latin.py:94:5: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:95:1: W191 indentation contains tabs
./tools/no-bad-latin.py:96:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:109:17: E122 continuation line missing indentation or outdented
./tools/no-bad-latin.py:110:17: E122 continuation line missing indentation or outdented
./tools/no-bad-latin.py:131:1: W191 indentation contains tabs
./tools/no-bad-latin.py:131:1: E101 indentation contains mixed spaces and tabs
./tools/no-bad-latin.py:132:1: W191 indentation contains tabs
./tools/no-bad-latin.py:134:1: W191 indentation contains tabs
./tools/no-bad-latin.py:135:1: W191 indentation contains tabs
./tools/no-bad-latin.py:136:1: W191 indentation contains tabs
./tools/no-bad-latin.py:137:1: E101 indentation contains mixed spaces and tabs
./tools/schemacode/schema.py:47:80: E501 line too long (82 > 79 characters)
./tools/schemacode/schema.py:179:80: E501 line too long (83 > 79 characters)
./tools/schemacode/schema.py:463:80: E501 line too long (82 > 79 characters)
./tools/schemacode/utils.py:18:80: E501 line too long (87 > 79 characters)
./tools/schemacode/utils.py:42:80: E501 line too long (80 > 79 characters)
./tools/mkdocs_macros_bids/macros.py:8:1: E402 module level import not at top of file
./tools/mkdocs_macros_bids/macros.py:9:1: E402 module level import not at top of file
./tools/mkdocs_macros_bids/main.py:13:1: E402 module level import not at top of file
./tools/examplecode/example.py:12:1: E302 expected 2 blank lines, found 1
./tools/examplecode/example.py:74:80: E501 line too long (85 > 79 characters)
./pdf_build_src/pandoc_script.py:60:80: E501 line too long (82 > 79 characters)
./pdf_build_src/process_markdowns.py:75:80: E501 line too long (91 > 79 characters)
./pdf_build_src/process_markdowns.py:117:80: E501 line too long (81 > 79 characters)
./pdf_build_src/process_markdowns.py:156:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:157:80: E501 line too long (84 > 79 characters)
./pdf_build_src/process_markdowns.py:166:80: E501 line too long (101 > 79 characters)
./pdf_build_src/process_markdowns.py:167:80: E501 line too long (97 > 79 characters)
./pdf_build_src/process_markdowns.py:174:80: E501 line too long (102 > 79 characters)
./pdf_build_src/process_markdowns.py:186:80: E501 line too long (89 > 79 characters)
./pdf_build_src/process_markdowns.py:188:80: E501 line too long (80 > 79 characters)
./pdf_build_src/process_markdowns.py:193:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:198:80: E501 line too long (110 > 79 characters)
./pdf_build_src/process_markdowns.py:202:80: E501 line too long (84 > 79 characters)
./pdf_build_src/process_markdowns.py:207:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:209:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:210:80: E501 line too long (91 > 79 characters)
./pdf_build_src/process_markdowns.py:211:80: E501 line too long (93 > 79 characters)
./pdf_build_src/process_markdowns.py:238:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:241:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:244:80: E501 line too long (95 > 79 characters)
./pdf_build_src/process_markdowns.py:247:80: E501 line too long (95 > 79 characters)
./pdf_build_src/process_markdowns.py:249:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:266:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:277:80: E501 line too long (81 > 79 characters)
./pdf_build_src/process_markdowns.py:278:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:290:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:291:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:325:80: E501 line too long (87 > 79 characters)
./pdf_build_src/process_markdowns.py:326:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:327:80: E501 line too long (89 > 79 characters)
./pdf_build_src/process_markdowns.py:328:80: E501 line too long (100 > 79 characters)
./pdf_build_src/process_markdowns.py:336:80: E501 line too long (81 > 79 characters)
./pdf_build_src/process_markdowns.py:340:80: E501 line too long (94 > 79 characters)
./pdf_build_src/process_markdowns.py:343:80: E501 line too long (87 > 79 characters)
./pdf_build_src/process_markdowns.py:358:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:359:80: E501 line too long (101 > 79 characters)
./pdf_build_src/process_markdowns.py:361:80: E501 line too long (95 > 79 characters)
./pdf_build_src/process_markdowns.py:363:80: E501 line too long (84 > 79 characters)
./pdf_build_src/process_markdowns.py:380:80: E501 line too long (84 > 79 characters)
./pdf_build_src/process_markdowns.py:383:80: E501 line too long (86 > 79 characters)
./pdf_build_src/process_markdowns.py:385:80: E501 line too long (101 > 79 characters)
./pdf_build_src/process_markdowns.py:403:27: W605 invalid escape sequence '\l'
./pdf_build_src/process_markdowns.py:405:19: W605 invalid escape sequence '\l'
./pdf_build_src/process_markdowns.py:459:21: E122 continuation line missing indentation or outdented
./pdf_build_src/process_markdowns.py:460:21: E122 continuation line missing indentation or outdented
./pdf_build_src/process_markdowns.py:503:80: E501 line too long (87 > 79 characters)

AFTER (60 issues)

./tools/pull_files.py:16:80: E501 line too long (106 > 79 characters)
./tools/pull_files.py:23:80: E501 line too long (95 > 79 characters)
./tools/pull_files.py:39:80: E501 line too long (98 > 79 characters)
./tools/no-bad-latin.py:3:80: E501 line too long (100 > 79 characters)
./tools/no-bad-latin.py:28:80: E501 line too long (81 > 79 characters)
./tools/no-bad-latin.py:77:80: E501 line too long (103 > 79 characters)
./tools/schemacode/schema.py:47:80: E501 line too long (82 > 79 characters)
./tools/schemacode/schema.py:179:80: E501 line too long (83 > 79 characters)
./tools/schemacode/schema.py:463:80: E501 line too long (82 > 79 characters)
./tools/schemacode/utils.py:18:80: E501 line too long (87 > 79 characters)
./tools/schemacode/utils.py:42:80: E501 line too long (80 > 79 characters)
./tools/mkdocs_macros_bids/macros.py:8:1: E402 module level import not at top of file
./tools/mkdocs_macros_bids/macros.py:9:1: E402 module level import not at top of file
./tools/mkdocs_macros_bids/main.py:13:1: E402 module level import not at top of file
./tools/examplecode/example.py:75:80: E501 line too long (85 > 79 characters)
./pdf_build_src/pandoc_script.py:60:80: E501 line too long (82 > 79 characters)
./pdf_build_src/process_markdowns.py:68:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:75:80: E501 line too long (91 > 79 characters)
./pdf_build_src/process_markdowns.py:117:80: E501 line too long (81 > 79 characters)
./pdf_build_src/process_markdowns.py:156:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:157:80: E501 line too long (84 > 79 characters)
./pdf_build_src/process_markdowns.py:166:80: E501 line too long (101 > 79 characters)
./pdf_build_src/process_markdowns.py:167:80: E501 line too long (97 > 79 characters)
./pdf_build_src/process_markdowns.py:174:80: E501 line too long (102 > 79 characters)
./pdf_build_src/process_markdowns.py:186:80: E501 line too long (89 > 79 characters)
./pdf_build_src/process_markdowns.py:188:80: E501 line too long (80 > 79 characters)
./pdf_build_src/process_markdowns.py:193:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:198:80: E501 line too long (110 > 79 characters)
./pdf_build_src/process_markdowns.py:202:80: E501 line too long (84 > 79 characters)
./pdf_build_src/process_markdowns.py:207:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:209:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:210:80: E501 line too long (91 > 79 characters)
./pdf_build_src/process_markdowns.py:211:80: E501 line too long (93 > 79 characters)
./pdf_build_src/process_markdowns.py:238:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:241:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:244:80: E501 line too long (95 > 79 characters)
./pdf_build_src/process_markdowns.py:247:80: E501 line too long (95 > 79 characters)
./pdf_build_src/process_markdowns.py:249:80: E501 line too long (96 > 79 characters)
./pdf_build_src/process_markdowns.py:266:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:277:80: E501 line too long (81 > 79 characters)
./pdf_build_src/process_markdowns.py:278:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:290:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:291:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:325:80: E501 line too long (87 > 79 characters)
./pdf_build_src/process_markdowns.py:326:80: E501 line too long (85 > 79 characters)
./pdf_build_src/process_markdowns.py:327:80: E501 line too long (89 > 79 characters)
./pdf_build_src/process_markdowns.py:328:80: E501 line too long (102 > 79 characters)
./pdf_build_src/process_markdowns.py:336:80: E501 line too long (81 > 79 characters)
./pdf_build_src/process_markdowns.py:340:80: E501 line too long (94 > 79 characters)
./pdf_build_src/process_markdowns.py:343:80: E501 line too long (87 > 79 characters)
./pdf_build_src/process_markdowns.py:358:80: E501 line too long (83 > 79 characters)
./pdf_build_src/process_markdowns.py:359:80: E501 line too long (101 > 79 characters)
./pdf_build_src/process_markdowns.py:361:80: E501 line too long (95 > 79 characters)
./pdf_build_src/process_markdowns.py:363:80: E501 line too long (84 > 79 characters)
./pdf_build_src/process_markdowns.py:380:80: E501 line too long (86 > 79 characters)
./pdf_build_src/process_markdowns.py:383:80: E501 line too long (88 > 79 characters)
./pdf_build_src/process_markdowns.py:385:80: E501 line too long (101 > 79 characters)
./pdf_build_src/process_markdowns.py:459:21: E122 continuation line missing indentation or outdented
./pdf_build_src/process_markdowns.py:460:21: E122 continuation line missing indentation or outdented
./pdf_build_src/process_markdowns.py:503:80: E501 line too long (87 > 79 characters)

@DimitriPapadopoulos
Copy link
Collaborator Author

If you disregard E501, that's 81 issues BEFORE and 12 issues AFTER:

./tools/mkdocs_macros_bids/macros.py:8:1: E402 module level import not at top of file
./tools/mkdocs_macros_bids/macros.py:9:1: E402 module level import not at top of file
./tools/mkdocs_macros_bids/main.py:13:1: E402 module level import not at top of file
./pdf_build_src/process_markdowns.py:403:60: W504 line break after binary operator
./pdf_build_src/process_markdowns.py:404:31: W504 line break after binary operator
./pdf_build_src/process_markdowns.py:405:29: W504 line break after binary operator
./pdf_build_src/process_markdowns.py:406:28: W504 line break after binary operator
./pdf_build_src/process_markdowns.py:407:21: W504 line break after binary operator
./pdf_build_src/process_markdowns.py:408:29: W504 line break after binary operator
./pdf_build_src/process_markdowns.py:409:27: W504 line break after binary operator
./pdf_build_src/process_markdowns.py:459:21: E122 continuation line missing indentation or outdented
./pdf_build_src/process_markdowns.py:460:21: E122 continuation line missing indentation or outdented

@sappelhoff
Copy link
Member

I find black really too intrusive - besides there are forks such as oitnb for that very reason (for example accept 'string' instead of "string").

there we have our linter war 🎉 🙂

Maybe a simple flake8 checker will suffice for now then. Eventually, most of the code currently in this repo will be migrated to their own repos.

@DimitriPapadopoulos
Copy link
Collaborator Author

DimitriPapadopoulos commented Sep 13, 2021

Oh, there's no linter war here 😄 I can adapt to any style, as long as I find it readable. Oh wait! That's not the case for black, but it's not totally unreadable either, so I can live with it. Whatever you prefer.

The real issue here is minimizing changes so as not to pollute the git log too much with stylistic issues. It's OK to run black on new projects, but it's too intrusive for existing projects. At least with flake8 you can disable errors such as E501 to avoid changing too much code at once.

@sappelhoff
Copy link
Member

yes, sounds good to me 👍

@tsalo
Copy link
Member

tsalo commented Sep 13, 2021

At least for schemacode, I'd like to use black's convention. That has a default maximum line length of 99, so I'm not concerned with E501 there.

EDIT: @DimitriPapadopoulos I just saw your comment about black 😆

@sappelhoff sappelhoff changed the title [INFRA] Flake8 [INFRA] Several style fixes (Flake8) for Python code in the repo Sep 15, 2021
@DimitriPapadopoulos
Copy link
Collaborator Author

I can run black on schemacode or all Python files if you want me too. Perhaps in another PR?

@sappelhoff
Copy link
Member

I can run black on schemacode or all Python files if you want me too. Perhaps in another PR?

from my side yes, I like BLACK and believe it delivers the advantages it promises. But if we do that, we also need to add a CI check for black formatting --> and that might be ugly for new contributors (need to install and run an additional package; or need to download and install a pre-commit hook). So maybe overall I am 50 50 on this

@DimitriPapadopoulos
Copy link
Collaborator Author

Then schemacode only? These are rather simple files, I don't expect too many changes. Actually, there are just 10 changes in tools/schemacode/__init__.py.

@satra
Copy link
Collaborator

satra commented Sep 15, 2021

just a note that for some of our other projects we use pre-commit.ci which is a service that integrates with github and automatically runs whichever precommits you configure. this may help alleviate user configuration. but they will have to download the updated branch to continue. however, that service helps a lot for github based edits, which is often the case now for many suggestions.

@sappelhoff
Copy link
Member

Thanks @satra for bringing this up, I remember @Remi-Gau thinking about that as well.

I am tempted to just merge this PR, and if people care deeply about this - continue the discussion in a dedicated issue, before we make changes.

The commits here contain one bugfix next to the style fixes, so they should not stay unmerged for so long :-)

@Remi-Gau
Copy link
Collaborator

Thanks @satra for bringing this up, I remember @Remi-Gau thinking about that as well.

I am tempted to just merge this PR, and if people care deeply about this - continue the discussion in a dedicated issue, before we make changes.

The commits here contain one bugfix next to the style fixes, so they should not stay unmerged for so long :-)

OK to merge and move black styling + pre-commit to another issue.

@sappelhoff sappelhoff merged commit 98d7af6 into bids-standard:master Sep 28, 2021
@sappelhoff
Copy link
Member

Thanks @DimitriPapadopoulos

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.

5 participants