Skip to content

Commit eaf583e

Browse files
committed
[docs]: add contributing guide
1 parent 418f331 commit eaf583e

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

.github/CONTRIBUTING.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
## Before Commit!
2+
3+
Your commit message must follow Conventional Commits (https://www.conventionalcommits.org/) and your code should be formatted. The Git hooks will do most of the work automatically:
4+
5+
### Tool Requirements
6+
7+
You need a recent `clang-format` (>= 18). In a conda environment you can install:
8+
9+
```shell
10+
conda install -c conda-forge clang-format=18
11+
```
12+
13+
If you previously configured with an older version, remove the build directory and reconfigure:
14+
15+
```shell
16+
rm -rf kt-kernel/build
17+
```
18+
19+
Install `black` for Python formatting:
20+
21+
```shell
22+
conda install black
23+
```
24+
25+
### Install hook:
26+
```shell
27+
bash kt-kernel/scripts/install-git-hooks.sh
28+
#or just cmake the kt-kernel
29+
cmake -S kt-kernel -B kt-kernel/build
30+
```
31+
32+
There are manual commands if you need format.
33+
34+
```shell
35+
cmake -S kt-kernel -B kt-kernel/build
36+
cmake --build kt-kernel/build --target format
37+
```
38+
39+
## Developer Note
40+
41+
Formatting and commit message rules are enforced by Git hooks. After installing `clang-format` and `black`, just commit normally—the hooks will run formatting for you.
42+
43+
> [!NOTE]
44+
> If formatting modifies files, the commit is aborted after staging those changes. Review them and run `git commit` again. Repeat until no further formatting changes appear.
45+
46+
---
47+
48+
### Conventional Commit Regex (Reference)
49+
50+
The commit-msg hook enforces this pattern:
51+
52+
```text
53+
regex='^\[(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|wip)\](\([^\)]+\))?(!)?: .+'
54+
```
55+
56+
Meaning (English):
57+
* `[type]` required — one of feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|wip
58+
* Optional scope: `(scope)` — any chars except `)`
59+
* Optional breaking change marker: `!` right after type or scope
60+
* Separator: `: ` (colon + space)
61+
* Subject: free text (at least one character)
62+
63+
Examples:
64+
```text
65+
[feat]: add adaptive batching
66+
[fix(parser)]: handle empty token list
67+
[docs]!: update API section for breaking rename
68+
```
69+
70+
You can bypass locally (not recommended) with:
71+
```shell
72+
git commit --no-verify
73+
```
74+
## 提交前提醒
75+
76+
提交信息必须满足 Conventional Commits 规范 (https://www.conventionalcommits.org/),代码需要符合格式要求。Git 钩子已经集成了大部分工作:
77+
### 软件要求
78+
79+
需要较新的 `clang-format` (>= 18),在 conda 环境中安装:
80+
81+
```shell
82+
conda install -c conda-forge clang-format=18
83+
```
84+
85+
如果之前用老版本配置过,请删除构建目录重新配置:
86+
87+
```shell
88+
rm -rf kt-kernel/build
89+
```
90+
91+
安装 `black` 以进行 Python 文件格式化:
92+
93+
```shell
94+
conda install black
95+
```
96+
### 安装钩子
97+
```shell
98+
bash kt-kernel/scripts/install-git-hooks.sh
99+
#or just cmake the kt-kernel
100+
cmake -S kt-kernel -B kt-kernel/build
101+
```
102+
如果你需要手动格式化:
103+
```shell
104+
cmake -S kt-kernel -B kt-kernel/build
105+
cmake --build kt-kernel/build --target format
106+
```
107+
108+
## 开发者说明
109+
110+
本仓库通过 Git hooks 自动执行代码格式化与提交信息规范检查。只需安装好 `clang-format``black` 后正常执行提交即可,钩子会自动格式化。
111+
112+
> [!NOTE]
113+
> 如果格式化修改了文件,钩子会终止提交并已暂存这些改动。请查看修改后再次执行 `git commit`,重复直到没有新的格式化变更。
114+
115+
### 提交信息正则(参考)
116+
117+
钩子使用如下正则检查提交信息:
118+
```text
119+
regex='^\[(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|wip)\](\([^\)]+\))?(!)?: .+'
120+
```
121+
含义:
122+
* `[type]` 必填:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|wip
123+
* 作用域可选:`(scope)`,不能包含右括号
124+
* 可选的破坏性标记:`!`
125+
* 分隔符:冒号+空格 `: `
126+
* 描述:至少一个字符
127+
128+
示例:
129+
```text
130+
[feat]: 增加自适应 batch 功能
131+
[fix(tokenizer)]: 修复空 token 列表处理
132+
[docs]!: 更新接口文档(存在破坏性修改)
133+
```
134+
135+
跳过钩子(不推荐,仅紧急时):
136+
```shell
137+
git commit --no-verify
138+
```
139+

0 commit comments

Comments
 (0)