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

Format Python script using Black formatter #1202

Merged
merged 11 commits into from
Jan 29, 2024

Conversation

za
Copy link
Contributor

@za za commented Jan 26, 2024

What kind of changes does this PR include?

  • Fixes or refactors
  • A new challenge
  • Additional documentation
  • Something else

Description

Format Python script using Black formatter so that the style is consistent. Hopefully this will make the code more readable and attract more contributors.

Relations

Closes #1200

References

https://github.com/psf/black

Checklist:

  • All the contributions made are solely the work of me and my co-authors
  • I tested the changes in this PR (if applicable)
  • I added unit tests to ensure my change works (when change in Java or on front-end code)
  • I added UI tests to ensure my UI changes work (when change in the overall UI, not needed if just adding a challenge)
  • The PR passes pre-commit hooks and automated tests

So the style is consistent
Refer to issue: OWASP#1200
Copy link
Collaborator

@commjoen commjoen left a comment

Choose a reason for hiding this comment

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

Hi @za ,
Can you please take a look on how we can have the formatting done automatically using precommit? Thanks!

@za
Copy link
Contributor Author

za commented Jan 26, 2024

Hi @commjoen ok, I'll have a look.

@za
Copy link
Contributor Author

za commented Jan 26, 2024

Hi @za , Can you please take a look on how we can have the formatting done automatically using precommit? Thanks!

Hi @commjoen I've added black.yml and updated pre-commit.yml file. Can you check?

@za za requested a review from commjoen January 26, 2024 07:40
@commjoen
Copy link
Collaborator

commjoen commented Jan 26, 2024

Something seems to fail when using the new pre-commit hook, can you please fix the black integration :) ? Then I am very happy to continue :) .

[26/01 4:42:29] ➜  sort_contibutors git:(python-black-formatted) ✗ pre-commit install
pre-commit installed at .git/hooks/pre-commit
[26/01 4:42:34] ➜  sort_contibutors git:(python-black-formatted) ✗ git commit        
[INFO] Initializing environment for https://github.com/psf/black.
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/opt/git/libexec/git-core/git', 'checkout', '22.6b0')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: pathspec '22.6b0' did not match any file(s) known to git
    
Check the log at /Users/razr/.cache/pre-commit/pre-commit.log
[26/01 4:42:38] ➜  sort_contibutors git:(python-black-formatted) ✗ git status
On branch python-black-formatted
Your branch is up to date with 'origin/python-black-formatted'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   main.py

@za
Copy link
Contributor Author

za commented Jan 29, 2024

Something seems to fail when using the new pre-commit hook, can you please fix the black integration :) ? Then I am very happy to continue :) .

[26/01 4:42:29] ➜  sort_contibutors git:(python-black-formatted) ✗ pre-commit install
pre-commit installed at .git/hooks/pre-commit
[26/01 4:42:34] ➜  sort_contibutors git:(python-black-formatted) ✗ git commit        
[INFO] Initializing environment for https://github.com/psf/black.
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/opt/git/libexec/git-core/git', 'checkout', '22.6b0')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    error: pathspec '22.6b0' did not match any file(s) known to git
    
Check the log at /Users/razr/.cache/pre-commit/pre-commit.log
[26/01 4:42:38] ➜  sort_contibutors git:(python-black-formatted) ✗ git status
On branch python-black-formatted
Your branch is up to date with 'origin/python-black-formatted'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   main.py

Updated in the next commit

@za za requested a review from commjoen January 29, 2024 01:59
as we implemented black in git pre-commit hook
Copy link
Collaborator

@commjoen commjoen left a comment

Choose a reason for hiding this comment

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

Thank you!

@commjoen commjoen merged commit d8bbd97 into OWASP:master Jan 29, 2024
13 of 14 checks passed
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.

Format Python scripts using Black
2 participants