1+ from pathlib import Path
2+
3+ TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable # 引入 Fit for Python 框架核心接口
4+
5+ # - 修改 ${genericable_id} / ${fitable_id} 为唯一的 ID
6+ # - 建议和插件功能相关,并且 GenericableId 必须全局唯一,通用的全局唯一方式可以采用域名的方式,例如:com.A.B
7+ @fitable("${genericable_id}", "${fitable_id}") # 指定可供调用函数的 genericable id 和 fitable id
8+ def hello(name: str) -> str: # 定义可供调用的函数,特别注意需要提供函数类型签名,可参照文档
9+ # - https://github.com/ModelEngine-Group/fit-framework/blob/main/docs/framework/fit/overview/00.%20%E6%A6%82%E8%BF%B0.md
10+ # - https://github.com/ModelEngine-Group/fit-framework/blob/main/docs/framework/fit/python/%E8%A2%AB%E6%B3%A8%E8%A7%A3%E5%87%BD%E6%95%B0%E7%AD%BE%E5%90%8D%E8%A7%84%E8%8C%83.md
11+ """
12+ 一个简单的 FIT 插件示例函数
13+
14+ 修改函数名和参数
15+ - 函数名(hello)应根据功能调整,例如 concat, multiply
16+ - 参数(name: str)可以增加多个,类型也可以是 int, float 等
17+ """
18+
19+ return f"Hello, {name}!" # 提供函数实现逻辑
20+
21+ # 关于插件开发其他内容可参考官方文档:https://github.com/ModelEngine-Group/fit-framework/tree/main/docs/framework/fit/python
22+ '''
23+
24+ def create_directory (path : Path ):
25+ """创建目录(如果不存在)"""
26+ if not path .exists ():
27+ path .mkdir (parents = True )
28+ return path
29+
30+
31+ def create_file (path : Path , content : str = "" , overwrite : bool = False ):
32+ """创建文件,支持写入内容"""
33+ if path .exists () and not overwrite :
34+ print (f"⚠️ 文件 { path } 已存在,未覆盖。" )
35+ return
36+ path .write_text (content , encoding = "utf-8" ) if content else path .touch ()
37+
38+
39+ def generate_plugin_structure (plugin_name : str ):
40+ """生成插件目录和文件结构"""
41+ base_dir = Path ("plugin" ) / plugin_name
42+ src_dir = base_dir / "src"
43+
44+ # 创建目录
45+ create_directory (base_dir )
46+ create_directory (src_dir )
47+
48+ # 创建 __init__.py
49+ init_file = src_dir / "__init__.py"
50+ create_file (init_file )
51+
52+ # 创建 plugin.py
53+ plugin_file = src_dir / "plugin.py"
54+ create_file (plugin_file , TEMPLATE_PLUGIN )
55+
56+ print (f"✅ 已创建目录 { base_dir } " )
57+
58+
59+ def run (args ):
60+ """命令入口"""
61+ generate_plugin_structure (args .name )
0 commit comments