diff options
author | Roey Darwish Dror <roey.ghost@gmail.com> | 2019-01-23 11:40:34 +0200 |
---|---|---|
committer | Roey Darwish Dror <roey.ghost@gmail.com> | 2019-01-24 17:08:07 +0200 |
commit | af92e149151bfd7c637b6691c2b7147c1953953f (patch) | |
tree | a6a5496df608a252d50bcbb39fbce5ba26525609 | |
parent | 27515dbf9ba2137bd62f766d930273232338d953 (diff) | |
download | isort-af92e149151bfd7c637b6691c2b7147c1953953f.tar.gz |
Read configuration from XDG_CONFIG_HOME
In addition to ~/.isort.cfg, isort will try to read a configuration file from
$XDG_CONFIG_HOME/isort.cfg
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | isort/settings.py | 24 | ||||
-rwxr-xr-x | setup.py | 2 |
3 files changed, 19 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 79ae6c4c..2a06d76b 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 @@ -33,6 +33,10 @@ import warnings from collections import namedtuple from distutils.util import strtobool +import appdirs +if appdirs.system == 'darwin': + appdirs.system = 'linux2' + from .pie_slice import lru_cache try: @@ -151,16 +155,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 path in default: + expanded = os.path.expanduser(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', |