Skip to content

Commit 468eb21

Browse files
authored
Add GitHub action to format and lint code (#96)
* Add pre-commit hook * Run commit hooks, remove ignored word list * Add GitHub action * Add Java to Clang * Fix pre-commit to include all Python files * Remove old formatter * Remove unused skipped files * Remove codeql because no more Python * Add more pre-commit filetype checkers * Trim whitespace hook * Remove unnecessary dependency * Add mixed-line-ending and case-conflicts checks * Add copyright * Update max-line-length * Remove unnecessary line * End of file * Fix comment * Add and apply isort * Remove duplicate copyrights, add hooks link * Pin workflow Ubuntu version * Flake8 Black style, move Flake8 conf to toml * Alphabetize configs by tool * Move flake8 back into pre-commit-config * Restore clang-format file * Eof newline * Fix yaml spacing * Normalize spacing * Normalize config indentation * Update line limit in clang-format to 80 chars * Update workflows to run on every PR * Run pre-commit
1 parent a2de06f commit 468eb21

14 files changed

+165
-262
lines changed

.clang-format

+2-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,4 @@ BinPackArguments: true
3435
BinPackParameters: true
3536
ConstructorInitializerAllOnOneLineOrOnePerLine: false
3637

37-
IndentCaseLabels: true
38+
IndentCaseLabels: true

.github/workflows/codeql.yml

-90
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/bin/bash
2-
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
32
#
43
# Redistribution and use in source and binary forms, with or without
54
# modification, are permitted provided that the following conditions
@@ -25,32 +24,15 @@
2524
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2625
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2726

28-
###############################################################################
29-
#
30-
# Git pre-commit hook for Triton related projects
31-
#
32-
# To install this hook for a project, copy "pre-commit" and "format.py" into
33-
# ".git/hooks/" directory of the project
34-
#
35-
###############################################################################
36-
37-
###############################################################################
38-
#
39-
# Run formatter script
40-
#
41-
###############################################################################
42-
43-
# Repo root
44-
GIT_REPO_ROOT=$(git rev-parse --show-toplevel)
45-
46-
PYTHON_CMD=python3
47-
FORMATTER_PY=${GIT_REPO_ROOT}/.git/hooks/format.py
27+
name: pre-commit
4828

49-
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '{ if (match($1, /R[0-9]+/)) { print $3 } else if ($1 != "D") { print $2 } }')"
29+
on:
30+
pull_request:
5031

51-
echo "Running Python auto-format..."
52-
for CHANGED_FILE in $CHANGED_FILES;
53-
do
54-
${PYTHON_CMD} ${FORMATTER_PY} ${GIT_REPO_ROOT}/${CHANGED_FILE}
55-
git add ${GIT_REPO_ROOT}/${CHANGED_FILE}
56-
done
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

cmake/TritonCommonConfig.cmake.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ check_required_components(triton-common-json
4343
triton-common-thread-pool
4444
)
4545

46-
set(TRITONCOMMON_LIBRARIES
46+
set(TRITONCOMMON_LIBRARIES
4747
TritonCommon::triton-common-json
4848
TritonCommon::triton-common-sync-queue
4949
TritonCommon::triton-common-async-work-queue

include/triton/common/model_config.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,28 @@ enum Platform {
7171
/// \param dims The shape.
7272
/// \return The number of elements, or -1 if the number of elements
7373
/// cannot be determined because the shape contains one or more
74-
/// wilcard dimensions.
74+
/// wildcard dimensions.
7575
int64_t GetElementCount(const DimsList& dims);
7676

7777
/// Get the number of elements in a shape.
7878
/// \param dims The shape.
7979
/// \return The number of elements, or -1 if the number of elements
8080
/// cannot be determined because the shape contains one or more
81-
/// wilcard dimensions.
81+
/// wildcard dimensions.
8282
int64_t GetElementCount(const std::vector<int64_t>& dims);
8383

8484
/// Get the number of elements in the shape of a model input.
8585
/// \param mio The model input.
8686
/// \return The number of elements, or -1 if the number of elements
8787
/// cannot be determined because the shape contains one or more
88-
/// wilcard dimensions.
88+
/// wildcard dimensions.
8989
int64_t GetElementCount(const inference::ModelInput& mio);
9090

9191
/// Get the number of elements in the shape of a model output.
9292
/// \param mio The model output.
9393
/// \return The number of elements, or -1 if the number of elements
9494
/// cannot be determined because the shape contains one or more
95-
/// wilcard dimensions.
95+
/// wildcard dimensions.
9696
int64_t GetElementCount(const inference::ModelOutput& mio);
9797

9898
/// Are values of a datatype fixed-size, or variable-sized.

include/triton/common/triton_json.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class TritonJson {
373373
return TRITONJSON_STATUSSUCCESS;
374374
}
375375

376-
// Add a reference to a expicit-length string as a new member to
376+
// Add a reference to a explicit-length string as a new member to
377377
// this value. It is assumed that 'name' and 'value' can be used
378378
// by reference, it is the caller's responsibility to make sure
379379
// the lifetime of 'name' and 'value' extend at least as long as
@@ -531,7 +531,7 @@ class TritonJson {
531531
return TRITONJSON_STATUSSUCCESS;
532532
}
533533

534-
// Append a reference to a expicit-length string to this value,
534+
// Append a reference to a explicit-length string to this value,
535535
// which must be an array. It is assumed that 'value' can be used
536536
// by reference, it is the caller's responsibility to make sure
537537
// the lifetime of 'value' extends at least as long as the object.
@@ -688,7 +688,7 @@ class TritonJson {
688688
return false;
689689
}
690690

691-
// Whether the object is null value. Note that false will also be retuned
691+
// Whether the object is null value. Note that false will also be returned
692692
// if the object is not a JSON value.
693693
bool IsNull() const { return ((value_ != nullptr) && value_->IsNull()); }
694694

protobuf/grpc_service.proto

+3-3
Original file line numberDiff line numberDiff line change
@@ -994,23 +994,23 @@ message InferStatistics
994994
//@@ cache. On a cache miss, the request hash and response output tensor
995995
//@@ data is added to the cache. See response cache docs for more info:
996996
//@@
997-
//https://github.com/triton-inference-server/server/blob/main/docs/response_cache.md
997+
// https://github.com/triton-inference-server/server/blob/main/docs/response_cache.md
998998
//@@
999999
StatisticDuration cache_hit = 7;
10001000

10011001
//@@ .. cpp:var:: StatisticDuration cache_miss
10021002
//@@
10031003
//@@ The count of response cache misses and cumulative duration to lookup
10041004
//@@ and insert output tensor data from the computed response to the
1005-
//cache.
1005+
// cache.
10061006
//@@ For example, this duration should include the time to copy
10071007
//@@ output tensor data from the response object to the Response Cache.
10081008
//@@ Assuming the response cache is enabled for a given model, a cache
10091009
//@@ miss occurs for a request to that model when the request metadata
10101010
//@@ does NOT hash to an existing entry in the cache. See the response
10111011
//@@ cache docs for more info:
10121012
//@@
1013-
//https://github.com/triton-inference-server/server/blob/main/docs/response_cache.md
1013+
// https://github.com/triton-inference-server/server/blob/main/docs/response_cache.md
10141014
//@@
10151015
StatisticDuration cache_miss = 8;
10161016
}

0 commit comments

Comments
 (0)