Forráskód Böngészése

doc: python virtual environment support

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
Jiyong Huang 2 éve
szülő
commit
b1d4fa7a33

+ 24 - 9
docs/en_US/extension/portable/overview.md

@@ -63,22 +63,37 @@ In the json file, we need to depict the metadata of this plugin. The information
   "sources": [
   "sources": [
     "random"
     "random"
   ],
   ],
-  "sinks": [
-    "file"
-  ],
-  "functions": [
-    "echo"
-  ]
+   "sinks": [
+      "file"
+   ],
+   "functions": [
+      "echo"
+   ]
 }
 }
 ```
 ```
 
 
-A plugin can contain multiple sources, sinks and functions, define them in the corresponding arrays in the json file. A plugin must be implemented in a single language, and specify that in the *language* field. Additionally, the *executable* field is required to specify the plugin main program executable. Please refer to [mirror.zip](https://github.com/lf-edge/ekuiper/blob/master/internal/plugin/testzips/portables/mirror.zip) as an example.
+A plugin can contain multiple sources, sinks and functions, define them in the corresponding arrays in the json file. A
+plugin must be implemented in a single language, and specify that in the *language* field. Additionally, the
+*executable* field is required to specify the plugin main program executable. Please refer
+to [mirror.zip](https://github.com/lf-edge/ekuiper/blob/master/internal/plugin/testzips/portables/mirror.zip) as an
+example.
+
+If using Python plugin, users can specify a virtual environment for the python script by specifying the below
+properties:
+
+- virtualEnvType: the virtual environment type, currently only `conda` is supported.
+- env: the virtual environment name to be run.
+
+For detail, please check [run in virtual environment](./python_sdk.md#virtual-environment).
 
 
 ## Management
 ## Management
 
 
-The portable plugins can be automatically loaded in start up by putting the content(the json, the executable and all supportive files) inside `plugins/portables/${pluginName}` and the configurations to the corresponding directories under `etc`.
+The portable plugins can be automatically loaded in start up by putting the content(the json, the executable and all
+supportive files) inside `plugins/portables/${pluginName}` and the configurations to the corresponding directories
+under `etc`.
 
 
-To manage the portable plugins in runtime, we can use the [REST](../../api/restapi/plugins.md) or [CLI](../../api/cli/plugins.md) commands.
+To manage the portable plugins in runtime, we can use the [REST](../../api/restapi/plugins.md)
+or [CLI](../../api/cli/plugins.md) commands.
 
 
 ## Restrictions
 ## Restrictions
 
 

+ 40 - 3
docs/en_US/extension/portable/python_sdk.md

@@ -89,12 +89,49 @@ if __name__ == '__main__':
     plugin.start(c)
     plugin.start(c)
 ```
 ```
 
 
-For the full example, please check the [python sdk example](https://github.com/lf-edge/ekuiper/tree/master/sdk/python/example/pysam).
+For the full example, please check
+the [python sdk example](https://github.com/lf-edge/ekuiper/tree/master/sdk/python/example/pysam).
 
 
 ## Package
 ## Package
 
 
-As python is an interpretive language, we don't need to build an executable for it. Just specify the main program python file in the plugin json file is ok. For detail, please check [packaing](./overview.md#package).
+As python is an interpretive language, we don't need to build an executable for it. Just specify the main program python
+file in the plugin json file is ok. For detail, please check [packaging](./overview.md#package).
 
 
 ## Deployment requirements
 ## Deployment requirements
 
 
-Running python script requires the python environment. Make sure python 3.x are installed in the target environment. If using docker image, we recommend to use tags like `lfedge/ekuiper:<tag>-slim-python` which have both eKuiper and python environment.
+Running python script requires the python environment. Make sure python 3.x are installed in the target environment. If
+using docker image, we recommend to use tags like `lfedge/ekuiper:<tag>-slim-python` which have both eKuiper and python
+environment.
+
+### Virtual Environment
+
+Virtual environments are a common and effective technique used in Python development which is useful for python
+dependency management. Anaconda or Miniconda are one of the most popular environment manager for Python.
+The [conda](https://conda.io/projects/conda/en/latest/index.html) package and environment manager is included in all
+versions of Anaconda®, Miniconda, and Anaconda Repository. eKuiper supports to run the Python plugin with conda
+environment.
+
+To use conda environment, the common steps are:
+
+1. Create and set up the conda environment.
+2. When packaging the plugin, make sure `virtualEnvType` is set to `conda` and `env` is set to the created virtual
+   environment. Below is an example.
+    ```json
+    {
+      "version": "v1.0.0",
+      "language": "python",
+      "executable": "pysam.py",
+      "virtualEnvType": "conda",
+      "env": "myenv",
+      "sources": [
+        "pyjson"
+      ],
+      "sinks": [
+        "print"
+      ],
+      "functions": [
+        "revert"
+      ]
+    }
+    ```
+3. If the plugin has installation script, make sure the script install the dependencies to the correct environment.

+ 20 - 8
docs/zh_CN/extension/portable/overview.md

@@ -58,21 +58,33 @@
   "sources": [
   "sources": [
     "random"
     "random"
   ],
   ],
-  "sinks": [
-    "file"
-  ],
-  "functions": [
-    "echo"
-  ]
+   "sinks": [
+      "file"
+   ],
+   "functions": [
+      "echo"
+   ]
 }
 }
 ```
 ```
-一个插件可以包含多个源、目标和函数,在 json 文件中的相应数组中定义它们。插件必须以单一语言实现,并在 *language* 字段中指定。此外,*executable* 字段需要指定插件主程序可执行文件。请参考[mirror.zip](https://github.com/lf-edge/ekuiper/blob/master/internal/plugin/testzips/portables/mirror.zip) 。
+
+一个插件可以包含多个源、目标和函数,在 json 文件中的相应数组中定义它们。插件必须以单一语言实现,并在 *language* 字段中指定。此外,
+*executable*
+字段需要指定插件主程序可执行文件。请参考[mirror.zip](https://github.com/lf-edge/ekuiper/blob/master/internal/plugin/testzips/portables/mirror.zip) 。
+
+使用Python插件时,用户可以通过指定以下属性为 Python 脚本指定一个虚拟环境。
+
+- virtualEnvType:虚拟环境类型,目前只支持`conda`。
+- env:要运行的虚拟环境名称。
+
+详情请查看[在虚拟环境运行](./python_sdk.md#虚拟环境)。
 
 
 ## 管理
 ## 管理
 
 
-通过将内容(json、可执行文件和所有支持文件)放在`plugins/portables/${pluginName}`中,并将配置放在`etc`下的相应目录中,可以在启动时自动加载可移植插件。
+通过将内容(json、可执行文件和所有支持文件)放在`plugins/portables/${pluginName}`中,并将配置放在`etc`
+下的相应目录中,可以在启动时自动加载可移植插件。
 
 
 要在运行时管理可移植插件,我们可以使用 [REST](../../api/restapi/plugins.md) 或 [CLI](../../api/cli/plugins.md) 命令。
 要在运行时管理可移植插件,我们可以使用 [REST](../../api/restapi/plugins.md) 或 [CLI](../../api/cli/plugins.md) 命令。
+
 ## 限制
 ## 限制
 
 
 目前,与原生插件相比,有两个方面的区别:
 目前,与原生插件相比,有两个方面的区别:

+ 34 - 2
docs/zh_CN/extension/portable/python_sdk.md

@@ -91,8 +91,40 @@ if __name__ == '__main__':
 
 
 ## 打包发布
 ## 打包发布
 
 
-由于 python 是解释性语言,不需要编译出可执行文件,需要确保 json 描述文件中可执行文件名字的准确性即可。详细信息,请[参考](./overview.md#打包发布)
+由于 python 是解释性语言,不需要编译出可执行文件,需要确保 json
+描述文件中可执行文件名字的准确性即可。详细信息,请[参考](./overview.md#打包发布)
 
 
 ## 部署要求
 ## 部署要求
 
 
-运行 python 脚本需要有 python 环境。所以,目标系统必须安装 python 3.x 环境。如果使用 docker ,建议使用 `lfedge/ekuiper:<tag>-slim-python` 版本。该版本包含 eKuiper 和 python 环境,无需再手动安装。
+运行 python 脚本需要有 python 环境。所以,目标系统必须安装 python 3.x 环境。如果使用 docker
+,建议使用 `lfedge/ekuiper:<tag>-slim-python` 版本。该版本包含 eKuiper 和 python 环境,无需再手动安装。
+
+### 虚拟环境
+
+虚拟环境是Python开发中常用的技术,对 Python 的依赖性管理很有用。Anaconda 或 Miniconda 是最流行的 Python
+环境管理器之一。[conda](https://conda.io/projects/conda/en/latest/index.html) 软件包和环境管理器包含在所有版本的
+Anaconda®、Miniconda 和 Anaconda Repository 中。eKuiper 支持使用 conda 环境运行 Python 插件。
+
+使用 conda 虚拟环境通常包括如下步骤:
+
+1. 创建并配置虚拟环境。
+2. 在打包插件时,确保 `virtualEnvType` 设置为 `conda`,`env` 设置为创建的虚拟环境名,如下所示。
+    ```json
+    {
+      "version": "v1.0.0",
+      "language": "python",
+      "executable": "pysam.py",
+      "virtualEnvType": "conda",
+      "env": "myenv",
+      "sources": [
+        "pyjson"
+      ],
+      "sinks": [
+        "print"
+      ],
+      "functions": [
+        "revert"
+      ]
+    }
+    ```
+3. 如果该插件有安装脚本,确保该脚本将依赖安装到正确的虚拟环境中。