summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2020-01-21 02:31:37 +0000
committerAnthony Sottile <asottile@umich.edu>2020-01-21 02:31:37 +0000
commitebba642268de603655558494f3e3baa5afb5ec3e (patch)
treed0a101c3189c63fe61c4bcf3ca64fb62f030ec5f /src
parent990adcd56e4ed389c6dba1e43d1e5226b6445f7b (diff)
parentaab1f14375d7e0d4d059536e0f53b420d6cec470 (diff)
downloadflake8-ebba642268de603655558494f3e3baa5afb5ec3e.tar.gz
Merge branch 'config-appdirs' into 'master'
config: Determine path to user configuration immediately See merge request pycqa/flake8!409
Diffstat (limited to 'src')
-rw-r--r--src/flake8/options/config.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/flake8/options/config.py b/src/flake8/options/config.py
index 0adb957..5884873 100644
--- a/src/flake8/options/config.py
+++ b/src/flake8/options/config.py
@@ -3,7 +3,6 @@ import collections
import configparser
import logging
import os.path
-import sys
from typing import List, Optional, Tuple
from flake8 import utils
@@ -46,22 +45,30 @@ class ConfigFileFinder(object):
# The value of --isolated from the CLI.
self.ignore_config_files = ignore_config_files
- # Platform specific settings
- self.is_windows = sys.platform == "win32"
- self.xdg_home = os.environ.get(
- "XDG_CONFIG_HOME", os.path.expanduser("~/.config")
- )
-
- # Look for '.<program_name>' files
- self.program_config = "." + program_name
+ # User configuration file.
self.program_name = program_name
+ self.user_config_file = self._user_config_file(program_name)
# List of filenames to find in the local/project directory
- self.project_filenames = ("setup.cfg", "tox.ini", self.program_config)
+ self.project_filenames = ("setup.cfg", "tox.ini", "." + program_name)
self.local_directory = os.path.abspath(os.curdir)
@staticmethod
+ def _user_config_file(program_name):
+ # type: (str) -> str
+ if utils.is_windows():
+ home_dir = os.path.expanduser("~")
+ config_file_basename = "." + program_name
+ else:
+ home_dir = os.environ.get(
+ "XDG_CONFIG_HOME", os.path.expanduser("~/.config")
+ )
+ config_file_basename = program_name
+
+ return os.path.join(home_dir, config_file_basename)
+
+ @staticmethod
def _read_config(*files):
# type: (*str) -> Tuple[configparser.RawConfigParser, List[str]]
config = configparser.RawConfigParser()
@@ -139,15 +146,9 @@ class ConfigFileFinder(object):
"""Parse all local config files into one config object."""
return self.local_configs_with_files()[0]
- def user_config_file(self):
- """Find the user-level config file."""
- if self.is_windows:
- return os.path.expanduser("~\\" + self.program_config)
- return os.path.join(self.xdg_home, self.program_name)
-
def user_config(self):
"""Parse the user config file into a config object."""
- config, found_files = self._read_config(self.user_config_file())
+ config, found_files = self._read_config(self.user_config_file)
if found_files:
LOG.debug("Found user configuration files: %s", found_files)
return config