-
Notifications
You must be signed in to change notification settings - Fork 328
新增python的FIT插件开发CLI工具 #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CodeCasterX
merged 5 commits into
ModelEngine-Group:main
from
Akeyiii:fit-feature-plugin-cli
Sep 7, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from .main import main | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from pathlib import Path | ||
|
|
||
| TEMPLATE_PLUGIN = '''from fitframework.api.decorators import fitable # 引入 Fit for Python 框架核心接口 | ||
|
|
||
| # - 修改 ${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 插件示例函数 | ||
|
|
||
| 修改函数名和参数 | ||
| - 函数名(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 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" | ||
|
|
||
| # 创建目录 | ||
| create_directory(base_dir) | ||
| create_directory(src_dir) | ||
|
|
||
| # 创建 __init__.py | ||
| init_file = src_dir / "__init__.py" | ||
| create_file(init_file) | ||
|
|
||
| # 创建 plugin.py | ||
| plugin_file = src_dir / "plugin.py" | ||
| create_file(plugin_file, TEMPLATE_PLUGIN) | ||
|
|
||
| print(f"✅ 已创建目录 {base_dir} ") | ||
|
|
||
|
|
||
| def run(args): | ||
| """命令入口""" | ||
| generate_plugin_structure(args.name) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import argparse | ||
| from fit_cli.commands import init_cmd | ||
CodeCasterX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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} 目录,并生成插件模板。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.