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 formatting targets to the makefile #173

Merged
merged 6 commits into from Jan 26, 2020

Conversation

pablogsal
Copy link
Collaborator

@pablogsal pablogsal commented Jan 21, 2020

As requested by @lysnikolaou , add one target that allows formatting pegen/pegen.c (requires
clang-format and clang-tidy) available on the system and another target
that formats everything (Python and C files).

Feel free to suggest tweaks to the C file or if you want additional files to be formatted.

Copy link
Collaborator

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

How do I get clang-today and clang-format?

Makefile Show resolved Hide resolved
Makefile Outdated
@@ -87,6 +87,13 @@ mypy: regen-metaparser
black:
black pegen tatsu test scripts

format-pegen:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The difference in naming style for this target from ‘black’ somehow bothers me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I rename black to format-python and format-pegen to format-c?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good.

@pablogsal
Copy link
Collaborator Author

pablogsal commented Jan 21, 2020

How do I get clang-tidy and clang-format?

Not a heavy MacOS user but after a bit of research seems that:

  • Clang format can easily be installed by brew install clang-format
  • It seems that clang-tidy is not on brew so the easiest way is to install LLVM and symlink the tools (yeah, I know, is a bit overkill):
brew install llvm
ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"

To be honest, the original reason I didn't initially commit this to the makefile is that I find these tools a bit heavyweight and I am not an expert with them so I will understand if we end deciding to use only clang-format (seems that is the easiest to get) or to not add any new target at all.

@gvanrossum
Copy link
Collaborator

How do I get clang-today and clang-format?

Not a heavy MacOS user but after a bit of research seems that:

* Clang format can easily be installed by `brew install clang-format`

* It seems that `clang-tidy` is not on brew so the easiest way is to install LLVM and symlink the tools (yeah, I know, is a bit overkill):
brew install llvm
ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"

To be honest, the original reason I didn't initially commit this to the makefile is that I find these tools a bit heavyweight and I am not an expert with them so I will understand if we end deciding to use only clang-format (seems that is the easiest to get) or to not add any new target at all.

Maybe we should only use clang-format then? (Honestly I don't know which one does what -- why do we need both?) And it would be nice if instructions for installing it were in a comment in the Makefile at least (so someone for whom it doesn't work might find them upon inspecting the source of the Makefile).

@pablogsal
Copy link
Collaborator Author

why do we need both

It seems that only clang-tidy can add the braces around statements, I was unable to make clang-format do that :(

And it would be nice if instructions for installing it were in a comment in the Makefile at least (so someone for whom it doesn't work might find them upon inspecting the source of the Makefile).

Agreed, will update the PR soon.

@gvanrossum
Copy link
Collaborator

It seems that only clang-tidy can add the braces around statements, I was unable to make clang-format do that :(

I'm not adamant about braces everywhere, despite what PEP 7 says. Maybe you can have a separate rule that runs clang-tidy but which isn't depended on by format.

Separately, maybe we can run make format from Travis-CI and somehow fail if any file had to be formatted? Just like we run make mypy. (Though I think checking that nothing was formatted is a bit trickier.)

@lysnikolaou
Copy link
Collaborator

lysnikolaou commented Jan 21, 2020

@pablogsal Thanks for doing this!

Maybe you can have a separate rule that runs clang-tidy but which isn't depended on by format.

I agree, that this is the way to go, since clang-tidy is not that easy to install.

@gvanrossum
Copy link
Collaborator

Were you going to finish this?

Add one target that allows to format pegen/pegen.c (requires
clang-format and clang-tidy) available on the system and another target
that formats everything (Python and C files).
@pablogsal
Copy link
Collaborator Author

Were you going to finish this?

I have rebased and addressed the feedback.

Copy link
Collaborator

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Can you add comments explaining how to install clang-format and clang-tidy? I now know it's brew install clang-format for the former, so a single line would suffice there, but the other is more complicated, right?

@gvanrossum
Copy link
Collaborator

(Oh, add "On Mac" to those comments...)

Copy link
Collaborator

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Great!

@pablogsal pablogsal merged commit 86ec29a into we-like-parsers:master Jan 26, 2020
@pablogsal pablogsal deleted the format branch January 26, 2020 22:24
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

3 participants