From af92e149151bfd7c637b6691c2b7147c1953953f Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Wed, 23 Jan 2019 11:40:34 +0200 Subject: 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 --- README.rst | 2 +- isort/settings.py | 24 +++++++++++++++++------- setup.py | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index cd55df31..3f54bfb6 100644 --- a/README.rst +++ b/README.rst @@ -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: diff --git a/setup.py b/setup.py index cb501f1a..95908a58 100755 --- a/setup.py +++ b/setup.py @@ -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', -- cgit v1.2.1 From cda4ed945806c5f8cc7914e094ac19b2e890c19f Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Sun, 17 Feb 2019 18:47:59 -0800 Subject: Update settings.py Attempt to fix current test errors --- isort/settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/isort/settings.py b/isort/settings.py index 2a06d76b..1a584345 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -34,8 +34,6 @@ from collections import namedtuple from distutils.util import strtobool import appdirs -if appdirs.system == 'darwin': - appdirs.system = 'linux2' from .pie_slice import lru_cache @@ -48,6 +46,9 @@ try: import toml 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') -- cgit v1.2.1 From 961e075aa5c81c23436a62ecca52049b01d6937f Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Sun, 17 Feb 2019 18:57:33 -0800 Subject: Update settings.py --- isort/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isort/settings.py b/isort/settings.py index 1a584345..79036773 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -46,7 +46,7 @@ try: import toml except ImportError: toml = False - + if appdirs.system == 'darwin': appdirs.system = 'linux2' -- cgit v1.2.1 From 9e07c6d66d006a2d3607fa8630df6563a8d1357d Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Sat, 23 Feb 2019 11:12:33 -0800 Subject: Update settings.py Fix accidental variable override --- isort/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/isort/settings.py b/isort/settings.py index 79036773..79f0dbb2 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -166,8 +166,8 @@ def from_path(path): def _update_settings_with_config(path, name, default, sections, computed_settings): editor_config_file = None - for path in default: - expanded = os.path.expanduser(path) + for potential_settings_path in default: + expanded = os.path.expanduser(potential_settings_path) if os.path.exists(expanded): editor_config_file = expanded break -- cgit v1.2.1