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

update

parent 7a6a09a1
No related branches found
No related tags found
No related merge requests found
---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 120
NamespaceIndentation: All
SortIncludes: true
IndentWidth: 2
AccessModifierOffset: -2
PenaltyBreakComment: 30
PenaltyExcessCharacter: 100
AlignAfterOpenBracket: Align
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: Yes
ReflowComments: false
BinPackArguments: false
BinPackParameters: false
Checks: >-
bugprone-*,
clang-analyzer-*,
concurrency-*,
cppcoreguidelines-*,
google-*,
hicpp-*,
llvm-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-modernize-use-trailing-return-type,
-readability-identifier-length,
-readability-magic-numbers,
-cppcoreguidelines-avoid-magic-numbers,
-bugprone-easily-swappable-parameters,
-misc-include-cleaner,
-llvm-header-guard,
-modernize-macro-to-enum,
-bugprone-use-after-move,
-hicpp-invalid-access-moved,
-misc-const-correctness
CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- {
key: readability-identifier-naming.TemplateParameterCase,
value: aNy_CasE,
}
- { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- { key: readability-identifier-naming.ClassMemberPrefix, value: f_ }
- { key: readability-identifier-naming.MethodCase, value: CamelCase }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
- { key: readability-identifier-naming.ProtectedMemberPrefix, value: m_ }
- { key: readability-identifier-naming.EnumConstantCase, value: camelBack }
- {
key: readability-identifier-naming.ConstexprVariableCase,
value: CamelCase,
}
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalConstantPrefix, value: f }
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantPrefix, value: k }
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
- { key: readability-identifier-naming.StaticConstantPrefix, value: k }
- {
key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic,
value: 1,
}
- { key: readability-function-cognitive-complexity.Threshold, value: 21 }
WarningsAsErrors: "*"
HeaderFilterRegex: ""
FormatStyle: file
User: ""
......@@ -10,5 +10,20 @@
},
"editor.formatOnSave": true,
"isort.args": ["--profile", "black"],
"notebook.lineNumbers": "on"
"notebook.lineNumbers": "on",
"clangd.arguments": [
"--log=info",
"--pretty",
"--all-scopes-completion",
"--completion-style=bundled",
"--header-insertion=iwyu",
"--header-insertion-decorators",
"--background-index",
"--clang-tidy",
"-j=20",
"--pch-storage=disk",
"--function-arg-placeholders=false",
"--compile-commands-dir=build"
],
"clangd.path": "clangd-17"
}
......@@ -139,10 +139,74 @@ repos:
```
### c++ lint
- nox + vscode extensions
- setup nox
```python
@nox.session(venv_backend="none")
def dev(session: nox.Session) -> None:
"""
Prepare a .venv folder.
"""
session.run(sys.executable, "-m", "venv", ".venv")
session.run(
".venv/bin/pip",
"install",
"scikit-build-core[pyproject]",
"pybind11",
"pip>=23",
)
session.run(
".venv/bin/pip",
"install",
"--no-build-isolation",
"--check-build-dependencies",
"-ve.",
"-C",
"cmake.define.CMAKE_EXPORT_COMPILE_COMMANDS=1",
"-C",
"build-dir=build",
)
@nox.session(reuse_venv=True)
def cpp_lint(session: nox.Session) -> None:
cpp_files = glob.glob("**/*.cc", recursive=True)
session.install("clangd-tidy")
session.run("clangd-tidy", "-p", "build", *cpp_files)
```
- vscode extensions. use `clangd`
```
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 set
```json
"clangd.arguments": [
"--log=info",
"--pretty",
"--all-scopes-completion",
"--completion-style=bundled",
"--header-insertion=iwyu",
"--header-insertion-decorators",
"--background-index",
"--clang-tidy",
"-j=20",
"--pch-storage=disk",
"--function-arg-placeholders=false",
"--compile-commands-dir=build"
],
"clangd.path": "clangd-17"
```
### python lint
- ruff: pre-commit + vscode extensions
- pylint: nox + vscode extensions
#### ruff: pre-commit + vscode extensions
- install pre-commit
- install extensions
#### pylint: nox + vscode extensions
## vscode extensions to install
- "isort", which sort python import
......
......@@ -4,13 +4,13 @@ target_include_directories(hello PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(TARGETS hello LIBRARY DESTINATION .)
add_library(complex SHARED src/complex.cc)
target_include_directories(complex PUBLIC
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_link_libraries(complex PRIVATE hello)
install(TARGETS complex LIBRARY DESTINATION .)
set_target_properties(complex PROPERTIES
target_link_libraries(complexf PRIVATE hello)
install(TARGETS complexf LIBRARY DESTINATION .)
set_target_properties(complexf PROPERTIES
INSTALL_RPATH "$ORIGIN"
)
......
#pragma once
double complex(double a, double b);
#pragma once
double complexf(double a, double b);
#include "complex.h"
#include "hello.h"
double complex(double a, double b) { return add(a, b) + 2; }
#include "complexf.h"
#include "hello.h"
double complexf(double a, double b) { return add(a, b) + 2; }
......@@ -2,6 +2,7 @@
nox configuration file.
"""
import glob
import sys
from pathlib import Path
......@@ -46,6 +47,20 @@ def dev(session: nox.Session) -> None:
)
@nox.session(reuse_venv=True)
def cpp_lint_slow(session: nox.Session) -> None:
if "cpp_lint_slow" in sys.argv:
cpp_files = glob.glob("**/*.cc", recursive=True)
session.run("clang-tidy", "-p", "build", *cpp_files)
@nox.session(reuse_venv=True)
def cpp_lint(session: nox.Session) -> None:
cpp_files = glob.glob("**/*.cc", recursive=True)
session.install("clangd-tidy")
session.run("clangd-tidy", "-p", "build", *cpp_files)
@nox.session(reuse_venv=True)
def rr_run(session: nox.Session) -> None:
"""
......
......@@ -2,7 +2,7 @@ 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 hello complex)
target_link_libraries(_hello PRIVATE complexf)
install(TARGETS _hello DESTINATION _csrc)
set_target_properties(_hello PROPERTIES
INSTALL_RPATH "$ORIGIN/.."
......
#include "complex.h"
#include "hello.h"
#include <pybind11/pybind11.h>
namespace py = pybind11;
#include "complexf.h"
#include "hello.h"
PYBIND11_MODULE(_hello, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function which adds two numbers");
m.def("complex", &complex, "complex(a,b) = add(a,b) + 2");
m.def("complex", &complexf, "complex(a,b) = add(a,b) + 2");
}
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