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

Add a yapf precommit hook #72

Closed
wants to merge 4 commits into from
Closed

Add a yapf precommit hook #72

wants to merge 4 commits into from

Conversation

alahwa
Copy link
Contributor

@alahwa alahwa commented May 11, 2018

No description provided.

hooks/pre-commit Outdated

readonly changed_files_command="git diff --cached --name-only | grep '\.py$' | grep -v 'servers/[^\/]*/jobs/models' | grep -v 'setup.py'"
readonly files_in_commit=$(eval $changed_files_command)
echo $files_in_commit
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer not to have all these echo lines (line 19, 22, 28) for every commit.

Ideally precommit would automatically format and save files, without manual intervention, like "pretty-quick --staged". Since this PR doesn't do that, I would like to either cancel this PR, or remove all this logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -13,3 +13,22 @@ then
echo Please commit to a working branch and push it to GitHub for review/merge.
exit 1
fi

readonly changed_files_command="git diff --cached --name-only | grep '\.py$' | grep -v 'servers/[^\/]*/jobs/models' | grep -v 'setup.py'"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you exclude these files, like setup.py? The list of files to exclude should be kept in sync with CircleCI. CircleCI only excludes ui/node_modules.

if ! [ -z "$yapf_out" ]
then
echo "Reformatting staged files, please review them and stage the changes."
yapf -i $files_in_commit --exclude ui/node_modules/
Copy link
Contributor

Choose a reason for hiding this comment

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

# Keep in sync with .circleci/config.yml

Also add comment to .circleci/config.yml


if ! [ -z "$yapf_out" ]
then
echo "Reformatting staged files, please review them and stage the changes."
Copy link
Contributor

Choose a reason for hiding this comment

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

I just tested this out.

  • Made a change to a file that would cause yapf to fail
  • git commit -m 'blah'
  • commit went through with incorrectly formatted file
  • After commit, file is still incorrectly formatted.

That's not what you expect, right?

My advice is to abandon this PR, rather than try to get this working.

If you can get the automatic reformatting working, then this PR is worth it. Seems doable given you have file_in_commit.

@melissachang
Copy link
Contributor

melissachang commented May 29, 2018

Facebook is working on a new Python formatter, Black, which they will use for their .py files. I think Black will have more adoption than YAPF over time. I prefer Black over YAPF because:

See this thread for more details.

What do you think about looking into Black?

@alahwa alahwa closed this Jun 7, 2018
@alahwa alahwa deleted the ah/test branch June 7, 2018 22:16
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.

2 participants