Skip to content

Commit 304c2e8

Browse files
authored
Add GitHub action to format and lint code (triton-inference-server#116)
* Add and run pre-commit hooks * Restore clang-format * Fix yaml spacing * Normalize spacing * Normalize config indentation * Update line limit in clang-format to 80 chars * Update workflows to run on every PR * Update copyright
1 parent 00b38a9 commit 304c2e8

File tree

7 files changed

+169
-7
lines changed

7 files changed

+169
-7
lines changed

.clang-format

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
BasedOnStyle: Google
33

44
IndentWidth: 2
5+
ColumnLimit: 80
56
ContinuationIndentWidth: 4
67
UseTab: Never
78
MaxEmptyLinesToKeep: 2
@@ -34,4 +35,5 @@ BinPackArguments: true
3435
BinPackParameters: true
3536
ConstructorInitializerAllOnOneLineOrOnePerLine: false
3637

37-
IndentCaseLabels: true
38+
IndentCaseLabels: true
39+

.github/workflows/pre-commit.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions
5+
# are met:
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
# * Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# * Neither the name of NVIDIA CORPORATION nor the names of its
12+
# contributors may be used to endorse or promote products derived
13+
# from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
16+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
name: pre-commit
28+
29+
on:
30+
pull_request:
31+
32+
jobs:
33+
pre-commit:
34+
runs-on: ubuntu-22.04
35+
steps:
36+
- uses: actions/checkout@v3
37+
- uses: actions/setup-python@v3
38+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions
5+
# are met:
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
# * Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# * Neither the name of NVIDIA CORPORATION nor the names of its
12+
# contributors may be used to endorse or promote products derived
13+
# from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
16+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
repos:
28+
- repo: https://github.com/timothycrosley/isort
29+
rev: 5.12.0
30+
hooks:
31+
- id: isort
32+
additional_dependencies: [toml]
33+
- repo: https://github.com/psf/black
34+
rev: 23.1.0
35+
hooks:
36+
- id: black
37+
types_or: [python, cython]
38+
- repo: https://github.com/PyCQA/flake8
39+
rev: 5.0.4
40+
hooks:
41+
- id: flake8
42+
args: [--max-line-length=88, --select=C,E,F,W,B,B950, --extend-ignore = E203,E501]
43+
types_or: [python, cython]
44+
- repo: https://github.com/pre-commit/mirrors-clang-format
45+
rev: v16.0.5
46+
hooks:
47+
- id: clang-format
48+
types_or: [c, c++, cuda, proto, textproto, java]
49+
args: ["-fallback-style=none", "-style=file", "-i"]
50+
- repo: https://github.com/codespell-project/codespell
51+
rev: v2.2.4
52+
hooks:
53+
- id: codespell
54+
additional_dependencies: [tomli]
55+
args: ["--toml", "pyproject.toml"]
56+
exclude: (?x)^(.*stemmer.*|.*stop_words.*|^CHANGELOG.md$)
57+
# More details about these pre-commit hooks here:
58+
# https://pre-commit.com/hooks.html
59+
- repo: https://github.com/pre-commit/pre-commit-hooks
60+
rev: v4.4.0
61+
hooks:
62+
- id: check-case-conflict
63+
- id: check-executables-have-shebangs
64+
- id: check-merge-conflict
65+
- id: check-json
66+
- id: check-toml
67+
- id: check-yaml
68+
- id: check-shebang-scripts-are-executable
69+
- id: end-of-file-fixer
70+
types_or: [c, c++, cuda, proto, textproto, java, python]
71+
- id: mixed-line-ending
72+
- id: requirements-txt-fixer
73+
- id: trailing-whitespace

CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright 2019-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -85,7 +85,7 @@ find_package(Python3 REQUIRED COMPONENTS Development)
8585
#
8686
# Dependencies
8787
#
88-
# FetchContent's composibility isn't very good. We must include the
88+
# FetchContent's composability isn't very good. We must include the
8989
# transitive closure of all repos so that we can override the tag.
9090
#
9191
include(FetchContent)
@@ -181,7 +181,7 @@ set(OPENCV_LIBS
181181
"libopencv_highgui.so"
182182
"libopencv_imgcodecs.so"
183183
"libopencv_imgproc.so"
184-
"libopencv_core.so"
184+
"libopencv_core.so"
185185
"libopencv_calib3d.so"
186186
"libopencv_flann.so"
187187
"libopencv_features2d.so"
@@ -190,7 +190,7 @@ set(OPENCV_LIBS
190190
)
191191

192192
# The patchelf commands ensure the MKL libraries are loaded correctly during runtime
193-
# Without these, the framework/backend complains of missing libraries / symbols and
193+
# Without these, the framework/backend complains of missing libraries / symbols and
194194
# in some cases leads to segmentation faults.
195195
if (${TRITON_PYTORCH_DOCKER_BUILD})
196196
string(REPLACE ";" " " LIBTORCH_LIBS_STR "${LIBTORCH_LIBS}")

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ complex execution modes and dynamic shapes. If not specified, all are enabled by
206206

207207
`ENABLE_TENSOR_FUSER`
208208

209-
### Support
209+
### Support
210210

211211
#### Model Instance Group Kind
212212

pyproject.toml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions
5+
# are met:
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
# * Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# * Neither the name of NVIDIA CORPORATION nor the names of its
12+
# contributors may be used to endorse or promote products derived
13+
# from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
16+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
[tool.codespell]
28+
# note: pre-commit passes explicit lists of files here, which this skip file list doesn't override -
29+
# this is only to allow you to run codespell interactively
30+
skip = "./.git,./.github"
31+
# ignore short words, and typename parameters like OffsetT
32+
ignore-regex = "\\b(.{1,4}|[A-Z]\\w*T)\\b"
33+
# use the 'clear' dictionary for unambiguous spelling mistakes
34+
builtin = "clear"
35+
# disable warnings about binary files and wrong encoding
36+
quiet-level = 3
37+
38+
[tool.isort]
39+
profile = "black"
40+
use_parentheses = true
41+
multi_line_output = 3
42+
include_trailing_comma = true
43+
force_grid_wrap = 0
44+
ensure_newline_before_comments = true
45+
line_length = 88
46+
balanced_wrapping = true
47+
indent = " "
48+
skip = ["build"]
49+

src/libtorch.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ ModelInstanceState::Execute(
15521552
std::get<1>(model_state_->EnabledJitExecutor());
15531553
}
15541554

1555-
// Fuser. Parameter is ignored if NVFuser parameter is explicitily
1555+
// Fuser. Parameter is ignored if NVFuser parameter is explicitly
15561556
// set (either enabled or disabled). No change is made unless
15571557
// fuser is explicitly set in parameters.
15581558
if (!std::get<0>(model_state_->EnabledNvfuserPair()) &&

0 commit comments

Comments
 (0)