Skip to content
Snippets Groups Projects
Commit 7a6a09a1 authored by Xuefeng Ding's avatar Xuefeng Ding
Browse files

update

parent 0ab6f9c8
No related branches found
No related tags found
No related merge requests found
__pycache__/
build/
.cache/
.venv/
\ No newline at end of file
.venv/
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
......@@ -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"
}
......@@ -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)
......@@ -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
......
......@@ -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})
#pragma once
double complex(double a, double b);
\ No newline at end of file
double complex(double a, double b);
#pragma once
double add(double a, double b);
\ No newline at end of file
double add(double a, double b);
#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; }
#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; }
......@@ -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:
"""
......
......@@ -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
]
......@@ -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
)
......@@ -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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment