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

[py] proof of concept; formatting python code with black. #10560

Closed
wants to merge 2 commits into from

Conversation

symonk
Copy link
Member

@symonk symonk commented Apr 19, 2022

Hi, a quick proof of concept I'd like to discuss using something like black (https://github.com/psf/black) to apply to our python codebase. This is a naive implementation, consider this PR mainly for discussions. I think it's critical to get consistency across the python code base to make contributing as simple as possible with a clean (automatic) UX.

Ideally I'd like to get something like pre-commit (https://github.com/pre-commit/pre-commit) applying this stuff automatically on git pre-commit to avoid needless churn and be as as effecient as possible; formatting is only one small benefit there, we can use it to automate a whole heap of useful stuff.

Thoughts?

If we feel this is beneficial I will look at implementing it properly; for now I have just did a 'quick pass' of the tooling to show what it may look like. I think the consistency is a massive plus. We can make slight adjustments to the configuration if we need, or even go with a completely different formatter but I'd like to see something alongside flake8. I would strongly push implementing pre-commit with some hooks on the client side.

[Do not merge this with tox/setup configuration as is; for demo purposes only]

@jsa34
Copy link

jsa34 commented Apr 20, 2022

I would agree with linting and enforcing standards with precommit (just my opinion!)
Would probably be a good idea to pop in a flake8 or something for enforcing some pep8 standards in the precommit hook?

@symonk
Copy link
Member Author

symonk commented Apr 20, 2022

Absolutely; heres a config I tend to run with for my own projects:
https://github.com/symonk/asserto/blob/main/.pre-commit-config.yaml

black/flake8 are only a small drop in what we could do; the thing about pre-commit is how it's easy pluggable with whatever we need; (I have for example my own hook that catches pdb shortcuts as variable names and prevents commits e.g s = 10 type stuff

@AutomatedTester
Copy link
Member

I don't want a pre-commit hook for this but I'm not against this. The code has clearly grown organically over a while so cleaning it up will be a good thing.

@titusfortner titusfortner marked this pull request as draft May 9, 2022 15:12
@titusfortner
Copy link
Member

I made this draft since it is poc.

Where do we go since we aren't doing a pre-commit hook? Can we get the linter test in our CI to flag things that aren't correct?

@symonk
Copy link
Member Author

symonk commented May 9, 2022

I can add a tox recipe for running black and have it applied in CI. I understand you are against the concept of a pre-commit hook, maybe in future (I much prefer the code to not even make it to the server to be told its incorrect; find it inefficient) but for now i will make this a CI based tox thing that will fail PRs if you think theres value in having it. I'll also try not to tarnish git blame while doing so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants