From af95ba062af8c8095c72b4f542ea756b2ee38792 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Wed, 24 Apr 2024 05:56:05 +0100 Subject: [PATCH] refactor(env): Shorten paths on Windows with env vars --- devine/commands/env.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/devine/commands/env.py b/devine/commands/env.py index 24ffbac..d098c5c 100644 --- a/devine/commands/env.py +++ b/devine/commands/env.py @@ -1,5 +1,8 @@ import logging +import os import shutil +import sys +from pathlib import Path from typing import Optional import click @@ -38,10 +41,20 @@ def info() -> None: table.add_column("Name", no_wrap=True) table.add_column("Path") + path_vars = { + x: Path(os.getenv(x)) + for x in ("TEMP", "APPDATA", "LOCALAPPDATA", "USERPROFILE") + if sys.platform == "win32" and os.getenv(x) + } + for name in sorted(dir(config.directories)): if name.startswith("__") or name == "app_dirs": continue path = getattr(config.directories, name).resolve() + for var, var_path in path_vars.items(): + if path.is_relative_to(var_path): + path = rf"%{var}%\{path.relative_to(var_path)}" + break table.add_row(name.title(), str(path)) console.print(Padding(