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

Black formatter PR #282

Merged
merged 18 commits into from
Jun 5, 2019
Merged

Black formatter PR #282

merged 18 commits into from
Jun 5, 2019

Conversation

AhmetCanSolak
Copy link
Contributor

Description

This PR is to see how black formatter would change some of our code.
Please check the details and let each other know about your comments.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

References

https://github.com/python/black

How has this been tested?

Will be tested on review manually.

Final checklist:

  • My PR is the minimum possible work for the desired functionality

@AhmetCanSolak AhmetCanSolak self-assigned this May 21, 2019
@pep8speaks
Copy link

pep8speaks commented May 21, 2019

Hello @AhmetCanSolak! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 249:80: E501 line too long (84 > 79 characters)

Line 12:80: E501 line too long (84 > 79 characters)

Comment last updated at 2019-05-23 20:16:00 UTC

@AhmetCanSolak AhmetCanSolak mentioned this pull request May 21, 2019
@AhmetCanSolak AhmetCanSolak added this to the 0.1.0 milestone May 21, 2019
@AhmetCanSolak AhmetCanSolak added the feature New feature or request label May 21, 2019
@@ -31,16 +31,19 @@ class Viewer:
These key bindings are executed instead of any layer specific key
bindings.
"""
def __init__(self, title='napari'):

def __init__(self, title="napari"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the any way to configure black to use ' instead of "?

Copy link
Contributor Author

@AhmetCanSolak AhmetCanSolak May 21, 2019

Choose a reason for hiding this comment

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

No as far as i know. This is something black has a strong preference. To me also it makes sense, as double " is used for strings as a widely popular convention. On top of that, it is consistent with C/OpenCL and so. IMO we are very likely to depend such languages/tools in the long run.

Copy link
Contributor

@sofroniewn sofroniewn May 21, 2019

Choose a reason for hiding this comment

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

yeah - i just found a super long hacker news post on this one! Let's just say some very strong opinions on either side

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everybody(including me) has an opinion on everything(especially in python world) :D that's why maybe better to decide according to priorities instead of opinions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw, good news it is possible to stop black on this with: --skip-string-normalization

Copy link
Contributor

Choose a reason for hiding this comment

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

yes - very interesting, I just read this thread here psf/black#118, and the main developer very reasonably added that skip, which can be achieved with the short-cut black . -S

Copy link
Contributor

@sofroniewn sofroniewn left a comment

Choose a reason for hiding this comment

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

I'm pretty happy with how black has done the new line spacing, and I love how it has inserted white space between operators, I think that will cut down the review time on my PRs quite a bit!

One thing I'd be curious to see though is the output of running with the -S (--skip-string-normalization) command. I prefer the ability to mix ' and ", using ' for things like dictionary names as I find them easier to read. If we like the results then I'd vote for black -S

@jni
Copy link
Member

jni commented May 21, 2019

Yeah I gotta say I'm pretty happy with the result! Thanks for running this experiment, @AhmetCanSolak!

  • For sure I want -S on in our project. I'm firmly on one side of the debate here. =D
  • I often prefer for operators to be spaced but "intelligently" grouped by priority, e.g. length/2 - max_length/2 vs length / 2 - max_length / 2...
  • but on the whole I think it's done a good job and if it clears up mental space for never thinking about formatting again, then that's a significant win.
  • also, I'm surprised by the low number of changes it's proposed, which speaks to our generally good consistency in code style till now. Go team! =P

It'd be awesome if black could also format numpy-style docstrings, but that's a bit much to ask. =)

I'm moving my position from 👎 to neutral. =)

CC @stefanv (as we have considered black for skimage also)

@AhmetCanSolak
Copy link
Contributor Author

Thank you @sofroniewn and @jni !

Glad you guys like it and yes having -S will be okay too.

@AhmetCanSolak
Copy link
Contributor Author

all pre-commit and black integration business available now in this PR. Would you guys prefer to have a separate PR for all formatted version of codebase or prefer it also within this PR? @kne42 @sofroniewn @jni ?

@sofroniewn
Copy link
Contributor

I'm fine with one PR that does all the reformatting too and add the pre-commit. It looks like the build is failing now as it is not finding the right version of pre-commit

@AhmetCanSolak
Copy link
Contributor Author

eerh pypi and conda versions are different :( fixing it

Copy link
Member

@kne42 kne42 left a comment

Choose a reason for hiding this comment

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

I'd prefer to see the pre-commit stuff as a separate PR split into three commits:

  1. actual pre-commit code/setup
  2. documentation (README banner/CONTRIBUTING section)
  3. the results of pre-commit run --all-files

We could also make this PR just the results of black -S and the pre-commit code as a separate PR.

.pre-commit-config.yaml Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
requirements/default.txt Outdated Show resolved Hide resolved
Co-Authored-By: Kira Evans <[email protected]>
@AhmetCanSolak
Copy link
Contributor Author

Updated this PR. Will be happy if you guys @jni @sofroniewn @kne42 can review so i can continue with formatting the entire repo with black.

Copy link
Contributor

@sofroniewn sofroniewn left a comment

Choose a reason for hiding this comment

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

I'm approving as it looks close, though I did request some more detail in the contributing guidelines. Maybe @kne42 and @jni have further thoughts though

Copy link
Member

@jni jni left a comment

Choose a reason for hiding this comment

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

@AhmetCanSolak I think @sofroniewn's comment is worth addressing in this PR, as well as line length. I think both should be quick work!

pyproject.toml Show resolved Hide resolved
CONTRIBUTING.md Outdated

With help of pre-commit, your future commits will be reformatted with our black configuration
which includes settings like `skip-string-normalization = true` and `max-line-length = 79`.
If you like to learn more please check [black](https://github.com/python/black).
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change it to "If you would like to learn more", slightly better grammatically. Otherwise looks ready to merge

@jni jni merged commit 01b8ff0 into napari:master Jun 5, 2019
@jni
Copy link
Member

jni commented Jun 5, 2019

Boom! =)

@AhmetCanSolak AhmetCanSolak deleted the blackpr branch June 5, 2019 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants