format: add format fix for java proto options#5516
Conversation
Allows running tools/check_format.py fix to insert the necessary java proto options. Signed-off-by: Snow Pettersen <snowp@squareup.com>
|
/assign @jmarantz |
|
This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
@jmarantz You wanna give this one a look? |
| package_name = None | ||
| for line in fileinput.FileInput(file_path): | ||
| if line.startswith("package "): | ||
| package_name = re.compile("package (.*);").search(line).group(1) |
There was a problem hiding this comment.
Can you compile the regex at global scope?
| infile = os.path.join(src, filename) | ||
| directory = os.path.dirname(filename) | ||
| if not directory == '' and not os.path.isdir(directory): | ||
| os.makedirs(directory) |
There was a problem hiding this comment.
I'm curious why this is needed. If there's a filename reaching here, shouldn't we expect the directory to exist?
There was a problem hiding this comment.
At the time I added it because I had issues with the fact that the test file is api/java_options.proto and requires api to exist, but seems like I can remove this and it still works.
There was a problem hiding this comment.
The other mkdirs is necessary though to avoid:
diff proto_format.proto /source/tools/testdata/check_format/proto_format.proto.gold
Traceback (most recent call last):
File "./tools/check_format_test_helper.py", line 215, in <module>
errors += checkAndFixError("api/java_options.proto", "Java proto option")
File "./tools/check_format_test_helper.py", line 126, in checkAndFixError
errors = checkFileExpectingError(filename, expected_substring)
File "./tools/check_format_test_helper.py", line 121, in checkFileExpectingError
command, status, stdout = runCheckFormat("check", getInputFile(filename))
File "./tools/check_format_test_helper.py", line 55, in getInputFile
shutil.copyfile(infile, filename)
File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 2] No such file or directory: 'api/java_options.proto'
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Allows running tools/check_format.py fix to insert the necessary java proto options. Signed-off-by: Snow Pettersen <snowp@squareup.com> Signed-off-by: Fred Douglas <fredlas@google.com>
Allows running tools/check_format.py fix to insert the necessary java
proto options.
Signed-off-by: Snow Pettersen snowp@squareup.com
Risk Level: Low
Testing: Added check_format_test
Docs Changes: n/a
Release Notes: n/a
Fixes #5477