Download app/paths.py from dellweb3/build3d: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/spaces/dellweb3/build3d/resolve/main/app/paths.py
- Command line
-
hf download hf://spaces/dellweb3/build3d/app/paths.py
-
curl -L -o paths.py https://huggingface.co/spaces/dellweb3/build3d/resolve/main/app/paths.py
1.92 kB
| # -*- coding: utf-8 -*- | |
| """ | |
| 统一路径与可执行文件定位。 | |
| 原则:仓库内的一切路径都相对本文件推导,不写死盘符。 | |
| 克隆到 D:\\work\\build3d 或 /home/u/build3d 都能跑,只要遵守两点: | |
| 1. Blender 便携版解压在仓库根目录下(目录名以 blender 开头),或设置环境变量 BLENDER_EXE | |
| 2. Python 依赖按 requirements.txt 装好 | |
| """ | |
| import glob | |
| import os | |
| import shutil | |
| APP = os.path.dirname(os.path.abspath(__file__)) | |
| PROJECT = os.path.dirname(APP) | |
| DEMO = os.path.join(PROJECT, "demo") | |
| STATIC = os.path.join(APP, "static") | |
| PLANS = os.path.join(STATIC, "plans") | |
| THUMBS = os.path.join(STATIC, "thumbs") | |
| OUTPUT = os.path.join(APP, "output") | |
| MEDIA = DEMO # 页面里的 /media/* 映射到 demo/ | |
| BUILD_SCRIPT = os.path.join(DEMO, "build_model.py") | |
| BLENDER_VERSION = "4.5.15" | |
| BLENDER_DIR_NAME = "blender-%s-windows-x64" % BLENDER_VERSION | |
| def find_blender(): | |
| """按 环境变量 → 仓库根目录 blender*/blender.exe → PATH 的顺序查找""" | |
| env = os.environ.get("BLENDER_EXE", "").strip().strip('"') | |
| if env and os.path.isfile(env): | |
| return env | |
| for pattern in (os.path.join(PROJECT, "blender*", "blender.exe"), | |
| os.path.join(PROJECT, "*", "blender.exe")): | |
| for c in sorted(glob.glob(pattern)): | |
| if os.path.isfile(c): | |
| return c | |
| found = shutil.which("blender") or shutil.which("blender.exe") | |
| if found: | |
| return found | |
| # 都没找到时返回期望位置,便于上层给出"请先解压 Blender"的提示 | |
| return os.path.join(PROJECT, BLENDER_DIR_NAME, "blender.exe") | |
| BLENDER = find_blender() | |
| BLENDER_OK = os.path.isfile(BLENDER) | |
| if __name__ == "__main__": | |
| for k in ("PROJECT", "APP", "STATIC", "OUTPUT", "MEDIA", "BLENDER"): | |
| print("%-10s %s" % (k, globals()[k])) | |
| print("%-10s %s" % ("BLENDER_OK", BLENDER_OK)) | |