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

Use Black and isort for automatic formatting #184

Closed
felix-hilden opened this issue May 27, 2020 · 9 comments
Closed

Use Black and isort for automatic formatting #184

felix-hilden opened this issue May 27, 2020 · 9 comments
Assignees
Labels
style Refactoring, style or architectural improvement

Comments

@felix-hilden
Copy link
Owner

We should format code automatically. I already tried out a configuration in #183, but due to some issues with Black (psf/black#1054 & psf/black#1288) we'll be delaying that.

Here's the configuration in tox.ini:

[flake8]
select = C,E,F,W,B,B9
ignore = B305,E203,E402,E501,E722,F401,W503

[isort]
line_length=88
use_parentheses=True
multi_line_output=3
lines_between_types=1
include_trailing_comma=True
known_third_party=requests,httpx
known_first_party=tekore
force_grid_wrap=0

[testenv:black-run]
description = Run Black formatting on code
whitelist_externals = black
commands = black --target-version py36 .

[testenv:black-check]
description = Check code formatting
whitelist_externals = black
commands = black --target-version py36 --check .

[testenv:isort-run]
description = Run isort formatting on imports
whitelist_externals = isort
commands = isort -y

[testenv:isort-check]
description = Check import formatting
whitelist_externals = isort
commands = isort --check-only

[testenv:format]
description = Run all code formatting
whitelist_externals =
    isort
    black
commands =
    isort -y
    black --target-version py36 .
@felix-hilden felix-hilden added the waiting Waiting for another event label May 27, 2020
@felix-hilden felix-hilden self-assigned this May 27, 2020
@ichard26
Copy link

ichard26 commented Jul 4, 2020

Hello, Black contributor here! FYI, isort 5 has been released. It now has built-in Black support via profiles -> profile=black so the configuration can be simplified. Also isort 5 fixes another incompatiblity issue with Black (psf/black#251) with a new ensure_newline_before_comments option. isort 5 does require CPython 3.6.0+ to run, but it appears that this project targets 3.6.0+ already 🎉

python_requires = (3, 6)

Just something to keep in mind when considering to use Black (and isort) together for automatic code formatting. We're still working on the "magic trailing comma" issues so I do agree that introducing Black should wait for now (probably isort too since v5 is big change and probably needs a bit of ironing out - if isort v5 is used).

@felix-hilden
Copy link
Owner Author

Thank you for the information and suggestions!

@felix-hilden
Copy link
Owner Author

The magic trailing comma issue has been fixed! And I'm warming up to the formatting against which the other issue was raised. So we ought to start looking at this again!

@felix-hilden felix-hilden removed the waiting Waiting for another event label Aug 22, 2020
@felix-hilden
Copy link
Owner Author

Let's wait just a bit for the stable version of Black to be released. I was a bit quick to pull off the label.

@felix-hilden felix-hilden added the waiting Waiting for another event label Sep 3, 2020
@felix-hilden
Copy link
Owner Author

Also, when the time comes, Pre-commit could be used to enforce the formatting and reducing the number of oopsies. Remembering to run tox -e format before committing is just a worse version of having Pre-commit. Black uses it, so we could use that configuration at least as a basis for us.

@felix-hilden
Copy link
Owner Author

felix-hilden commented Sep 7, 2021

We could also use some RST formatter if one exists. Prettier is only for MD. It's rather annoying to change things yourself, particularly for contributors that don't know about it yet (ref #260).

@senpos
Copy link

senpos commented Feb 8, 2022

Let's wait just a bit for the stable version of Black to be released. I was a bit quick to pull off the label.

The first stable version of Black released! 🎉
https://github.com/psf/black/blob/main/CHANGES.md#2210

@felix-hilden
Copy link
Owner Author

😉 Thanks for the reminder!

@felix-hilden
Copy link
Owner Author

Finally there's enough action to warrant a resolution here, I'll look to introduce this for 5.0

@felix-hilden felix-hilden added style Refactoring, style or architectural improvement and removed waiting Waiting for another event labels Oct 17, 2022
@felix-hilden felix-hilden added this to the v5.0.0 milestone Oct 17, 2022
@felix-hilden felix-hilden mentioned this issue Jan 5, 2023
3 tasks
@felix-hilden felix-hilden removed this from the v5.0.0 milestone Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style Refactoring, style or architectural improvement
Projects
None yet
Development

No branches or pull requests

3 participants