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

Change code formatting to black #7458

Merged
merged 2 commits into from Feb 25, 2020
Merged

Conversation

JacobCallahan
Copy link
Member

This PR is a demo for the proposal to switch robottelo's code formatting
away from flak8 standards and over to python black.

@JacobCallahan JacobCallahan added DO NOT MERGE enhancement An addition to the robottelo framework labels Nov 6, 2019
@JacobCallahan
Copy link
Member Author

@SatelliteQE/quality-engineers Please check out the example changes in this PR. This will NOT be the final code to be merged when the change happens, as that should also include some additional pieces.

@jyejare
Copy link
Member

jyejare commented Nov 7, 2019

@JacobCallahan Formatting looks way better than flake8 and as it supports autoformatting its a cherry on cake. :)

Btw Travis is upset with you :(

@JacobCallahan
Copy link
Member Author

@jyejare yeah travis will be much less upset when the flake checks are removed!

@rochacbruno
Copy link
Contributor

@JacobCallahan we can still keep flake8 to warn about things like unused imports, unused variables etc..

Black can live with flake8 as long we ignore some specific checks example: https://github.com/rochacbruno/dynaconf/blob/master/.pre-commit-config.yaml#L35

@nixocio
Copy link

nixocio commented Nov 7, 2019

@rochacbruno I have not used yet. But https://pypi.org/project/flake8-black/

@JacobCallahan
Copy link
Member Author

@SatelliteQE/robottelo-automation I've updated this PR with the new pre-commit hook.
Note that engineers will still need to run black before committing, as it follows the non-changing standard.
See also: pre-commit/pre-commit#747 (comment)

@JacobCallahan JacobCallahan changed the title [DO NOT MERGE!!]Change code formatting to black[DO NOT MERGE] Change code formatting to black Feb 18, 2020
@codecov
Copy link

codecov bot commented Feb 18, 2020

Codecov Report

Merging #7458 into master will decrease coverage by 0.02%.
The diff coverage is 48.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7458      +/-   ##
==========================================
- Coverage   67.96%   67.93%   -0.03%     
==========================================
  Files          30       30              
  Lines        3814     3814              
==========================================
- Hits         2592     2591       -1     
- Misses       1222     1223       +1
Impacted Files Coverage Δ
robottelo/decorators/func_shared/base.py 71.42% <ø> (ø) ⬆️
robottelo/cli/repository.py 100% <ø> (ø) ⬆️
robottelo/decorators/func_shared/__init__.py 100% <100%> (ø) ⬆️
robottelo/decorators/func_locker.py 91.72% <100%> (-0.76%) ⬇️
robottelo/cli/base.py 98.3% <100%> (ø) ⬆️
robottelo/issue_handlers/bugzilla.py 100% <100%> (ø) ⬆️
robottelo/api/assertions.py 100% <100%> (ø) ⬆️
robottelo/decorators/host.py 95.65% <100%> (ø) ⬆️
robottelo/decorators/func_shared/file_storage.py 91.93% <100%> (ø) ⬆️
robottelo/decorators/__init__.py 81.17% <100%> (ø) ⬆️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ca5771...d883be2. Read the comment docs.

Copy link
Contributor

@mirekdlugosz mirekdlugosz left a comment

Choose a reason for hiding this comment

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

Note that engineers will still need to run black before committing, as it follows the non-changing standard.

Some people might misunderstand it in the same way I did, so to clarify:
You don't have to install and run black manually. black will be run during pre-commit run (or git commit, if pre-commit hook is installed), and it will modify files in repo. What it won't do is staging these changes.

So your workflow might be: git add, git commit (pre-commit runs black, black modifies files), git add again (to stage changes done by black), git commit again (to actually commit, as hook should now pass).

Also, black and pre-commit are still optional. If you don't use them and write code that doesn't conform to black liking, travis will fail for you. So you don't have to use these tools, it's just you will set yourself up for more work than it's worth.

SatelliteQE/robottelo-automation

For the record, this group is collection of random people, including 4 that don't even work on Satellite anymore. If you want wide distribution of your comment, you are better of using SatelliteQE/quality-engineers, which at least contains most of team members.

@rochacbruno
Copy link
Contributor

@mirekdlugosz you can use pre-commit run -a -v manually before commiting, I usually do this to avoid to do git add twice.

@@ -0,0 +1,17 @@
[tool.black]
line-length = 99
Copy link
Contributor

Choose a reason for hiding this comment

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

OMG! I am on the 79 team.. but I think I can try to accommodate 99 now that I have a widescreen monitor.

@JacobCallahan
Copy link
Member Author

Ok, so I ran a bunch of automation runs and couldn't find any failures linked to this PR. There is another issue I've identified, so we may want to wait on resolving that. The solution to the other problem might be easier to find before this is merged.

@JacobCallahan
Copy link
Member Author

@rochacbruno @mshriver @mirekdlugosz So the issue in our standalone doesn't seem to be affecting our tiered automation runs in 6.7. If you all don't have any reservations, we should be safe to merge.

This change adds python black to the pre-commit hook.
Additionally, it adds pyproject.toml to configure black.
This configurations is largely default, but I did skip string normalization.
Additionally, line length is capped to 99, per flake8.
Initial formatting of robottelo to the new black standards.
Note that string formatting is not changed, and line length is now
out to 99, to conform with flake8 settings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An addition to the robottelo framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants