Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[flake8]
select = B,C,E,F,P,T4,W,B9
max-line-length = 120
ignore = E203,E305
optional-ascii-coding = True
exclude =
./.git,
./.github,
./3rdparty,
./benchmark,
./cd,
./ci,
./cmake,
./config,
./contrib,
./cpp-package,
./docker,
./docs,
./example,
./include,
./licences,
./plugin,
./src,
./tools,
./build,
*.pyi
17 changes: 17 additions & 0 deletions ci/docker/runtime_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ sanity_check() {
sanity_clang
sanity_license
sanity_python
sanity_python_flake8
sanity_cpp
}

Expand All @@ -712,6 +713,22 @@ sanity_license() {
tools/license_header.py check
}

sanity_python_flake8() {
set -ex

# Install dependencies
pip3 install -r requirements-flake8.txt --user

# Run flake8
python3 -m flake8 | tee flake8-output.txt

if [ -s flake8-output.txt ]; then
echo 'Please fix the above Flake8 warnings.'
exit 1
fi
exit 0
}

sanity_cpp() {
set -ex
3rdparty/dmlc-core/scripts/lint.py mxnet cpp include src plugin cpp-package tests --exclude_path src/operator/contrib/ctc_include include/onednn
Expand Down
5 changes: 5 additions & 0 deletions requirements-flake8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flake8==3.8.2
flake8-pyi==20.5.0
flake8-bugbear==20.1.4
flake8-comprehensions==3.3.0
flake8-executable==2.0.4
3 changes: 3 additions & 0 deletions tools/git-pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ set -e

echo "Running pre-commit clang-format"
tools/lint/git-clang-format HEAD~ --force

echo "Running pre-commit flake8 checker"
python tools/lint/flake8_hook.py
44 changes: 44 additions & 0 deletions tools/lint/flake8_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#!/usr/bin/env python3

import sys

from flake8.main import git

if __name__ == '__main__':
sys.exit(
git.hook(
# (optional):
# any value > 0 enables complexity checking with mccabe
complexity=0,

# (optional):
# if True, this returns the total number of error which will cause
# the hook to fail
strict=True,

# (optional):
# a comma-separated list of errors and warnings to ignore
# ignore=

# (optional):
# allows for the instances where you don't add the the files to the
# index before running a commit, e.g git commit -a
lazy=git.config_for('lazy'),
)
)