From 7a6a09a1705d9969f3d6e47672366275a45bc7d4 Mon Sep 17 00:00:00 2001
From: "Xuefeng Ding (IHEP)" <dingxf@ihep.ac.cn>
Date: Thu, 14 Nov 2024 03:03:50 +0800
Subject: [PATCH] update

---
 .gitignore                                    |  2 +-
 .pre-commit-config.yaml                       | 25 ++++++
 .vscode/settings.json                         |  4 +
 CMakeLists.txt                                |  2 +-
 README.md                                     | 87 +++++++++++++++++--
 cpp/CMakeLists.txt                            |  2 +-
 cpp/include/complex.h                         |  2 +-
 cpp/include/hello.h                           |  2 +-
 cpp/src/complex.cc                            |  3 +-
 cpp/src/hello.cc                              |  2 +-
 noxfile.py                                    |  9 ++
 pyproject.toml                                |  2 +-
 python/myproj/simulation/_csrc/CMakeLists.txt |  2 +-
 .../myproj/simulation/_csrc/_hello_python.cc  |  2 +-
 14 files changed, 131 insertions(+), 15 deletions(-)

diff --git a/.gitignore b/.gitignore
index b00d830..f066e9c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
 __pycache__/
 build/
 .cache/
-.venv/
\ No newline at end of file
+.venv/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e2124a3..1bffa63 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,31 @@
 repos:
+  - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/pre-commit/pre-commit-hooks
+    rev: v5.0.0
+    hooks:
+      - id: check-added-large-files
+      - id: check-case-conflict
+      - id: check-merge-conflict
+      - id: check-symlinks
+      - id: check-yaml
+      - id: debug-statements
+      - id: end-of-file-fixer
+      - id: mixed-line-ending
+      - id: requirements-txt-fixer
+      - id: trailing-whitespace
+
   - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/kynan/nbstripout
     rev: 0.8.0
     hooks:
       - id: nbstripout
         files: \.ipynb$
+
+  - 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)$
+
+  - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/psf/black
+    rev: 24.10.0 # Use the latest stable version
+    hooks:
+      - id: black
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 8657f3f..97453c1 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -5,6 +5,10 @@
     },
     "editor.defaultFormatter": "ms-python.black-formatter"
   },
+  "[cpp]": {
+    "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
+  },
+  "editor.formatOnSave": true,
   "isort.args": ["--profile", "black"],
   "notebook.lineNumbers": "on"
 }
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3ed9ab..56217e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,4 +8,4 @@ project("${SKBUILD_PROJECT_NAME}"
 # include(GNUInstallDirs)
 add_subdirectory(cpp)
 
-add_subdirectory(python/myproj/simulation/_csrc)
\ No newline at end of file
+add_subdirectory(python/myproj/simulation/_csrc)
diff --git a/README.md b/README.md
index e259da8..ad6f472 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ use scikit-build-core to setup a python-cmake project that can be installed with
 ## Conclusion
 
 - package name has nothing to do with the import path. pacakge named my_package is installed with `pip install .`, uninstalled with `pip uninstall my_package`, but can be used as `import kk.ss as ks`.
-- installation of cpp files: 
+- installation of cpp files:
 ```cmake
 install(TARGET mylib LIBRARY DESTINATION .)
 ```
@@ -47,7 +47,7 @@ wheel.exclude = ["CMakeLists.txt","*.cc","*.h"]
   wheel.
 
 ## style and lint check
-### notebook otuput stripping
+### notebook output stripping
 - use pre-commit
 1. install
 ```bash
@@ -56,16 +56,93 @@ pip install pre-commit nbstripout
 2. set
 ```yaml
 repos:
-  - repo: https://github.com/kynan/nbstripout
-    rev: master  # Pin to a specific version if desired
+  - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/kynan/nbstripout
+    rev: 0.8.0
     hooks:
       - id: nbstripout
         files: \.ipynb$
 ```
-3. install  
+3. install
 ```bash
 pre-commit install
 ```
+4. run and verify
+```bash
+pre-commit run --all-files
+```
+or
+```bash
+nox -s pre_commit
+```
+
+### c++ formating
+- pre-commit + vscode extensions
+- install extensions
+```
+Name: clangd
+Id: llvm-vs-code-extensions.vscode-clangd
+Description: C/C++ completion, navigation, and insights
+Version: 0.1.30
+Publisher: LLVM
+VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
+```
+and make sure this is in `settings.json`:
+```json
+  "[cpp]": {
+    "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
+  }
+```
+- install pre-commit hooks
+Name: Black Formatter
+Id: ms-python.black-formatter
+Description: Formatting support for Python files using the Black formatter.
+Version: 2024.4.0
+Publisher: Microsoft
+VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
+```yaml
+- 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)$
+```
+
+### python formatting
+- pre-commit + vscode extensions
+- install vscode extensions
+- install extensions
+```
+Name: Black Formatter
+Id: ms-python.black-formatter
+Description: Formatting support for Python files using the Black formatter.
+Version: 2024.4.0
+Publisher: Microsoft
+VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
+```
+and update `settings.json`
+```json
+  "[python]": {
+    "editor.codeActionsOnSave": {
+      "source.organizeImports": "always"
+    },
+    "editor.defaultFormatter": "ms-python.black-formatter"
+  },
+  "isort.args": ["--profile", "black"],
+```
+- install pre-commit hooks
+```
+repos:
+  - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/psf/black
+    rev: 24.10.0  # Use the latest stable version
+    hooks:
+      - id: black
+```
+### c++ lint
+- nox + vscode extensions
+
+### python lint
+- ruff: pre-commit + vscode extensions
+- pylint: nox + vscode extensions
 
 ## vscode extensions to install
 - "isort", which sort python import
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index add6489..2dedfcf 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -21,4 +21,4 @@ set_target_properties(complex PROPERTIES
 # install(
 # EXPORT helloTargets
 # NAMESPACE hello::
-# DESTINATION ${HELLO_CMAKE_PACKAGE_INSTALL_SUBDIR})
\ No newline at end of file
+# DESTINATION ${HELLO_CMAKE_PACKAGE_INSTALL_SUBDIR})
diff --git a/cpp/include/complex.h b/cpp/include/complex.h
index 72d4d9a..0ebcf62 100644
--- a/cpp/include/complex.h
+++ b/cpp/include/complex.h
@@ -1,3 +1,3 @@
 #pragma once
 
-double complex(double a, double b);
\ No newline at end of file
+double complex(double a, double b);
diff --git a/cpp/include/hello.h b/cpp/include/hello.h
index 4c8c541..9c9beb9 100644
--- a/cpp/include/hello.h
+++ b/cpp/include/hello.h
@@ -1,3 +1,3 @@
 #pragma once
 
-double add(double a, double b);
\ No newline at end of file
+double add(double a, double b);
diff --git a/cpp/src/complex.cc b/cpp/src/complex.cc
index 4299798..3114e15 100644
--- a/cpp/src/complex.cc
+++ b/cpp/src/complex.cc
@@ -1,3 +1,4 @@
 #include "complex.h"
 #include "hello.h"
-double complex(double a, double b) { return add(a, b) + 2; }
\ No newline at end of file
+
+double complex(double a, double b) { return add(a, b) + 2; }
diff --git a/cpp/src/hello.cc b/cpp/src/hello.cc
index 80e43e2..6f4948a 100644
--- a/cpp/src/hello.cc
+++ b/cpp/src/hello.cc
@@ -1,3 +1,3 @@
 #include "hello.h"
 
-double add(double a, double b) { return a + b; }
\ No newline at end of file
+double add(double a, double b) { return a + b; }
diff --git a/noxfile.py b/noxfile.py
index 5fe4057..a611171 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -10,6 +10,15 @@ import nox
 DIR = Path(__file__).parent.resolve()
 
 
+@nox.session(venv_backend="none")
+def pre_commit(session: nox.Session) -> None:
+    """
+    Run pre-commit
+    """
+    if "pre_commit" in sys.argv:
+        session.run("pre-commit", "run", "--all-files")
+
+
 @nox.session(venv_backend="none")
 def dev(session: nox.Session) -> None:
     """
diff --git a/pyproject.toml b/pyproject.toml
index 59c184d..8ed0c30 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -63,4 +63,4 @@ disable = [
     "C0114",  # Missing module docstring
     "C0115",  # Missing class docstring
     "C0116"  # Missing function or method docstring
-]
\ No newline at end of file
+]
diff --git a/python/myproj/simulation/_csrc/CMakeLists.txt b/python/myproj/simulation/_csrc/CMakeLists.txt
index d5baf7b..3103c4a 100644
--- a/python/myproj/simulation/_csrc/CMakeLists.txt
+++ b/python/myproj/simulation/_csrc/CMakeLists.txt
@@ -6,4 +6,4 @@ target_link_libraries(_hello PRIVATE hello complex)
 install(TARGETS _hello DESTINATION _csrc)
 set_target_properties(_hello PROPERTIES
     INSTALL_RPATH "$ORIGIN/.."
-)
\ No newline at end of file
+)
diff --git a/python/myproj/simulation/_csrc/_hello_python.cc b/python/myproj/simulation/_csrc/_hello_python.cc
index feaeae7..21078d9 100644
--- a/python/myproj/simulation/_csrc/_hello_python.cc
+++ b/python/myproj/simulation/_csrc/_hello_python.cc
@@ -9,4 +9,4 @@ PYBIND11_MODULE(_hello, m) {
 
   m.def("add", &add, "A function which adds two numbers");
   m.def("complex", &complex, "complex(a,b) = add(a,b) + 2");
-}
\ No newline at end of file
+}
-- 
GitLab