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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Black Formatting #464

Closed
wants to merge 12 commits into from
Closed

Add Black Formatting #464

wants to merge 12 commits into from

Conversation

ethnh
Copy link
Contributor

@ethnh ethnh commented Feb 2, 2022

Changes

This change is entirely a style change -- There will be no impact on the code's performance from this
requirements.txt does not need to be updated -- this is not a requirement for running the code

Fixes

  • Inconsistent use of ' and "
  • Inconsistent use of tabs and spaces (if any exist)
  • (Tries to) Ensures code readability
  • Makes code style uniform
  • Update all code to follow PEP 8 (Read about Black's style here)

Checklist:

  • My code follows the style guidelines of this project and have read CONTRIBUTING.md (This adds style guidelines, I could not find any for this project)
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (I plan to add tests later)
  • I have checked my code and corrected any misspellings

@rachmadaniHaryono
Copy link

i don't know if this pr will be accepted, but maybe add pre commit black or use darker https://github.com/akaihola/darker

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022 via email

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022 via email

@rachmadaniHaryono
Copy link

If Theo wishes for the repo to have style guidelines, it'll be best to get
them done sooner rather than later -- Merging already existing PRs after a
large restyling like this could be a bit annoying, best to do it when there
are few open PRs

i think only #424 change the main program

other than that other pr mainly for non python file

@ThioJoe
Copy link
Owner

ThioJoe commented Feb 2, 2022

I have literally no idea what this means

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022 via email

@rachmadaniHaryono
Copy link

rachmadaniHaryono commented Feb 2, 2022

I have literally no idea what this means

simpler explanation

  • add github action to reformat pr
  • update contributing.md

is it too much @ThioJoe? if yes, maybe reduce the pr to essential and let thiojoe reformat the codebase

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

The majority of the commit is changing single quotes to double quotes (and
likely tabs to spaces) to keep the code consistent, but at a quick glance
of the changes, there are definitely some big improvements

As a note to Thio: none of this changes any of the existing code, it only changes the way it looks

[...]
-            text =post['contentText']['runs'][0]['text'].strip().replace('\n','').replace('\r', '')
+            text = (
+                post["contentText"]["runs"][0]["text"]
+                .strip()
+                .replace("\n", "")
+                .replace("\r", "")
+            )
[...]

(Deleted original to fix markdown)

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

i don't know if this pr will be accepted, but maybe add pre commit black or use darker https://github.com/akaihola/darker

@ThioJoe Also, if you are unaware of what a pre-commit is, I'd recommend checking out https://githooks.com/

The .git/hooks/pre-commit file tells git what to run before commiting files,
To add the black formatter to your pre-commit hooks, adding

python3 -m black

to the file should work馃憤

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

Example run of black-push workflow (with the "auto fix" feature commented out)
https://github.com/EthanHindmarsh/YT-Spammer-Purge/runs/5031727716?check_suite_focus=true

@dekoza
Copy link

dekoza commented Feb 2, 2022

Adding pre-commit would also benefit this project.

@KendallDoesCoding
Copy link
Contributor

KendallDoesCoding commented Feb 2, 2022

Yes, pre-commit black would be the best option馃憤 Not every PR/push is made on the desktop, which is why I included the workflow. I'm 100% sure some commits would slip by unformatted if the workflow was removed, The Autoblack workflow has a really neat feature to automatically edit PR's or create PR's if any push does not pass Black's check I'd personally set it to do a daily run over the repo and run on every new PR, but that's just my opinion, so I left it as it was set in Autoblack's source

Yes, I use the desktop app sometimes, but I mostly use the web application to commit/make PR's

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

let thiojoe reformat the codebase

Working on it right now 馃憤

@UP929312
Copy link

UP929312 commented Feb 2, 2022

I have literally no idea what this means

It's formatting which is objective so that everyone has to agree on following the same convention, that's what Black is, a forceful formatter that is pretty standard across python scripts.
A pre-commit hook or a workflow will mean that every time someone tries to add something to the codebase, it'll get automatically blackened (so automatically formatted) and is also pretty standard.

It has no effect on code functionality and is purely "cosmetic" in the sense that it's just so that everything follows formatting conventions.

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

Oops -- Workflow made that fixup! commit -- See https://github.com/EthanHindmarsh/YT-Spammer-Purge/actions/runs/1784682010
At least it shows it works 馃ぃ

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

@ThioJoe The changes should be ready for review -- The workflow (example run) will automatically style & format the codebase after you merge this PR (if you do), so I recommend merging any other PRs you want before merging in this one.
Only four files modified:

  • Add Two workflows
    • Run Black formatter on push
    • Run Black formatter on pull requests
  • Update CONTRIBUTING.md
  • Add .pre-commit-config.yaml for those who use the pre-commit python package

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

Changes reverted in Revert "Fix formatting issues with long dictionary names" can be re-added in a separate pull request should this be accepted 馃憤

Copy link
Contributor Author

@ethnh ethnh left a comment

Choose a reason for hiding this comment

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

CONTRIBUTING.md should get a complete update, but I think adding a note about Black should be enough for this PR

@rachmadaniHaryono
Copy link

rachmadaniHaryono commented Feb 2, 2022

if you use pre commit, you may don't need to think about it

because every commit will be autoformatted

maybe some note on how to setup your fork on contributing.md, example below


set up your fork


e: for poetry with pyproject


set up your fork

@ethnh
Copy link
Contributor Author

ethnh commented Feb 2, 2022

if you use pre commit, you may don't need to think about it

because every commit will be autoformatted

Not everyone commits from desktop:

Yes, I use the desktop app sometimes, but I mostly use the web application to commit/make PR's

maybe some note on how to setup your fork on contributing.md, example below

Yeah for sure 馃憤
See #489 -- His modified CONTRIBUTING.md is great

@rachmadaniHaryono
Copy link

Yeah for sure +1 See #489 --
His modified CONTRIBUTING.md is great

i have read it

unfortunately the pr change too much

but it is mostly correct

  • it describe how to setup the fork
  • how to check documentation
  • format/check/test the repo

i hope @dekoza can split the pr so better contributing.md can be used

@dekoza
Copy link

dekoza commented Feb 2, 2022

@rachmadaniHaryono I did what I could to minimize the changes. I used copier-poetry to create the basic directory structure and then moved most of the files into proper places. Then I refactored imports so that everything should work. Right now - since there are no tests - I'm trying to check if everything still works fine. If you ignore those several files added by copier-poetry, you'll see that the changes of imports are in fact small.

@ethnh
Copy link
Contributor Author

ethnh commented Feb 4, 2022

Fetch upstream to ensure no merge conflicts ^^

@rachmadaniHaryono
Copy link

dekoza close 489, maybe you can copy pretty-format-yaml hook to make sure all yaml file have the same format

@ethnh
Copy link
Contributor Author

ethnh commented Feb 4, 2022

dekoza close 489, maybe you can copy pretty-format-yaml hook to make sure all yaml file have the same format

I updated .pre-commit-config.yaml to match #489
I'm not sure anything else from #489 is relevant to adding Black formatting -- the purpose of this PR

Maybe pyproject, but that seems more of a poetry thing

@ethnh
Copy link
Contributor Author

ethnh commented Feb 4, 2022

Also, the failed check can be ignored, obviously, the current state of the repo would not pass a Black formatting check 馃榿

Copy link

@rachmadaniHaryono rachmadaniHaryono left a comment

Choose a reason for hiding this comment

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

also run pre commit autoupdate to make sure it use latest version

.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@rachmadaniHaryono
Copy link

I'm not sure anything else from #489 is relevant to adding Black formatting -- the purpose of this PR

as far as i can tell only some hook pre commit

@ethnh
Copy link
Contributor Author

ethnh commented Feb 4, 2022

also run pre commit autoupdate to make sure it use latest version

Doing this right now

As for the other issues you mentioned, I'll just comment out those parts of the yaml file for later 馃憤

@ThioJoe
Copy link
Owner

ThioJoe commented Feb 5, 2022

Tbh I don't really have any intention of adding this, I don't really understand the benefit

@ThioJoe ThioJoe closed this Feb 5, 2022
@dekoza
Copy link

dekoza commented Feb 5, 2022

Tbh I don't really have any intention of adding this, I don't really understand the benefit

Another brick in the wall...

@ethnh ethnh mentioned this pull request Feb 5, 2022
8 tasks
@Masamune3210
Copy link

Dude chill out, its not your repo. If you don't like a choice you don't have to deal with it lol

@KendallDoesCoding
Copy link
Contributor

Dude chill out, its not your repo. If you don't like a choice you don't have to deal with it lol

Comment by Masamune3210

This comment was directed to someone else, not towards the PR or myself
@EthanHindmarsh

Who was this comment directed to @Masamune3210

@ethnh
Copy link
Contributor Author

ethnh commented Feb 6, 2022

Dude chill out, its not your repo. If you don't like a choice you don't have to deal with it lol

Comment by Masamune3210

This comment was directed to someone else, not towards the PR or myself
@EthanHindmarsh

Who was this comment directed to @Masamune3210

image
Probably the comment above馃槀

@KendallDoesCoding
Copy link
Contributor

Dude chill out, its not your repo. If you don't like a choice you don't have to deal with it lol

Comment by Masamune3210

This comment was directed to someone else, not towards the PR or myself
@EthanHindmarsh

Who was this comment directed to @Masamune3210

image Probably the comment above馃槀

Ok lol, I think he was just joking though.

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

Successfully merging this pull request may close these issues.

None yet

7 participants