diff options
author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2019-02-23 12:10:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-23 12:10:57 -0800 |
commit | 61f3cde3f92cc0162263ac472cbd6a6d1ac5594d (patch) | |
tree | 8b05ce9bc376d7f3b8ba4d01376981b501fa8a22 | |
parent | 94ed1dd36f0bc00a2caec2947496417842cf1037 (diff) | |
parent | 9e07c6d66d006a2d3607fa8630df6563a8d1357d (diff) | |
download | isort-61f3cde3f92cc0162263ac472cbd6a6d1ac5594d.tar.gz |
Merge pull request #806 from r-darwish/xdg
Read configuration from XDG_CONFIG_HOME
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | isort/settings.py | 25 | ||||
-rwxr-xr-x | setup.py | 2 |
3 files changed, 20 insertions, 9 deletions
@@ -228,7 +228,7 @@ Configuring isort If you find the default isort settings do not work well for your project, isort provides several ways to adjust the behavior. -To configure isort for a single user create a ``~/.isort.cfg`` file: +To configure isort for a single user create a ``~/.isort.cfg`` or ``$XDG_CONFIG_HOME/isort.cfg`` file: .. code-block:: ini diff --git a/isort/settings.py b/isort/settings.py index f6ef1c25..7b3153c6 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -3,7 +3,7 @@ Defines how the default settings for isort should be loaded (First from the default setting dictionary at the top of the file, then overridden by any settings - in ~/.isort.cfg if there are any) + in ~/.isort.cfg or $XDG_CONFIG_HOME/isort.cfg if there are any) Copyright (C) 2013 Timothy Edmund Crosley @@ -34,6 +34,8 @@ import warnings from collections import namedtuple from distutils.util import strtobool +import appdirs + from .pie_slice import lru_cache from .utils import difference, union @@ -47,6 +49,9 @@ try: except ImportError: toml = False +if appdirs.system == 'darwin': + appdirs.system = 'linux2' + MAX_CONFIG_SEARCH_DEPTH = 25 # The number of parent directories isort will look for a config file within DEFAULT_SECTIONS = ('FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER') @@ -159,16 +164,22 @@ default = {'force_to_top': [], @lru_cache() def from_path(path): computed_settings = default.copy() - _update_settings_with_config(path, '.editorconfig', '~/.editorconfig', ('*', '*.py', '**.py'), computed_settings) - _update_settings_with_config(path, 'pyproject.toml', None, ('tool.isort', ), computed_settings) - _update_settings_with_config(path, '.isort.cfg', '~/.isort.cfg', ('settings', 'isort'), computed_settings) - _update_settings_with_config(path, 'setup.cfg', None, ('isort', 'tool:isort'), computed_settings) - _update_settings_with_config(path, 'tox.ini', None, ('isort', 'tool:isort'), computed_settings) + _update_settings_with_config(path, '.editorconfig', ['~/.editorconfig'], ('*', '*.py', '**.py'), computed_settings) + _update_settings_with_config(path, 'pyproject.toml', [], ('tool.isort', ), computed_settings) + _update_settings_with_config(path, '.isort.cfg', [appdirs.user_config_dir('isort.cfg'), '~/.isort.cfg'], ('settings', 'isort'), computed_settings) + _update_settings_with_config(path, 'setup.cfg', [], ('isort', 'tool:isort'), computed_settings) + _update_settings_with_config(path, 'tox.ini', [], ('isort', 'tool:isort'), computed_settings) return computed_settings def _update_settings_with_config(path, name, default, sections, computed_settings): - editor_config_file = default and os.path.expanduser(default) + editor_config_file = None + for potential_settings_path in default: + expanded = os.path.expanduser(potential_settings_path) + if os.path.exists(expanded): + editor_config_file = expanded + break + tries = 0 current_directory = path while current_directory and tries < MAX_CONFIG_SEARCH_DEPTH: @@ -26,7 +26,7 @@ setup(name='isort', 'pyproject': ['toml'], 'requirements': ['pip', 'pipreqs'], }, - install_requires=['futures; python_version < "3.2"'], + install_requires=['futures; python_version < "3.2"', 'appdirs'], python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", keywords='Refactor, Python, Python2, Python3, Refactoring, Imports, Sort, Clean', classifiers=['Development Status :: 6 - Mature', |