Config: Detect user config using `os.path.expanduser()`

Instead of `$HOME`, since the former works when `$HOME` is not set.

[1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828033#10
pull/12/head
Adrien Vergé 9 years ago
parent 8e6e851c5b
commit 8c839a20c2

@ -16,7 +16,7 @@ following locations (by order of preference):
- ``.yamllint`` in the current working directory
- ``$XDG_CONFIG_HOME/yamllint/config``
- ``$HOME/.config/yamllint/config``
- ``~/.config/yamllint/config``
Finally if no config file is found, the default configuration is applied.

@ -87,13 +87,11 @@ def run(argv=None):
sys.exit(-1)
# User-global config is supposed to be in ~/.config/yamllint/config
user_global_config = None
if 'XDG_CONFIG_HOME' in os.environ:
user_global_config = os.path.join(
os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config')
elif 'HOME' in os.environ:
user_global_config = os.path.join(
os.environ['HOME'], '.config', 'yamllint', 'config')
else:
user_global_config = os.path.expanduser('~/.config/yamllint/config')
try:
if args.config_data is not None:
@ -104,7 +102,7 @@ def run(argv=None):
conf = YamlLintConfig(file=args.config_file)
elif os.path.isfile('.yamllint'):
conf = YamlLintConfig(file='.yamllint')
elif user_global_config and os.path.isfile(user_global_config):
elif os.path.isfile(user_global_config):
conf = YamlLintConfig(file=user_global_config)
else:
conf = YamlLintConfig('extends: default')

Loading…
Cancel
Save