From c889b15098bb99eeba557ced79cc2555ac054868 Mon Sep 17 00:00:00 2001 From: Akeyiii Date: Tue, 2 Sep 2025 21:31:39 +0800 Subject: [PATCH 1/5] cli init --- framework/fit/python/fit_cli/__init__.py | 0 framework/fit/python/fit_cli/__main__.py | 4 +++ .../fit/python/fit_cli/commands/__init__.py | 0 .../fit/python/fit_cli/commands/init_cmd.py | 35 +++++++++++++++++++ framework/fit/python/fit_cli/main.py | 25 +++++++++++++ framework/fit/python/fit_cli/readme.md | 14 ++++++++ 6 files changed, 78 insertions(+) create mode 100644 framework/fit/python/fit_cli/__init__.py create mode 100644 framework/fit/python/fit_cli/__main__.py create mode 100644 framework/fit/python/fit_cli/commands/__init__.py create mode 100644 framework/fit/python/fit_cli/commands/init_cmd.py create mode 100644 framework/fit/python/fit_cli/main.py create mode 100644 framework/fit/python/fit_cli/readme.md diff --git a/framework/fit/python/fit_cli/__init__.py b/framework/fit/python/fit_cli/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/framework/fit/python/fit_cli/__main__.py b/framework/fit/python/fit_cli/__main__.py new file mode 100644 index 00000000..40e2b013 --- /dev/null +++ b/framework/fit/python/fit_cli/__main__.py @@ -0,0 +1,4 @@ +from .main import main + +if __name__ == "__main__": + main() diff --git a/framework/fit/python/fit_cli/commands/__init__.py b/framework/fit/python/fit_cli/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/framework/fit/python/fit_cli/commands/init_cmd.py b/framework/fit/python/fit_cli/commands/init_cmd.py new file mode 100644 index 00000000..7e384cdf --- /dev/null +++ b/framework/fit/python/fit_cli/commands/init_cmd.py @@ -0,0 +1,35 @@ +from pathlib import Path + +TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable + +@fitable("genericable_id_demo", "fitable_id_demo") +def hello(name: str) -> str: + """一个简单的 FIT 插件示例函数""" + return f"Hello, {name}!" +''' + +def run(args): + """生成插件模板""" + base_dir = "plugin" / Path(args.name) + src_dir = base_dir / "src" + + # 创建目录 + if not base_dir.exists(): + base_dir.mkdir(parents=True) + print(f"✅ 已创建目录 {base_dir}") + if not src_dir.exists(): + src_dir.mkdir(parents=True) + + # __init__.py + init_file = src_dir / "__init__.py" + if not init_file.exists(): + init_file.touch() + else: + print(f"⚠️ 文件 {init_file} 已存在,未覆盖。") + + # plugin.py + plugin_file = src_dir / "plugin.py" + if not plugin_file.exists(): + plugin_file.write_text(TEMPLATE_PLUGIN, encoding="utf-8") + else: + print(f"⚠️ 文件 {plugin_file} 已存在,未覆盖。") diff --git a/framework/fit/python/fit_cli/main.py b/framework/fit/python/fit_cli/main.py new file mode 100644 index 00000000..558af8ba --- /dev/null +++ b/framework/fit/python/fit_cli/main.py @@ -0,0 +1,25 @@ +import argparse +from fit_cli.commands import init_cmd + +# , build_cmd, package_cmd) + + +def main(): + parser = argparse.ArgumentParser(description="FIT Framework CLI 插件开发工具") + subparsers = parser.add_subparsers(dest="command") + + # init + parser_init = subparsers.add_parser("init", help="生成插件模板") + parser_init.add_argument("name", help="插件目录名称") + parser_init.set_defaults(func=init_cmd.run) + + args = parser.parse_args() + + if hasattr(args, "func"): + args.func(args) + else: + parser.print_help() + + +if __name__ == "__main__": + main() diff --git a/framework/fit/python/fit_cli/readme.md b/framework/fit/python/fit_cli/readme.md new file mode 100644 index 00000000..71f9c650 --- /dev/null +++ b/framework/fit/python/fit_cli/readme.md @@ -0,0 +1,14 @@ +# FIT CLI 工具 + +FIT CLI 工具是基于 **FIT Framework** 的命令行开发工具,提供插件初始化、打包等功能,帮助用户快速开发和管理 FIT 插件。 + +--- + +## 使用方式 + +以framework/fit/python为项目根目录,运行: + +```bash +python -m fit_cli init your_plugin_name +``` +将会在plugin目录中创建your_plugin_name目录,并生成插件模板。 From 37e7faf88b8411084aec8a2643e960cd7a81947b Mon Sep 17 00:00:00 2001 From: Akeyiii Date: Thu, 4 Sep 2025 19:38:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9init=5Fcmd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fit/python/fit_cli/commands/init_cmd.py | 74 +++++++++++++------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/framework/fit/python/fit_cli/commands/init_cmd.py b/framework/fit/python/fit_cli/commands/init_cmd.py index 7e384cdf..11174bf7 100644 --- a/framework/fit/python/fit_cli/commands/init_cmd.py +++ b/framework/fit/python/fit_cli/commands/init_cmd.py @@ -1,35 +1,63 @@ from pathlib import Path -TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable +TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable # 引入 Fit for Python 框架核心接口 -@fitable("genericable_id_demo", "fitable_id_demo") -def hello(name: str) -> str: - """一个简单的 FIT 插件示例函数""" - return f"Hello, {name}!" +# 修改 genericable_id_hello / fitable_id_hello 为唯一的 ID +# - 建议和插件功能相关,例如: +# - @fitable("genericable_id_concat", "fitable_id_concat") +@fitable("genericable_id_hello", "fitable_id_hello") # 指定可供调用函数的 genericable id 和 fitable id +def hello(name: str) -> str: # 定义可供调用的函数,特别注意需要提供函数类型签名, + # 可参照文档https://www.modelengine-ai.com/#/docs/zh_CN/ai-framework/fit/python/function-signature + """ + 一个简单的 FIT 插件示例函数 + + 修改函数名和参数 + - 函数名(hello)应根据功能调整,例如 concat, multiply + - 参数(name: str)可以增加多个,类型也可以是 int, float 等 + """ + + return f"Hello, {name}!" # 提供函数实现逻辑 + +# 关于插件开发其他内容可参考官方文档:https://github.com/ModelEngine-Group/fit-framework/tree/main/docs/framework/fit/python ''' -def run(args): - """生成插件模板""" - base_dir = "plugin" / Path(args.name) +def create_directory(path: Path): + """创建目录(如果不存在)""" + if not path.exists(): + path.mkdir(parents=True) + + return path + + +def create_file(path: Path, content: str = "", overwrite: bool = False): + """创建文件,支持写入内容""" + if path.exists() and not overwrite: + print(f"⚠️ 文件 {path} 已存在,未覆盖。") + return + path.write_text(content, encoding="utf-8") if content else path.touch() + + + +def generate_plugin_structure(plugin_name: str): + """生成插件目录和文件结构""" + base_dir = Path("plugin") / plugin_name src_dir = base_dir / "src" # 创建目录 - if not base_dir.exists(): - base_dir.mkdir(parents=True) - print(f"✅ 已创建目录 {base_dir}") - if not src_dir.exists(): - src_dir.mkdir(parents=True) + create_directory(base_dir) + create_directory(src_dir) - # __init__.py + # 创建 __init__.py init_file = src_dir / "__init__.py" - if not init_file.exists(): - init_file.touch() - else: - print(f"⚠️ 文件 {init_file} 已存在,未覆盖。") + create_file(init_file) - # plugin.py + # 创建 plugin.py plugin_file = src_dir / "plugin.py" - if not plugin_file.exists(): - plugin_file.write_text(TEMPLATE_PLUGIN, encoding="utf-8") - else: - print(f"⚠️ 文件 {plugin_file} 已存在,未覆盖。") + create_file(plugin_file, TEMPLATE_PLUGIN) + + print(f"✅ 已创建目录 {base_dir} ") + + +def run(args): + """命令入口""" + generate_plugin_structure(args.name) \ No newline at end of file From cb9824a26c150c3eff97d0efa9e2961ece833e86 Mon Sep 17 00:00:00 2001 From: Akeyiii Date: Fri, 5 Sep 2025 20:17:27 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E4=B8=BA${xxx}=E6=A0=BC=E5=BC=8F=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/fit/python/fit_cli/commands/init_cmd.py | 13 ++++++------- framework/fit/python/fit_cli/main.py | 1 - framework/fit/python/fit_cli/readme.md | 8 ++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/framework/fit/python/fit_cli/commands/init_cmd.py b/framework/fit/python/fit_cli/commands/init_cmd.py index 11174bf7..cb6402d2 100644 --- a/framework/fit/python/fit_cli/commands/init_cmd.py +++ b/framework/fit/python/fit_cli/commands/init_cmd.py @@ -2,12 +2,12 @@ TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable # 引入 Fit for Python 框架核心接口 -# 修改 genericable_id_hello / fitable_id_hello 为唯一的 ID -# - 建议和插件功能相关,例如: -# - @fitable("genericable_id_concat", "fitable_id_concat") -@fitable("genericable_id_hello", "fitable_id_hello") # 指定可供调用函数的 genericable id 和 fitable id -def hello(name: str) -> str: # 定义可供调用的函数,特别注意需要提供函数类型签名, - # 可参照文档https://www.modelengine-ai.com/#/docs/zh_CN/ai-framework/fit/python/function-signature +# - 修改 ${genericable_id} / ${fitable_id} 为唯一的 ID +# - 建议和插件功能相关,并且 GenericableId 必须全局唯一,通用的全局唯一方式可以采用域名的方式,例如:com.A.B +@fitable("${genericable_id}", "${fitable_id}") # 指定可供调用函数的 genericable id 和 fitable id +def hello(name: str) -> str: # 定义可供调用的函数,特别注意需要提供函数类型签名,可参照文档 + # - https://github.com/ModelEngine-Group/fit-framework/blob/main/docs/framework/fit/overview/00.%20%E6%A6%82%E8%BF%B0.md + # - 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 """ 一个简单的 FIT 插件示例函数 @@ -37,7 +37,6 @@ def create_file(path: Path, content: str = "", overwrite: bool = False): path.write_text(content, encoding="utf-8") if content else path.touch() - def generate_plugin_structure(plugin_name: str): """生成插件目录和文件结构""" base_dir = Path("plugin") / plugin_name diff --git a/framework/fit/python/fit_cli/main.py b/framework/fit/python/fit_cli/main.py index 558af8ba..c7eb168b 100644 --- a/framework/fit/python/fit_cli/main.py +++ b/framework/fit/python/fit_cli/main.py @@ -1,7 +1,6 @@ import argparse from fit_cli.commands import init_cmd -# , build_cmd, package_cmd) def main(): diff --git a/framework/fit/python/fit_cli/readme.md b/framework/fit/python/fit_cli/readme.md index 71f9c650..7ae782cf 100644 --- a/framework/fit/python/fit_cli/readme.md +++ b/framework/fit/python/fit_cli/readme.md @@ -1,14 +1,14 @@ # FIT CLI 工具 -FIT CLI 工具是基于 **FIT Framework** 的命令行开发工具,提供插件初始化、打包等功能,帮助用户快速开发和管理 FIT 插件。 +FIT CLI 工具是基于 **FIT Framework** 的命令行开发工具,提供插件初始化、打包、发布等功能,帮助用户快速开发和管理 FIT 插件。 --- ## 使用方式 -以framework/fit/python为项目根目录,运行: +以 framework/fit/python 为项目根目录,运行: ```bash -python -m fit_cli init your_plugin_name +python -m fit_cli init %{your_plugin_name} ``` -将会在plugin目录中创建your_plugin_name目录,并生成插件模板。 +将会在 plugin 目录中创建 %{your_plugin_name} 目录,并生成插件模板。 From 9c369ae9a8e2adf3202dfb2b577edd7cd07e8942 Mon Sep 17 00:00:00 2001 From: Akeyiii Date: Sun, 7 Sep 2025 18:57:10 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/fit/python/fit_cli/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/framework/fit/python/fit_cli/main.py b/framework/fit/python/fit_cli/main.py index c7eb168b..120207f2 100644 --- a/framework/fit/python/fit_cli/main.py +++ b/framework/fit/python/fit_cli/main.py @@ -1,8 +1,6 @@ import argparse from fit_cli.commands import init_cmd - - def main(): parser = argparse.ArgumentParser(description="FIT Framework CLI 插件开发工具") subparsers = parser.add_subparsers(dest="command") From 427b0c435156259448044d67d5774e3cc3d2507f Mon Sep 17 00:00:00 2001 From: Akeyiii Date: Sun, 7 Sep 2025 19:00:10 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/fit/python/fit_cli/commands/init_cmd.py | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/fit/python/fit_cli/commands/init_cmd.py b/framework/fit/python/fit_cli/commands/init_cmd.py index cb6402d2..e3552b34 100644 --- a/framework/fit/python/fit_cli/commands/init_cmd.py +++ b/framework/fit/python/fit_cli/commands/init_cmd.py @@ -25,7 +25,6 @@ def create_directory(path: Path): """创建目录(如果不存在)""" if not path.exists(): path.mkdir(parents=True) - return path