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
This commit is contained in:
@@ -16,7 +16,7 @@ following locations (by order of preference):
|
|||||||
|
|
||||||
- ``.yamllint`` in the current working directory
|
- ``.yamllint`` in the current working directory
|
||||||
- ``$XDG_CONFIG_HOME/yamllint/config``
|
- ``$XDG_CONFIG_HOME/yamllint/config``
|
||||||
- ``$HOME/.config/yamllint/config``
|
- ``~/.config/yamllint/config``
|
||||||
|
|
||||||
Finally if no config file is found, the default configuration is applied.
|
Finally if no config file is found, the default configuration is applied.
|
||||||
|
|
||||||
|
|||||||
@@ -87,13 +87,11 @@ def run(argv=None):
|
|||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# User-global config is supposed to be in ~/.config/yamllint/config
|
# User-global config is supposed to be in ~/.config/yamllint/config
|
||||||
user_global_config = None
|
|
||||||
if 'XDG_CONFIG_HOME' in os.environ:
|
if 'XDG_CONFIG_HOME' in os.environ:
|
||||||
user_global_config = os.path.join(
|
user_global_config = os.path.join(
|
||||||
os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config')
|
os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config')
|
||||||
elif 'HOME' in os.environ:
|
else:
|
||||||
user_global_config = os.path.join(
|
user_global_config = os.path.expanduser('~/.config/yamllint/config')
|
||||||
os.environ['HOME'], '.config', 'yamllint', 'config')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.config_data is not None:
|
if args.config_data is not None:
|
||||||
@@ -104,7 +102,7 @@ def run(argv=None):
|
|||||||
conf = YamlLintConfig(file=args.config_file)
|
conf = YamlLintConfig(file=args.config_file)
|
||||||
elif os.path.isfile('.yamllint'):
|
elif os.path.isfile('.yamllint'):
|
||||||
conf = YamlLintConfig(file='.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)
|
conf = YamlLintConfig(file=user_global_config)
|
||||||
else:
|
else:
|
||||||
conf = YamlLintConfig('extends: default')
|
conf = YamlLintConfig('extends: default')
|
||||||
|
|||||||
Reference in New Issue
Block a user