summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-02-23 12:20:00 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-02-23 12:20:00 -0800
commit719fb8d4750fd595c2ca63211701958fc90e4f1d (patch)
tree388754f495c7a0d5cb4775be59724e0f512c664a
parent61f3cde3f92cc0162263ac472cbd6a6d1ac5594d (diff)
downloadisort-719fb8d4750fd595c2ca63211701958fc90e4f1d.tar.gz
Make appdirs an optional requirement
-rw-r--r--isort/settings.py16
-rw-r--r--requirements.txt1
-rwxr-xr-xsetup.py3
3 files changed, 14 insertions, 6 deletions
diff --git a/isort/settings.py b/isort/settings.py
index 7b3153c6..9024dfc1 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -34,8 +34,6 @@ import warnings
from collections import namedtuple
from distutils.util import strtobool
-import appdirs
-
from .pie_slice import lru_cache
from .utils import difference, union
@@ -49,8 +47,12 @@ try:
except ImportError:
toml = False
-if appdirs.system == 'darwin':
- appdirs.system = 'linux2'
+try:
+ import appdirs
+ if appdirs.system == 'darwin':
+ appdirs.system = 'linux2'
+except ImportError:
+ appdirs = None
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')
@@ -164,9 +166,13 @@ default = {'force_to_top': [],
@lru_cache()
def from_path(path):
computed_settings = default.copy()
+ isort_defaults = ['~/.isort.cfg']
+ if appdirs:
+ isort_defaults = [appdirs.user_config_dir('isort.cfg')] + isort_defaults
+
_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, '.isort.cfg', isort_defaults, ('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
diff --git a/requirements.txt b/requirements.txt
index 5a72af01..ebd54a93 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
pytest==2.9.1
ipython==4.1.2
+appdirs
diff --git a/setup.py b/setup.py
index 95908a58..3a2ea7f9 100755
--- a/setup.py
+++ b/setup.py
@@ -25,8 +25,9 @@ setup(name='isort',
'pipfile': ['pipreqs', 'requirementslib'],
'pyproject': ['toml'],
'requirements': ['pip', 'pipreqs'],
+ 'xdg_home': ['appdirs'],
},
- install_requires=['futures; python_version < "3.2"', 'appdirs'],
+ install_requires=['futures; python_version < "3.2"'],
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',