f
This commit is contained in:
10
SYS/utils.py
10
SYS/utils.py
@@ -37,7 +37,15 @@ def expand_path(p: str | Path | None) -> Path:
|
||||
"""Expand ~ and environment variables in path."""
|
||||
if p is None:
|
||||
return None # type: ignore
|
||||
expanded = os.path.expandvars(str(p))
|
||||
s = str(p)
|
||||
# Courtesy check for $home -> $HOME if we're on a POSIX-like system
|
||||
# (where env vars are case-sensitive)
|
||||
if os.name != 'nt' and '$home' in s and '$HOME' not in os.environ:
|
||||
# If $home is literally used in config but only HOME is defined
|
||||
if 'HOME' in os.environ:
|
||||
s = s.replace('$home', '$HOME')
|
||||
|
||||
expanded = os.path.expandvars(s)
|
||||
return Path(expanded).expanduser()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user