Skip to content

Commit

Permalink
fix: use short paths when formatting Python code if available
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Feb 18, 2022
1 parent 369ded8 commit e358fcd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion calcipy/doit_tasks/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))


Expand Down

0 comments on commit e358fcd

Please sign in to comment.