From 5017cd44eb39cd081eba29f707de695afdfd092b Mon Sep 17 00:00:00 2001 From: "Xuefeng Ding (IHEP)" <dingxf@ihep.ac.cn> Date: Fri, 15 Nov 2024 01:04:42 +0800 Subject: [PATCH] update --- .pre-commit-config.yaml | 44 +++++++++++++++++-- .vscode/settings.json | 6 +++ CMakeLists.txt | 7 +-- README.md | 1 + cpp/CMakeLists.txt | 28 +++++------- notebooks/example.ipynb | 5 ++- pyproject.toml | 6 +-- python/myproj/simulation/_csrc/CMakeLists.txt | 9 ++-- 8 files changed, 74 insertions(+), 32 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1bffa63..af2e2d6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,7 @@ +ci: + autoupdate_commit_msg: "chore: update pre-commit hooks" + autofix_commit_msg: "style: pre-commit fixes" + repos: - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/pre-commit/pre-commit-hooks rev: v5.0.0 @@ -17,15 +21,47 @@ repos: rev: 0.8.0 hooks: - id: nbstripout - files: \.ipynb$ + types_or: [jupyter] - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/pre-commit/mirrors-clang-format rev: v19.1.3 hooks: - id: clang-format - files: \.(cpp|hpp|c|h)$ + types_or: [c++, c, cuda] - - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/psf/black + - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/psf/black-pre-commit-mirror rev: 24.10.0 # Use the latest stable version hooks: - - id: black + - id: black-jupyter + + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.7.3 # Use the latest version + hooks: + - id: ruff + args: ["--fix", "--show-fixes"] + + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + types: [file] + files: (\.cmake|CMakeLists.txt)(.in)?$ + + # - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/codespell-project/codespell + # rev: v + # hooks: + # - id: codespell + # args: ["-L", "sur,falsy,gaus,hist,lsit,nd,parms,retur,ue,ba,claus,fo"] + + # - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/pre-commit/pygrep-hooks + # rev: v + # hooks: + # - id: rst-backticks + # - id: rst-directive-colons + # - id: rst-inline-touching-normal + + # - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/shellcheck-py/shellcheck-py + # rev: v0.9.0.5 + # hooks: + # - id: shellcheck + # stages: [manual] diff --git a/.vscode/settings.json b/.vscode/settings.json index 0ce852d..2c69779 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,12 @@ }, "editor.defaultFormatter": "ms-python.black-formatter" }, + "[jupyter]": { + "editor.codeActionsOnSave": { + "source.organizeImports": "always" + }, + "editor.defaultFormatter": "ms-python.black-formatter" + }, "[cpp]": { "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd" }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 56217e4..e54ab69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.20) -project("${SKBUILD_PROJECT_NAME}" - LANGUAGES CXX - VERSION "${SKBUILD_PROJECT_VERSION}") +project( + "${SKBUILD_PROJECT_NAME}" + LANGUAGES CXX + VERSION "${SKBUILD_PROJECT_VERSION}") # set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) diff --git a/README.md b/README.md index 976a320..1e5e087 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ and set - install pre-commit - install extensions + #### pylint: nox + vscode extensions ## vscode extensions to install diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 18e508b..ebe8615 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -1,24 +1,20 @@ add_library(hello SHARED src/hello.cc) -target_include_directories(hello PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> - $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) +target_include_directories( + hello PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) install(TARGETS hello LIBRARY DESTINATION .) add_library(complexf SHARED src/complexf.cc) -target_include_directories(complexf PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> - $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) +target_include_directories( + complexf PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) target_link_libraries(complexf PRIVATE hello) install(TARGETS complexf LIBRARY DESTINATION .) -set_target_properties(complexf PROPERTIES - INSTALL_RPATH "$ORIGIN" -) +set_target_properties(complexf PROPERTIES INSTALL_RPATH "$ORIGIN") -# install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" -# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -# set(HELLO_CMAKE_PACKAGE_INSTALL_SUBDIR "share/hello/cmake") +# install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION +# ${CMAKE_INSTALL_INCLUDEDIR}) set(HELLO_CMAKE_PACKAGE_INSTALL_SUBDIR +# "share/hello/cmake") -# install( -# EXPORT helloTargets -# NAMESPACE hello:: -# DESTINATION ${HELLO_CMAKE_PACKAGE_INSTALL_SUBDIR}) +# install( EXPORT helloTargets NAMESPACE hello:: DESTINATION +# ${HELLO_CMAKE_PACKAGE_INSTALL_SUBDIR}) diff --git a/notebooks/example.ipynb b/notebooks/example.ipynb index 1f75b37..b9fb9dd 100644 --- a/notebooks/example.ipynb +++ b/notebooks/example.ipynb @@ -7,8 +7,9 @@ "outputs": [], "source": [ "import myproj.simulation as ms\n", - "print(ms.add(1,2))\n", - "print(ms.complex(1,2))" + "\n", + "print(ms.add(1, 2))\n", + "print(ms.complex(1, 2))" ] } ], diff --git a/pyproject.toml b/pyproject.toml index 8ed0c30..ff9bbf1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,9 +39,9 @@ Changelog = "https://package.readthedocs.io/en/latest/changelog.html" [tool.scikit-build.wheel.packages] "myproj/simulation" = "python/myproj/simulation" -[tool.scikit-build] -wheel.install-dir = "myproj/simulation" -wheel.exclude = ["CMakeLists.txt","*.cc","*.h"] +[tool.scikit-build.wheel] +install-dir = "myproj/simulation" +exclude = ["CMakeLists.txt","*.cc","*.h"] [tool.mypy] strict = true diff --git a/python/myproj/simulation/_csrc/CMakeLists.txt b/python/myproj/simulation/_csrc/CMakeLists.txt index 796e35d..d42c7a1 100644 --- a/python/myproj/simulation/_csrc/CMakeLists.txt +++ b/python/myproj/simulation/_csrc/CMakeLists.txt @@ -1,9 +1,10 @@ -find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) +find_package( + Python + COMPONENTS Interpreter Development.Module + REQUIRED) find_package(pybind11 CONFIG REQUIRED) pybind11_add_module(_hello MODULE _hello_python.cc) target_link_libraries(_hello PRIVATE complexf) install(TARGETS _hello DESTINATION _csrc) -set_target_properties(_hello PROPERTIES - INSTALL_RPATH "$ORIGIN/.." -) +set_target_properties(_hello PROPERTIES INSTALL_RPATH "$ORIGIN/..") -- GitLab