This is an archive of the discontinued LLVM Phabricator instance.

clang-format-diff: Make it work with python3 too
ClosedPublic

Authored by MarcoFalke on Jun 12 2018, 2:40 PM.

Details

Summary

It is not necessary, but would be nice if the script run on python3 as well (as opposed to only python2, which is going to be deprecated https://pythonclock.org/)

Diff Detail

Repository
rL LLVM

Event Timeline

MarcoFalke created this revision.Jun 12 2018, 2:40 PM

In python2.7:
TypeError: 'encoding' is an invalid keyword argument for this function

So remove it for now.

djasper edited reviewers, added: krasimir; removed: djasper.Jun 12 2018, 11:26 PM
djasper added a subscriber: sammccall.
krasimir requested changes to this revision.Jun 13 2018, 2:54 AM

Sorry, I'm not familiar with this tool. Could you elaborate:

  • why is this switch necessary?
  • what's expected to be supported with it?
  • how do I test it?
This revision now requires changes to proceed.Jun 13 2018, 2:54 AM
why is this switch necessary?

It is not necessary, but would be nice if the script run on python3 as well (as opposed to only python2, which is going to be deprecated https://pythonclock.org/)

what's expected to be supported with it?

I'd assume python2.7 (which is the only supported python2) and everything from python3.4 and upward.

how do I test it?

The clang-format-diff.py is a wrapper around clang-format, to format only a diff. You can get any diff, e.g. the last ten commits to the master branch:

git diff HEAD~10 -U0 | python2 ./tools/clang-format/clang-format-diff.py

(You might have to pass -p1)

Then test that the following options work with both python2 and python3:

-i -v  # flags
-regex # could be -regex '.*\.h'
-iregex # could be -iregex '.*\.H'
MarcoFalke edited the summary of this revision. (Show Details)
MarcoFalke edited the summary of this revision. (Show Details)
MarcoFalke edited the summary of this revision. (Show Details)Jun 13 2018, 3:19 PM

Please always upload all patches with the full context (-U99999)

tools/clang-format/clang-format-diff.py
1 ↗(On Diff #151260)

Why do you need to *switch* the default?
What's wrong with [at least starting with] just making sure it works with both python 2 and 3?

krasimir added inline comments.Jun 14 2018, 2:05 AM
tools/clang-format/clang-format-diff.py
1 ↗(On Diff #151260)

+1: I'm not an expert, but IMO python2.7 is more prevalent.

Keep python2 by default for now

MarcoFalke marked 2 inline comments as done.Jun 26 2018, 3:57 AM
krasimir accepted this revision.Jun 29 2018, 7:28 AM

Checked with both python 2 and python 3 as suggested. Works like a charm! Thank you!

This revision is now accepted and ready to land.Jun 29 2018, 7:28 AM
lebedev.ri retitled this revision from clang-format-diff: Switch to python3 by default, support python 2.7 to clang-format-diff: Make it work with python3 too.Jun 29 2018, 7:29 AM

MarcoFalke: do you need someone to submit this for you?

MarcoFalke: do you need someone to submit this for you?

Yes, I'd appreciate any help on how to submit this for merge.

This revision was automatically updated to reflect the committed changes.