Separate linters from cmake (#587)

This commit is contained in:
Changho Hwang
2025-07-28 09:59:20 +08:00
committed by GitHub
parent 01e72f3aca
commit 5b84c8a3d1
6 changed files with 83 additions and 105 deletions

View File

@@ -19,27 +19,25 @@ jobs:
sudo apt-get install -y clang-format
- name: Run cpplint
run: |
CPPSOURCES=$(find ./src ./include ./python ./test ./apps -regextype posix-extended -regex '.*\.(c|cpp|h|hpp|cc|cxx|cu)')
clang-format -style=file --verbose --Werror --dry-run ${CPPSOURCES}
run: bash ./tools/lint.sh cpp dry
pylint:
runs-on: ubuntu-22.04
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3
- name: Check out Git repository
uses: actions/checkout@v4
- name: Install Python dependencies
run: python3 -m pip install black
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3
- name: Run black
run: python3 -m black --check --config pyproject.toml .
- name: Install Python dependencies
run: python3 -m pip install black
- name: Run black
run: bash ./tools/lint.sh py dry
spelling:
runs-on: ubuntu-22.04

View File

@@ -119,9 +119,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(DEBUG_BUILD)
endif()
# Format targets
include(${PROJECT_SOURCE_DIR}/cmake/AddFormatTargets.cmake)
find_package(IBVerbs)
find_package(NUMA REQUIRED)
find_package(Threads REQUIRED)

View File

@@ -1,38 +0,0 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# Add targets to run clang-format and black
add_custom_target(check-format)
add_custom_target(format)
find_program(CLANG_FORMAT clang-format)
if(CLANG_FORMAT)
message(STATUS "Found clang-format: ${CLANG_FORMAT}")
set(FIND_DIRS ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/python ${PROJECT_SOURCE_DIR}/test ${PROJECT_SOURCE_DIR}/apps/nccl/src)
add_custom_target(check-format-cpp ALL
COMMAND ${CLANG_FORMAT} -style=file --dry-run `find ${FIND_DIRS} -type f -name *.h -o -name *.hpp -o -name *.c -o -name *.cc -o -name *.cpp -o -name *.cu`
)
add_dependencies(check-format check-format-cpp)
add_custom_target(format-cpp
COMMAND ${CLANG_FORMAT} -style=file -i `find ${FIND_DIRS} -type f -name *.h -o -name *.hpp -o -name *.c -o -name *.cc -o -name *.cpp -o -name *.cu`
)
add_dependencies(format format-cpp)
else()
message(STATUS "clang-format not found.")
endif()
find_program(BLACK black)
if (BLACK)
message(STATUS "Found black: ${BLACK}")
add_custom_target(check-format-py
COMMAND ${BLACK} --config ${PROJECT_SOURCE_DIR}/pyproject.toml --check ${PROJECT_SOURCE_DIR}
)
add_dependencies(check-format check-format-py)
add_custom_target(format-py
COMMAND ${BLACK} --config ${PROJECT_SOURCE_DIR}/pyproject.toml ${PROJECT_SOURCE_DIR}
)
add_dependencies(format format-py)
else()
message(STATUS "black not found.")
endif()

View File

@@ -1,44 +0,0 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# Find the GDRCopy libraries
#
# The following variables are optionally searched for defaults
# GDRCOPY_ROOT_DIR: Base directory where all GDRCopy components are found
# GDRCOPY_INCLUDE_DIR: Directory where GDRCopy headers are found
# GDRCOPY_LIB_DIR: Directory where GDRCopy libraries are found
# The following are set after configuration is done:
# GDRCOPY_FOUND
# GDRCOPY_INCLUDE_DIRS
# GDRCOPY_LIBRARIES
# An imported target MSCCLPP::gdrcopy is created if the library is found.
find_path(GDRCOPY_INCLUDE_DIRS
NAMES gdrapi.h
HINTS
${GDRCOPY_INCLUDE_DIR}
${GDRCOPY_ROOT_DIR}
${GDRCOPY_ROOT_DIR}/include)
find_library(GDRCOPY_LIBRARIES
NAMES gdrapi
HINTS
${GDRCOPY_LIB_DIR}
${GDRCOPY_ROOT_DIR}
${GDRCOPY_ROOT_DIR}/lib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GDRCopy DEFAULT_MSG GDRCOPY_INCLUDE_DIRS GDRCOPY_LIBRARIES)
mark_as_advanced(GDRCOPY_INCLUDE_DIR GDRCOPY_LIBRARIES)
if(GDRCOPY_FOUND)
if(NOT TARGET MSCCLPP::gdrcopy)
add_library(MSCCLPP::gdrcopy UNKNOWN IMPORTED)
endif()
set_target_properties(MSCCLPP::gdrcopy PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GDRCOPY_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${GDRCOPY_LIBRARIES}")
endif()

View File

@@ -6,10 +6,10 @@
__global__ void kernel() {}
int main() {
int cnt;
cudaError_t err = cudaGetDeviceCount(&cnt);
if (err != cudaSuccess || cnt == 0) {
return 1;
}
return 0;
int cnt;
cudaError_t err = cudaGetDeviceCount(&cnt);
if (err != cudaSuccess || cnt == 0) {
return 1;
}
return 0;
}

65
tools/lint.sh Executable file
View File

@@ -0,0 +1,65 @@
#!/usr/bin/env bash
PROJECT_ROOT=$(dirname "$(realpath "$0")")/..
LINT_CPP=false
LINT_PYTHON=false
DRY_RUN=false
usage() {
echo "Usage: $0 [cpp] [py] [dry]"
echo " cpp Lint C++ code"
echo " py Lint Python code"
echo " dry Dry run mode (no changes made)"
}
# Parse arguments
for arg in "$@"; do
case "$arg" in
cpp)
LINT_CPP=true
;;
py)
LINT_PYTHON=true
;;
dry)
DRY_RUN=true
;;
*)
echo "Error: Unknown argument '$arg'"
usage
exit 1
;;
esac
done
# If no cpp or py specified, default to both
if [ "$LINT_CPP" = false ] && [ "$LINT_PYTHON" = false ]; then
LINT_CPP=true
LINT_PYTHON=true
fi
if $LINT_CPP; then
echo "Linting C++ code..."
# Find all git-tracked files with .c/.h/.cpp/.hpp/.cc/.cu/.cuh extensions
files=$(git ls-files --cached | grep -E '\.(c|h|cpp|hpp|cc|cu|cuh)$')
if [ -n "$files" ]; then
if $DRY_RUN; then
clang-format -style=file --dry-run $files
else
clang-format -style=file -i $files
fi
fi
fi
if $LINT_PYTHON; then
echo "Linting Python code..."
# Find all git-tracked files with .py extension
files=$(git ls-files --cached | grep -E '\.py$')
if [ -n "$files" ]; then
if $DRY_RUN; then
python3 -m black --check --diff $files
else
python3 -m black $files
fi
fi
fi