Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] BREAKING CHANGE: Change get_config_dir to honor XDG spec #30668

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/azure-cli-core/azure/cli/core/_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@

def get_config_dir():
import os
return os.getenv('AZURE_CONFIG_DIR', None) or os.path.expanduser(os.path.join('~', '.azure'))
def sanitize(*d):
return os.path.expanduser(os.path.expandvars(os.path.join(*d)))

# Directory set in env has precedence
if env := os.getenv('AZURE_CONFIG_DIR'):
return sanitize(env)

# Honor XDG variables
if env := os.getenv('XDG_CONFIG_HOME'):
return sanitize(env, 'azure')

# Or the default fallover directory conform the XDG Base Directory Specification
if os.path.isdir(sanitize('~', '.config')):
return sanitize('~', '.config', 'azure')

# If all others fail, return a dot-dir in the user's home directory.
return sanitize('~', '.azure')
Loading