未验证 提交 43265614 编写于 作者: A Advait Jain 提交者: GitHub

Turn on Python formatting checks as part of CI. (#316)

* Groundwork to enable python format checks (via yapf) as part of the CI.

With this change:
 * we are set up to use yapf as part of the docker container
 * pigweed patch is updated to use the google Python style (pep8 with indent of 2 spaces)
 * some documentation updates.

The code still needs to be formatted, and then the Python formatting check will be turned on as part of ci.

BUG=http://b/194404216

* Format all the code.

Once this change is merged, we will turn on Python formatting check as
part of the CI.

* minor formatting update.

* Turn on Python formatting checks as part of CI.

Also, add an option to fix the formatting via the test_code_style.sh
script.

BUG=http://b/194404984 and http://b/194404216
上级 0315e685
......@@ -221,6 +221,14 @@ Below are some tips that might be useful and improve the development experience.
* Get a copy of [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint)
* [yapf](https://github.com/google/yapf/) should be used for formatting Python
code. For example:
```
pip3 install yapf
yapf log_parser.py -i --style='{based_on_style: pep8, indent_width: 2}'
```
* Add a git hook to check for code style etc. prior to creating a pull request:
```
cp tensorflow/lite/micro/tools/dev_setup/pre-push.tflm .git/hooks/pre-push
......@@ -338,18 +346,8 @@ Below are some tips that might be useful and improve the development experience.
## Python notes
Most PRs for TensorFlow Lite Micro will be C++ only. Adding some notes on Python
that can be expanded and improved as necessary.
* [TensorFlow guide](https://www.tensorflow.org/community/contribute/code_style#python_style)
for Python development
* [yapf](https://github.com/google/yapf/) should be used for formatting. For example:
```
pip3 install yapf
yapf log_parser.py -i --style='{based_on_style: pep8, indent_width: 2}'
```
# Continuous Integration System
* Some [additional documentation](docs/continuous_integration.md) on the TFLM CI.
......@@ -62,20 +62,28 @@ LICENSE_CHECK_RESULT=$?
############################################################
# Formatting Check
############################################################
# We are currently ignoring Python files (with yapf as the formatter) because
# that needs additional setup. We are also ignoring the markdown files to allow
# for a more gradual rollout of this presubmit check.
if [[ ${1} == "--fix_formatting" ]]
then
FIX_FORMAT_OPTIONS="--fix"
else
FIX_FORMAT_OPTIONS=""
fi
micro/tools/make/downloads/pigweed/pw_presubmit/py/pw_presubmit/format_code.py \
kernels/internal/reference/ \
micro/ \
../../third_party/ \
${FIX_FORMAT_OPTIONS} \
-e c/common.c \
-e core/api/error_reporter.cc \
-e kernels/internal/reference/integer_ops/ \
-e kernels/internal/reference/reference_ops.h \
-e kernels/internal/types.h \
-e experimental \
-e schema/schema_generated.h \
-e schema/schema_utils.h \
-e "\.inc" \
-e "\.md" \
-e "\.py"
-e "\.md"
CLANG_FORMAT_RESULT=$?
FORMAT_RESULT=$?
#############################################################################
# Avoided specific-code snippets for TFLM
......@@ -121,8 +129,12 @@ popd
# Re-enable exit on error now that we are done with the temporary git repo.
set -e
if [[ ${FORMAT_RESULT} != 0 ]]
then
echo "The formatting errors can be fixed with tensorflow/lite/micro/tols/ci_build/test_code_style.sh --fix_formatting"
fi
if [[ ${LICENSE_CHECK_RESULT} != 0 || \
${CLANG_FORMAT_RESULT} != 0 || \
${FORMAT_RESULT} != 0 || \
${GTEST_RESULT} != 0 || \
${ERROR_REPORTER_RESULT} != 0 || \
${ASSERT_RESULT} != 0 \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册