Skip to content

Commit

Permalink
complete c++ format check
Browse files Browse the repository at this point in the history
  • Loading branch information
lipracer committed Jul 12, 2024
1 parent 9823d93 commit ec5c3aa
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 37 deletions.
56 changes: 50 additions & 6 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,55 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Fetch sources
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install clang-format
run: sudo apt-get install -y clang-format
- name: Checkout through merge base
uses: rmacklin/fetch-through-merge-base@v0
with:
base_ref: ${{ github.event.pull_request.base.ref }}
head_ref: ${{ github.event.pull_request.head.sha }}
deepen_length: 500

- name: Run clang-format
run: bash script/format-check.sh
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v39
with:
separator: ","
skip_initial_fetch: true
- name: "Listed files"
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Formatting files:"
echo "$CHANGED_FILES"
- name: Install clang-format
uses: aminya/setup-cpp@v1
with:
clangformat: 18.1.7

- name: Run clang-format
env:
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
START_REV: ${{ github.event.pull_request.base.sha }}
END_REV: ${{ github.event.pull_request.head.sha }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Changed C++ files: $CHANGED_FILES"
# Check format for each changed file
python -c "import sys;[print(file) for file in filter(lambda x:(x.endswith('h') or x.endswith('h') or x.endswith('hpp') or x.endswith('hxx') or x.endswith('c') or x.endswith('cxx') or x.endswith('cpp')), sys.argv[1].split(','))]" $CHANGED_FILES | xargs -I {} clang-format -i {}
- name: Check for unformatted code
run: |
# Check if any files were changed by clang-format
if [[ $(git status --porcelain) ]]; then
echo "The following files are not formatted correctly:"
git diff --name-only
exit 1
else
echo "All files are formatted correctly."
fi
1 change: 0 additions & 1 deletion include/cuda_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void dh_create_py_hook_installer(
// for runtime check python version build vs runtime
const char* get_build_python_string_version();
int get_build_python_int_version();

}

void install_triton_hook();
Expand Down
23 changes: 0 additions & 23 deletions script/format-check.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/cuda_mock/cuda_mock_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def patch_runtime():
return cuda_mock_impl.patch_runtime()

def test_any_hook():
return cuda_mock_impl.dh_any_hook_install()
return cuda_mock_impl.any_hook_install()

def log(*args, level=0):
caller_frame = inspect.currentframe().f_back
Expand Down
12 changes: 6 additions & 6 deletions src/cuda_mock_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ HOOK_API void print_hook_start_capture() { __print_hook_start_capture(); }
HOOK_API void print_hook_end_capture(PyObject* py_instance) {
auto cpp_string = __print_hook_end_capture();
LOG(INFO) << "__print_hook_end_capture:" << cpp_string;
// Always initialize threads at startup, like in Py_Initialize for Cpython3.9
// https://doc.pypy.org/en/latest/release-v7.3.14.html#id2
// Always initialize threads at startup, like in Py_Initialize for
// Cpython3.9 https://doc.pypy.org/en/latest/release-v7.3.14.html#id2
#ifndef PYPY_VERSION
Py_Initialize();
#endif
Expand All @@ -131,8 +131,8 @@ HOOK_API void patch_runtime() { dh_patch_runtime(); }

HOOK_API bool call_python_method_bool(PyObject* py_instance, HookString_t name,
HookString_t value) {
// Always initialize threads at startup, like in Py_Initialize for Cpython3.9
// https://doc.pypy.org/en/latest/release-v7.3.14.html#id2
// Always initialize threads at startup, like in Py_Initialize for
// Cpython3.9 https://doc.pypy.org/en/latest/release-v7.3.14.html#id2
#ifndef PYPY_VERSION
Py_Initialize();
#endif
Expand Down Expand Up @@ -162,8 +162,8 @@ HOOK_API bool call_python_method_bool(PyObject* py_instance, HookString_t name,
HOOK_API HookString_t call_python_method_string(PyObject* py_instance,
HookString_t name,
HookString_t value) {
// Always initialize threads at startup, like in Py_Initialize for Cpython3.9
// https://doc.pypy.org/en/latest/release-v7.3.14.html#id2
// Always initialize threads at startup, like in Py_Initialize for
// Cpython3.9 https://doc.pypy.org/en/latest/release-v7.3.14.html#id2
#ifndef PYPY_VERSION
Py_Initialize();
#endif
Expand Down

0 comments on commit ec5c3aa

Please sign in to comment.