From 8c839a20c2ae16c4f7c1bbf61dcece9fc9cbffa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 24 Jun 2016 18:41:45 +0200 Subject: [PATCH] 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 --- docs/configuration.rst | 2 +- yamllint/cli.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index ac26c47..cadd29a 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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. diff --git a/yamllint/cli.py b/yamllint/cli.py index 8e01701..525e162 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -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')