Skip to content

Commit

Permalink
[Workflow] Use pre-commit hooks to check codes (#4633)
Browse files Browse the repository at this point in the history
* Use pre-commit hooks

* Add pylint to pre-commit hooks

* Update the docs

* add pre-commit to requirements-dev

* make both yapf and isort happy

* change the update schedule

* remove code_format.py

* turn off yapf for one line
  • Loading branch information
frostming authored Mar 30, 2022
1 parent 22a099d commit 2cdc580
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 330 deletions.
5 changes: 2 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BraceWrapping:
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
Expand Down Expand Up @@ -48,7 +48,7 @@ DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Expand Down Expand Up @@ -93,4 +93,3 @@ Standard: Auto
TabWidth: 8
UseTab: Never
...

1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ CheckOptions:
- { key: readability-identifier-naming.PublicMethodCase, value: lower_case }
- { key: readability-identifier-naming.PublicMemberSuffix, value: "" }
...

2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
blank_issues_enabled: true
contact_links:
- name: Contributor Guideline
url: https://docs.taichi.graphics/lang/articles/contributor_guide
url: https://docs.taichi.graphics/lang/articles/contributor_guide
about: Please check this out if you'd like to contribute by opening a PR :)
- name: Taichi Forum
url: https://forum.taichi.graphics
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/issue_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
issue-type: pull-request
permission: triage
commands: |
format
benchmark
rebase
rerun
99 changes: 19 additions & 80 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,75 +57,14 @@ jobs:
echo "::set-output name=run_job::false"
fi
check_code_format:
name: Check Code Format
runs-on: ubuntu-latest
needs: check_files
# This job will be required to pass before merging to master branch.
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Setup git & clang-format
run: |
git config user.email "[email protected]"
git config user.name "Taichi Gardener"
git checkout -b _fake_squash
git remote add upstream https://github.com/taichi-dev/taichi.git
git fetch upstream master
sudo apt install clang-format-10
- name: Cache PIP
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ hashFiles('setup.py') }}-${{ hashFiles('requirements_dev.txt') }}

- name: Install requirements
run: |
python3 -m pip install --user -r requirements_dev.txt
- name: Check code format
run: |
python3 misc/code_format.py
git checkout -b _enforced_format
git commit -am "enforce code format" || true
# exit with 1 if there were differences:
git diff _fake_squash _enforced_format --exit-code
check_static_analyzer:
name: Check Static Analyzer
runs-on: ubuntu-latest
needs: check_files
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Pylint
run: |
if [[ ${{needs.check_files.outputs.run_job}} == false ]]; then
exit 0
fi
python3 -m pip install --user pylint
# Make sure pylint doesn't regress
pylint python/taichi/ --disable=all --enable=$(python scripts/generate_pylint_tags.py)
if [ $? -eq 0 ]
then
echo "PASSED: pylint is happy"
exit 0
else
echo "FAILED: please run the pylint command above and make sure it passes"
exit 1
fi
submodules: 'recursive'

- name: clang-tidy
run: |
Expand All @@ -145,27 +84,27 @@ jobs:

build_and_test_cpu_linux:
name: Build and Test linux (CPU)
needs: [check_code_format, check_files]
needs: check_files
timeout-minutes: 60
strategy:
matrix:
include:
- os: ubuntu-latest
python: py39
with_cc: ON
wanted_archs: "cpu,cc"
wanted_archs: 'cpu,cc'
- os: ubuntu-latest
python: py310
with_cc: ON
wanted_archs: "cpu,cc"
wanted_archs: 'cpu,cc'
runs-on: ${{ matrix.os }}
permissions:
packages: read
contents: read
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
submodules: 'recursive'

- name: Get sccache cache
uses: actions/cache@v2
Expand Down Expand Up @@ -234,7 +173,7 @@ jobs:
build_and_test_cpu_mac:
name: Build and Test macos (CPU)
needs: [check_code_format, check_files]
needs: check_files
timeout-minutes: 60
strategy:
matrix:
Expand All @@ -243,12 +182,12 @@ jobs:
python: 3.7
with_cc: OFF
with_cpp_tests: ON
wanted_archs: "cpu"
wanted_archs: 'cpu'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
submodules: 'recursive'

- uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -302,13 +241,13 @@ jobs:

build_and_test_gpu_linux:
name: Build and Test (GPU)
needs: [check_code_format, check_files]
needs: check_files
runs-on: [self-hosted, cuda, vulkan, cn]
timeout-minutes: 60
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
submodules: 'recursive'

- name: Get sccache cache
uses: actions/cache@v2
Expand Down Expand Up @@ -364,7 +303,7 @@ jobs:
PY: py38
GPU_TEST: ON
DISPLAY: :1
TI_WANTED_ARCHS: "cpu,cuda,vulkan,opengl"
TI_WANTED_ARCHS: 'cpu,cuda,vulkan,opengl'
TI_DEVICE_MEMORY_GB: '0.7'

- name: clean docker container
Expand All @@ -374,7 +313,7 @@ jobs:
build_and_test_windows:
name: Build and Test Windows
needs: [check_code_format, check_files]
needs: check_files
runs-on: [self-hosted, windows, gpu]
timeout-minutes: 90
steps:
Expand All @@ -386,7 +325,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: "recursive"
submodules: 'recursive'

- uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -421,12 +360,12 @@ jobs:
TAICHI_CMAKE_ARGS: -DTI_WITH_OPENGL:BOOL=ON -DTI_WITH_CC:BOOL=OFF
TI_SKIP_VERSION_CHECK: ON
TI_CI: 1
PYTHON: "3.7"
PYTHON: '3.7'
TI_DEVICE_MEMORY_GB: '0.7'

build_and_test_m1:
name: Build and Test (Apple M1)
needs: [check_code_format, check_files]
needs: check_files
timeout-minutes: 60
strategy:
matrix:
Expand All @@ -436,12 +375,12 @@ jobs:
defaults:
run:
# https://github.com/actions/runner/issues/805#issuecomment-844426478
shell: "/usr/bin/arch -arch arm64e /bin/bash --noprofile --norc -eo pipefail {0}"
shell: '/usr/bin/arch -arch arm64e /bin/bash --noprofile --norc -eo pipefail {0}'
runs-on: [self-hosted, m1]
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
submodules: 'recursive'

- name: Get sccache cache
uses: actions/cache@v2
Expand Down Expand Up @@ -472,7 +411,7 @@ jobs:
export PATH=/Users/github/miniforge3/envs/$PY/bin:$PATH
.github/workflows/scripts/unix_test.sh
env:
TI_WANTED_ARCHS: "metal,vulkan,cpu"
TI_WANTED_ARCHS: 'metal,vulkan,cpu'
PY: ${{ matrix.python }}
PLATFORM: "m1"
PLATFORM: 'm1'
TI_CI: 1
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ci:
autoupdate_schedule: quarterly

exclude: ^((tests/python/test_exception|.*/examples/.*)\.py$|external/)
repos:
- repo: https://github.com/google/yapf
rev: v0.31.0
hooks:
- id: yapf
additional_dependencies: [toml]

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v10.0.1
hooks:
- id: clang-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/PyCQA/pylint
rev: v2.13.1
hooks:
- id: pylint
args: ['-rn', '-sn']
files: ^python/taichi/
7 changes: 6 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[MESSAGES CONTROL]
disable=invalid-name, missing-function-docstring, missing-class-docstring, missing-module-docstring, unused-wildcard-import, cyclic-import, blacklisted-name, import-outside-toplevel
disable=all
enable=
C0121,C0200,C0209,C0321,C0325,C0415,
W0101,W0108,W0202,W0235,W0401,W0404,W0611,W0621,W0622,W612,W1309,
E1101,
R0201,R0205,R0402,R1703,R1705,R1710,R1732
22 changes: 11 additions & 11 deletions ci/scripts/release_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function taichi::test::ggui {
# divider
taichi::utils::line
taichi::utils::logger::info "Running GGUI examples"

# clone the repo
taichi::utils::git_clone "${ORG}" "${REPO}"
cd "${REPO}/python/taichi/examples/ggui_examples"
Expand All @@ -114,7 +114,7 @@ function taichi::test::difftaichi {
# divider
taichi::utils::line
taichi::utils::logger::info "Running DiffTaichi examples"

# clone the repo
taichi::utils::git_clone "${ORG}" "${REPO}"
cd "${REPO}/examples"
Expand All @@ -139,7 +139,7 @@ function taichi::test::taichi_elements {
# divider
taichi::utils::line
taichi::utils::logger::info "Running Taichi Elements examples"

# clone the repo
taichi::utils::git_clone "${ORG}" "${REPO}"
cd "${REPO}"
Expand All @@ -148,7 +148,7 @@ function taichi::test::taichi_elements {
python "download_ply.py"

# run tests
cd "${REPO}/demo"
cd "${REPO}/demo"
for match in $(find ./ -name "${PATTERN}"); do
python "${match}"
taichi::utils::line
Expand Down Expand Up @@ -179,7 +179,7 @@ function taichi::test::stannum {
# divider
taichi::utils::line
taichi::utils::logger::info "Running Stannum examples"

# clone the repo
taichi::utils::git_clone "${ORG}" "${REPO}"
cd "${REPO}"
Expand All @@ -199,7 +199,7 @@ function taichi::test::sandyfluid {
# divider
taichi::utils::line
taichi::utils::logger::info "Running SandyFluid examples"

# clone the repo
taichi::utils::git_clone "${ORG}" "${REPO}"
cd "${REPO}"
Expand All @@ -224,7 +224,7 @@ function taichi::test::voxel_editor {
# divider
taichi::utils::line
taichi::utils::logger::info "Running Voxel Editor examples"

# clone the repo
taichi::utils::git_clone "${ORG}" "${REPO}"
cd "${REPO}"
Expand All @@ -245,7 +245,7 @@ function taichi::test::generate_videos {
# divider
taichi::utils::line
taichi::utils::logger::info "Generating examples videos"

# clone the repo
taichi::utils::git_clone "${ORG}" "${REPO}"
# mkdir "${REPO}/misc/output_videos"
Expand Down Expand Up @@ -282,7 +282,7 @@ function taichi::test::main {

# ggui examples
taichi::test::ggui "${WORKDIR}"

# difftaichi examples
taichi::test::difftaichi "${WORKDIR}"

Expand All @@ -292,10 +292,10 @@ function taichi::test::main {
# stannum tests
taichi::test::stannum "${WORKDIR}"

# sandyfluid tests
# sandyfluid tests
taichi::test::sandyfluid "${WORKDIR}"

# voxel editor tests
# voxel editor tests
taichi::test::voxel_editor "${WORKDIR}"

# generating example videos
Expand Down
Loading

0 comments on commit 2cdc580

Please sign in to comment.