From e358fcd5cc9ad17706534d6e55f6a2eb8289d687 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Fri, 18 Feb 2022 16:22:10 -0500 Subject: [PATCH] fix: use short paths when formatting Python code if available --- calcipy/doit_tasks/lint.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/calcipy/doit_tasks/lint.py b/calcipy/doit_tasks/lint.py index a2c472a1..4eacadaa 100755 --- a/calcipy/doit_tasks/lint.py +++ b/calcipy/doit_tasks/lint.py @@ -5,6 +5,7 @@ from beartype import beartype from beartype.typing import Iterable, List from doit.tools import Interactive +from loguru import logger from ..file_helpers import if_found_unlink from .base import debug_task, echo @@ -304,7 +305,18 @@ def task_auto_format() -> DoitTask: DoitTask: doit task """ - paths = ' '.join(f'"{pth}"' for pth in DG.lint.paths_py) + @beartype + def get_short_path(_pth: Path) -> Path: + try: + return _pth.relative_to(DG.meta.path_project) + except Exception as exc: + logger.warning( + '{pth} is not relative to {rel_path}. Error: {exc}', + pth=_pth, rel_path=DG.meta.path_project, exc=exc, + ) + return _pth + + paths = ' '.join(f'"{get_short_path(pth)}"' for pth in DG.lint.paths_py) return debug_task(_gen_format_actions(paths))