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

Adopt Black and isort #327

Merged
merged 12 commits into from
Apr 27, 2023
Merged

Adopt Black and isort #327

merged 12 commits into from
Apr 27, 2023

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Oct 21, 2020

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 tsalo added the Internal Changes affect the internal API. It doesn't increase the version, but produces a changelog label Oct 21, 2020
@tsalo tsalo requested a review from smoia October 21, 2020 18:35
@tsalo
Copy link
Member Author

tsalo commented Oct 21, 2020

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?

@eurunuela
Copy link
Collaborator

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.

@smoia smoia self-assigned this Oct 21, 2020
@smoia
Copy link
Member

smoia commented Oct 21, 2020

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?

@tsalo
Copy link
Member Author

tsalo commented Oct 21, 2020

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.

@smoia
Copy link
Member

smoia commented Oct 21, 2020

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.

@eurunuela
Copy link
Collaborator

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!

@smoia
Copy link
Member

smoia commented Oct 26, 2020

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

@tsalo
Copy link
Member Author

tsalo commented Feb 6, 2021

Where did we land on this? Should I close?

@smoia
Copy link
Member

smoia commented Feb 11, 2021

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
Copy link
Member

smoia commented Nov 29, 2022

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.

@tsalo
Copy link
Member Author

tsalo commented Nov 30, 2022

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

@smoia
Copy link
Member

smoia commented Nov 30, 2022

Thank you!

@codecov
Copy link

codecov bot commented Dec 1, 2022

Codecov Report

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

❗ 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

@smoia
Copy link
Member

smoia commented Dec 2, 2022

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

@tsalo
Copy link
Member Author

tsalo commented Dec 14, 2022

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

@smoia
Copy link
Member

smoia commented Dec 14, 2022

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
Copy link
Member

smoia commented Dec 14, 2022

And now it's running!

Copy link
Member

@smoia smoia left a comment

Choose a reason for hiding this comment

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

Hey, I trust you're checking the results of the format.

If I can ask you, there's a couple of things we didn't want to automatically format. There are also a couple of issues with strings and if you could set it up to ignore configuration files, that'd be great!

@@ -11,45 +11,90 @@
LGR = logging.getLogger(__name__)
Copy link
Member

Choose a reason for hiding this comment

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

If I remember correctly, we wanted not to auto-format the two aliases dictionaries

@smoia
Copy link
Member

smoia commented Dec 14, 2022

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

@smoia
Copy link
Member

smoia commented Apr 27, 2023

@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
Copy link
Member

smoia commented Apr 27, 2023

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

@smoia smoia marked this pull request as ready for review April 27, 2023 00:27
@smoia smoia changed the title Use black formatting rules for linting in CI Adopt Black and isort Apr 27, 2023
@smoia smoia merged commit d2a54ff into physiopy:master Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internal Changes affect the internal API. It doesn't increase the version, but produces a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Going black (i.e. adopting an _opinionated_ python code formatter)
3 participants