phys2bids icon indicating copy to clipboard operation
phys2bids copied to clipboard

Use black formatting rules for linting in CI

Open tsalo opened this issue 3 years ago • 9 comments

Closes #324.

Proposed Changes

  • Change flake8 dependency to flake8-black. Calling flake8 in the CI will use flake8-black automatically.
  • Ignore E203 (whitespace before ':'), which flake8 flags, but which is actually not PEP8 compliant. See here for an explanation.

tsalo avatar Oct 21 '20 18:10 tsalo

There are surprisingly few style issues, which is nice to see!

@smoia, do you want to use isort as well? There's a flake8-isort plugin that could be added to the dependencies, and I think we'd need some isort-specific settings in setup.cfg to fit with black.

EDIT: Given that we don't want to let PRs sprawl, I think it would be good to open a separate PR (to be merged before this one) in which black is run on the whole repository. WDYT?

tsalo avatar Oct 21 '20 18:10 tsalo

Thank you @tsalo ! It's great to see we were already close to the style required by black.

EDIT: Given that we don't want to let PRs sprawl, I think it would be good to open a separate PR (to be merged before this one) in which black is run on the whole repository. WDYT?

I'd open a separate PR.

eurunuela avatar Oct 21 '20 19:10 eurunuela

Ok, one quick thought about this. I thought we were going to add a CI job to run black during PR merge.

This solution obliges the user to run black locally instead. I don't love the idea, mainly because it complicates (a little, but still complicates) the process of contributing to the repos - it might scare contributors away (especially new ones) or force them to adopt black during coding. Can we check if setting up a CI action (actually, adding a job in the autorelease GH action would be better) is feasible?

smoia avatar Oct 21 '20 21:10 smoia

I considered using the black GitHub Action in NiMARE, but I was wary to give an Action the ability to directly commit to folks' pull requests. I chose to just use a stricter linter in that situation. It doesn't require contributors to run black (they could just fix things manually if they wanted), but it does flag poorly formatted code.

That said, it's up to you. I can try switching things out with an Action, but I honestly think you'd be the best person to set it up. I don't use Actions much (if at all), and the last time I tried it messed up my local repo.

tsalo avatar Oct 21 '20 23:10 tsalo

I see - and understand the warning you're raising. This might be worth discussing between developers (next meeting or back in #324).

I don't love to force users to adopt opinionated code formatters (or even worse a very opinionated code style) locally, honestly. This is because I'd be the first to be pushed away if I had to. Since I'll hardly adopt double quotes or line splitting during coding, I know I won't adjust things manually. I can run black before readying a PR for review, but if I need to work on the code again after a review I would be disoriented, making the process a bit more bothersome. I might even end up committing, running black and re-commiting. Uff (and I know a couple of physiopy contributors that might be even more exasperated by this). Besides, new users might already overcome the challenge of understanding the library, (possibly) learn and code in python, install or run an easy-peasy linter (still problematic for some of the more expert contributors), possibly add documentation and tests. Asking to adopt a strict format or run black might be a bit too much. Especially since we're not talking about unreadable vs readable code - IMMO "simple" flake8 is not a poorly formatted code, and going through #328 I find blackened code less clear than the previous version (I know it's a matter of habit).

However, if @physiopy/all prefer to run black locally before PR, we can do that - let's keep the discussion flowing.

smoia avatar Oct 21 '20 23:10 smoia

However, if @physiopy/all prefer to run black locally before PR, we can do that - let's keep the discussion flowing.

I'd rather have the linter tell us what to change. I think asking contributors to run black locally is a bit too much. I think we should make our lives easier and not complicate our contributions too much!

eurunuela avatar Oct 26 '20 14:10 eurunuela

What if we discuss this in the upcoming meeting? We can start the agenda now, given that it's next week.

smoia avatar Oct 26 '20 14:10 smoia

Where did we land on this? Should I close?

tsalo avatar Feb 06 '21 18:02 tsalo

Sorry @tsalo, I've been pretty busy with the rest of my commitments. I need just a bit more time to work on this!

smoia avatar Feb 11 '21 15:02 smoia

Hey @tsalo! Would you still be interested in following the black-ification of the library? If so, the library changed a little, so could you rebase on the latest master?

After that, we can implement pre-commits to automatically run isort and black on the files.

smoia avatar Nov 29 '22 10:11 smoia

I'm happy to give it a try. I'll try to fix up this PR later today.

tsalo avatar Nov 30 '22 14:11 tsalo

Thank you!

smoia avatar Nov 30 '22 16:11 smoia

Codecov Report

Merging #327 (ac03c5c) into master (d3a7443) will increase coverage by 0.17%. The diff coverage is n/a.

:exclamation: Current head ac03c5c differs from pull request most recent head e3496d7. Consider uploading reports for the commit e3496d7 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #327      +/-   ##
==========================================
+ Coverage   94.25%   94.42%   +0.17%     
==========================================
  Files           8        8              
  Lines         974      879      -95     
==========================================
- Hits          918      830      -88     
+ Misses         56       49       -7     

see 6 files with indirect coverage changes

codecov[bot] avatar Dec 01 '22 16:12 codecov[bot]

Let me know when you want me to review to merge!

BTW, I'm going to configure Pre Commit on all Physiopy packages, so if you want to go ahead and add it here too, I'm following this configuration with this setup from our repository template

smoia avatar Dec 02 '22 07:12 smoia

@smoia I added the pre-commit config, but I've never used pre-commit before. Is adding the config file enough?

tsalo avatar Dec 14 '22 13:12 tsalo

Hey @tsalo! On your side it should be sufficient, although you may want to activate it locally. On my side, I just allowed pre-commit to run on phys2bids.

pre-commit.ci run

smoia avatar Dec 14 '22 16:12 smoia

And now it's running!

smoia avatar Dec 14 '22 16:12 smoia

Oh, and we're not doing checks on tests, at least for docstrings.

smoia avatar Dec 14 '22 16:12 smoia

@tsalo I tried to update this PR in order to merge it, but I get an error I can't figure out on the style check.

Locally, isort and black skip all files. Remotely, something isn't happy.

Do you have ideas on why?

smoia avatar Apr 27 '23 00:04 smoia

Ok, problem found. It was "just" a black version issue.

smoia avatar Apr 27 '23 00:04 smoia