You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/plugin/overview.md
+100-9Lines changed: 100 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,102 @@ sidebar_position: 1
4
4
5
5
# Introduction
6
6
7
-
KCL provides plugin support through a plugin agent and auxiliary command line tools, and the KCL plugin framework supports different general-purpose languages to develop plugins. Here we take Python as an example to briefly explain the use of plugins.
7
+
KCL provides plugin support through a plugin agent and auxiliary command line tools, and the KCL plugin framework supports different general-purpose languages to develop plugins. The KCL plugin framework currently supports the development of plugins in Python and Go languages.
three = hello.add(1,2) # hello.add is written by Go
43
+
`
44
+
```
45
+
46
+
In KCL code, the `hello` plugin can be imported via `import kcl_plugin.hello`. The output result is
47
+
48
+
```yaml
49
+
name: kcl
50
+
three: 3
51
+
```
52
+
53
+
### 2. Plugin Directory Structure
54
+
55
+
The KCL Go plugin is essentially a simple Go project, mainly containing the Go file `api.go` for the plugin code, which defines the registration and implementation functions of the plugin.
Using the KCL Python plugin requires the presence of `Python 3.7+` in your `PATH`, install the KCL python SDK and set the plugin path.
14
105
@@ -18,7 +109,7 @@ alias kcl-plugin="python3 -m kclvm.tools.plugin"
18
109
export KCL_PLUGINS_ROOT=~/.kcl/plugins
19
110
```
20
111
21
-
## 1. Hello Plugin
112
+
### 1. Hello Plugin
22
113
23
114
KCL plugins are installed in the `plugins` subdirectory of KCL (usually installed in the `$HOME/.kcl/plugins` directory), or set through the `$KCL_PLUGINS_ROOT` environment variable. Besides, the `plugins` directory could also be placed at the `pwd` path. KCL plugins are managed in the Git repository: [https://github.com/kcl-lang/kcl-plugin](https://github.com/kcl-lang/kcl-plugin), we can clone the repository for development.
24
115
@@ -55,7 +146,7 @@ name: kcl
55
146
three: 3
56
147
```
57
148
58
-
## 2. `kcl-plugin` Command
149
+
### 2. `kcl-plugin` Command
59
150
60
151
`kcl-plugin` is a plugin helper command line tool, the command line help is as follows:
61
152
@@ -80,7 +171,7 @@ optional arguments:
80
171
- The `gendoc` subcommand is used to update the API documentation of all plugins.
81
172
- The `test` subcommand is used to test specified plugins.
82
173
83
-
## 3. Plugin Information and Documentation
174
+
### 3. Plugin Information and Documentation
84
175
85
176
Enter `kcl-plugin info hello` to view the `hello` plugin information:
86
177
@@ -104,7 +195,7 @@ $ kcl-plugin info hello
104
195
105
196
The information of the plugin mainly includes the name and version information of the plugin, and the function information provided by the plugin. This information is consistent with the automatically generated `api.md` file in the plugin directory (regenerate the `api.md` file for all plugins via `kcl-plugin gendoc` when the plugin API document changes).
106
197
107
-
## 4. Plugin Directory Structure
198
+
### 4. Plugin Directory Structure
108
199
109
200
The directory structure of the plugin is as follows (replace `/Users/kcl_user` with the local `$HOME` path):
110
201
@@ -141,7 +232,7 @@ Where `INFO` specifies the name of the plugin, a brief description, a detailed d
141
232
142
233
> Note: KCL plugins are implemented in an independent pure Python code file, and plugins cannot directly call each other.
143
234
144
-
## 5. Create Plugin
235
+
### 5. Create Plugin
145
236
146
237
A plugin can be created with the `kcl-plugin init` command:
147
238
@@ -154,7 +245,7 @@ hi: hi doc - 0.0.1
154
245
155
246
The `kcl-plugin init` command will construct a new plugin from the built-in template, and then we can view the created plugin information with the `kcl-plugin list` command.
156
247
157
-
## 6. Remove Plugin
248
+
### 6. Remove Plugin
158
249
159
250
KCL plugins are located in the `plugins` subdirectory of KCL (usually installed in the `$HOME/.kcl/plugins` directory).
160
251
We can query the plugin installation directory with the command `kcl-plugin info`.
@@ -173,7 +264,7 @@ $ tree /Users/kcl_user/.kcl/plugins/
173
264
$
174
265
```
175
266
176
-
## 7. Test Plugin
267
+
### 7. Test Plugin
177
268
178
269
There is a `plugin_test.py` file in the plugin directory, which is the unit test file of the plugin (based on the `pytest` testing framework). Also placed in the `_test` directory are plugin integration tests for KCL files. The `plugin_test.py` unit test is required, and the KCL integration tests in the `_test` directory can be added as needed.
0 commit comments