D29: объект путей AppPaths с базой данных из CF_DATA_DIR

infrastructure/cli/paths.py: AppPaths(data_dir, exports_dir) с model_path;
from_env() читает CF_DATA_DIR (дефолт ./data — поведение не меняется) на
каждую команду. CF_DATA_DIR переопределяет только данные модели: экспорты
остаются в ./exports относительно CWD. load_model/save_model, cf init и
cf import-xlsx идут через объект; дефолт cf export-xlsx прежний.
Тесты: дефолтные пути, переопределение, init/config/info/import/export.
This commit is contained in:
oqyude committed 2026-10-25 16:49:33 +03:00
1 parent f41fc19cc9
commit 6470978693
6 files changed
+153 -17

No files matched your search

+4 -4
View File
@@ -3,16 +3,16 @@
import typer
from infrastructure.cli.i18n import t
from infrastructure.cli.paths import EXPORTS_DIR
from infrastructure.cli.paths import AppPaths
from infrastructure.cli.services import console, load_model
from infrastructure.repositories import ExcelRepository, ExcelRepositoryError
_repo = ExcelRepository()
# Значение по умолчанию остаётся ровно "exports/forecast.xlsx" (строка в help
# и в аргументе CLI не меняется) — собирается из EXPORTS_DIR во избежание
# дублирования литерала пути.
DEFAULT_EXPORT_PATH: str = str(EXPORTS_DIR / "forecast.xlsx")
# и в аргументе CLI не меняется) — собирается из `AppPaths.exports_dir` во
# избежание дублирования литерала пути. `CF_DATA_DIR` на экспорты не влияет.
DEFAULT_EXPORT_PATH: str = str(AppPaths.from_env().exports_dir / "forecast.xlsx")
def export_xlsx(
+3 -2
View File
@@ -2,12 +2,13 @@
from domain import FinancialModel
from infrastructure.cli.i18n import t
from infrastructure.cli.paths import MODEL_PATH
from infrastructure.cli.paths import AppPaths
from infrastructure.cli.services import console, save_model
def init() -> None:
"""Создать пустую финансовую модель"""
model = FinancialModel()
model_path = AppPaths.from_env().model_path
save_model(model)
console.print(t("cmd.init.ok", path=str(MODEL_PATH)))
console.print(t("cmd.init.ok", path=str(model_path)))