覆盖文生 3D、图生 3D、多视图、批量生成,以及重拓扑、绑定、动画、智能分割、 纹理、PBR、智能 UV、部件补全、格式导出与下载。 代码组织:一个功能一个模块(tripo/features/),入口薄壳 tripocli.py。
63 lines
2.7 KiB
Python
63 lines
2.7 KiB
Python
"""自我更新 — tripocli update.
|
||
|
||
tripocli update # 从记住的源码目录重装全局 CLI
|
||
tripocli update --from ~/Documents/AI/github/Tripo2Api
|
||
tripocli update --check # 只查看当前状态,不安装
|
||
tripocli update --dry-run # 只打印将要执行的命令
|
||
|
||
改完源码后跑一次,全局 `tripocli` 就更新到最新;用 pyenv 时自动 rehash。
|
||
"""
|
||
|
||
from .. import __version__, update as updater
|
||
|
||
NAME = "update"
|
||
HELP = "更新全局 CLI 到项目源码的最新版本"
|
||
|
||
|
||
def add_arguments(parser):
|
||
parser.add_argument("--from", dest="source", help="指定项目源码目录(会记住,之后无需再传)")
|
||
parser.add_argument("--check", action="store_true", help="只显示源码目录与已安装版本,不执行安装")
|
||
parser.add_argument("--dry-run", action="store_true", help="只打印将要执行的命令")
|
||
parser.add_argument("--no-rehash", action="store_true", help="跳过 pyenv rehash")
|
||
|
||
|
||
def run(ctx):
|
||
source = updater.detect_source(ctx.args.source, config=ctx.config)
|
||
|
||
if ctx.args.check or not source:
|
||
installed = updater.installed_version()
|
||
info = {
|
||
"source": str(source) if source else None,
|
||
"running_version": __version__,
|
||
"installed_version": installed,
|
||
"needs_install": bool(source) and installed != __version__,
|
||
"pyenv": updater._has_pyenv(),
|
||
}
|
||
if not source:
|
||
ctx.out.error(
|
||
"未找到项目源码目录。请指定一次:tripocli update --from <项目目录>"
|
||
)
|
||
return info
|
||
ctx.out.data(info, human=lambda: (
|
||
ctx.out.line(f"源码目录 : {info['source']}"),
|
||
ctx.out.line(f"当前运行版本: {info['running_version']}"),
|
||
ctx.out.line(f"已安装版本 : {info['installed_version'] or '未安装'}"),
|
||
ctx.out.line(f"需要更新 : {'是' if info['needs_install'] else '否(已一致)'}"),
|
||
ctx.out.line(f"pyenv : {'是(安装后会自动 rehash)' if info['pyenv'] else '否'}"),
|
||
))
|
||
return info
|
||
|
||
# Remember the source so later runs are just `tripocli update`.
|
||
ctx.config.set(**{updater.INSTALL_SOURCE_KEY: str(source)})
|
||
|
||
report = updater.update(source, rehash=not ctx.args.no_rehash, dry_run=ctx.args.dry_run)
|
||
ctx.out.data(
|
||
report,
|
||
human=lambda: (
|
||
ctx.out.line("✅ 已更新全局 tripocli" if not ctx.args.dry_run else "(dry-run)"),
|
||
*[ctx.out.line(" " + line) for line in updater.report_lines(report)],
|
||
ctx.out.line(" 提示: 在项目目录内执行时会用项目里的代码;其它目录才用刚装的这份"),
|
||
),
|
||
)
|
||
return report
|