convert paths like .../ArchiveBox/archivebox/../output/abc into output/abc
(path: Union[Path, str], pwd: Union[Path, str]=OUTPUT_DIR)
| 544 | |
| 545 | @enforce_types |
| 546 | def pretty_path(path: Union[Path, str], pwd: Union[Path, str]=OUTPUT_DIR) -> str: |
| 547 | """convert paths like .../ArchiveBox/archivebox/../output/abc into output/abc""" |
| 548 | pwd = str(Path(pwd)) # .resolve() |
| 549 | path = str(path) |
| 550 | |
| 551 | if not path: |
| 552 | return path |
| 553 | |
| 554 | # replace long absolute paths with ./ relative ones to save on terminal output width |
| 555 | if path.startswith(pwd) and (pwd != '/'): |
| 556 | path = path.replace(pwd, '.', 1) |
| 557 | |
| 558 | # quote paths containing spaces |
| 559 | if ' ' in path: |
| 560 | path = f'"{path}"' |
| 561 | |
| 562 | # if path is just a plain dot, replace it back with the absolute path for clarity |
| 563 | if path == '.': |
| 564 | path = pwd |
| 565 | |
| 566 | return path |
| 567 | |
| 568 | |
| 569 | @enforce_types |
no outgoing calls
no test coverage detected