Files
mes-demo/core/path.py
T

22 lines
715 B
Python

# -*- coding: utf-8 -*-
"""统一路径入口:所有文件路径都基于项目根目录计算。
路径不在别处硬编码,跨平台可跑;运行期产物统一落 artifacts/。
"""
import os
# 项目根目录(core/ 的上一级)
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def get_path(*parts):
"""返回项目根目录下的拼接路径,如 get_path('fixtures', 'login.yml')。"""
return os.path.join(ROOT, *parts)
def artifact_path(*parts):
"""返回 artifacts/ 下的路径(运行时产物目录,已 gitignore),不存在则创建。"""
path = get_path('artifacts', *parts)
os.makedirs(os.path.dirname(path), exist_ok=True)
return path